SourcePatientIdentifierPIDTransformer implements PIDTransformer { @Override public List<String> toHL7(PatientInfo patientInfo) { notNull(patientInfo, "patientInfo cannot be null"); List<String> result = new ArrayList<String>(); for (Identifiable id : patientInfo.getIds()) { String part = Hl7v2Based.render(id); if (part != null) { result.add(part); } } return result.isEmpty() ? null : result; }  @Override void fromHL7(String hl7Data, PatientInfo patientInfo); @Override List<String> toHL7(PatientInfo patientInfo);  }
@Test public void testToHL7() { PatientInfo patientInfo = new PatientInfo(); Identifiable id1 = new Identifiable(); id1.setId("id1"); AssigningAuthority assigningAuthority1 = new AssigningAuthority(); assigningAuthority1.setUniversalId("1.1.1.1"); assigningAuthority1.setUniversalIdType("ISO"); id1.setAssigningAuthority(assigningAuthority1); Identifiable id2 = new Identifiable(); id2.setId("id2"); AssigningAuthority assigningAuthority2 = new AssigningAuthority(); assigningAuthority2.setUniversalId("2.2.2.2"); assigningAuthority2.setUniversalIdType("ISO"); id2.setAssigningAuthority(assigningAuthority2); patientInfo.getIds().add(id1); patientInfo.getIds().add(id2); List<String> result = transformer.toHL7(patientInfo); assertEquals(2, result.size()); assertEquals("id1^^^&1.1.1.1&ISO", result.get(0)); assertEquals("id2^^^&2.2.2.2&ISO", result.get(1)); }
@Test public void testToHL7EmptyIds() { PatientInfo patientInfo = new PatientInfo(); patientInfo.getIds().add(new Identifiable()); patientInfo.getIds().add(new Identifiable()); assertNull(transformer.toHL7(patientInfo)); }
@Test public void testToHL7NoIds() { assertNull(transformer.toHL7(new PatientInfo())); }