diff --git a/omod/src/main/java/org/openmrs/module/appointments/web/mapper/AppointmentMapper.java b/omod/src/main/java/org/openmrs/module/appointments/web/mapper/AppointmentMapper.java index 4e69f4bfc..124f565ca 100644 --- a/omod/src/main/java/org/openmrs/module/appointments/web/mapper/AppointmentMapper.java +++ b/omod/src/main/java/org/openmrs/module/appointments/web/mapper/AppointmentMapper.java @@ -274,7 +274,7 @@ private Map createPatientMap(Patient p) { map.put("identifier", p.getPatientIdentifier().getIdentifier()); map.put("age", p.getAge()); map.put("gender", p.getGender()); - map.putAll(p.getActiveIdentifiers().stream().filter(e -> e.getIdentifierType() != null).collect(Collectors.toMap(e -> e.getIdentifierType().toString().replaceAll("[- ]", ""), e -> e.getIdentifier()))); + map.putAll(p.getActiveIdentifiers().stream().filter(e -> e.getIdentifierType() != null).collect(Collectors.toMap(e -> e.getIdentifierType().toString().replaceAll("[- ]", ""), e -> e.getIdentifier(), (e1, e2) -> e1 + "," + e2))); return map; } diff --git a/omod/src/test/java/org/openmrs/module/appointments/web/mapper/AppointmentMapperTest.java b/omod/src/test/java/org/openmrs/module/appointments/web/mapper/AppointmentMapperTest.java index 0e76c5c9e..c0d582e14 100644 --- a/omod/src/test/java/org/openmrs/module/appointments/web/mapper/AppointmentMapperTest.java +++ b/omod/src/test/java/org/openmrs/module/appointments/web/mapper/AppointmentMapperTest.java @@ -11,6 +11,7 @@ import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.PatientIdentifier; +import org.openmrs.PatientIdentifierType; import org.openmrs.PersonName; import org.openmrs.Provider; import org.openmrs.api.LocationService; @@ -53,7 +54,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -578,6 +581,8 @@ public void shouldReturnEmptyListWhenProvidersListIsEmptyForAnAppointment() thro assertEquals(Collections.EMPTY_LIST, appointmentDefaultResponse.getProviders()); } + + @Test public void shouldChangeTheResponseAndVoidedDataWhenProviderIsVoidedAndAddedAgain() throws ParseException { String appointmentUuid = "7869637c-12fe-4121-9692-b01f93f99e55"; @@ -641,4 +646,45 @@ public void shouldReturnClonedAppointmentFromRequest() throws ParseException { assertEquals(AppointmentStatus.Scheduled, appointment.getStatus()); assertEquals(appointmentRequest.getComments(), appointment.getComments()); } + + @Test + public void shouldNotFailIfPatientHasMultipleIdentifiersOfTheSameIdentifierType() throws Exception { + Appointment appointment = createAppointment(); + + Set identifiers = new HashSet<>(); + PatientIdentifierType type = new PatientIdentifierType(); + type.setId(1); + type.setName("Basic Identifier Type"); + PatientIdentifier identifier1 = new PatientIdentifier(); + identifier1.setIdentifierType(type); + identifier1.setIdentifier("identifier1"); + identifiers.add(identifier1); + + PatientIdentifier identifier2 = new PatientIdentifier(); + identifier2.setIdentifierType(type); + identifier2.setIdentifier("identifier2"); + identifiers.add(identifier2); + + PatientIdentifier identifier3 = new PatientIdentifier(); + identifier3.setIdentifierType(type); + identifier3.setIdentifier("identifier3"); + identifiers.add(identifier3); + + appointment.getPatient().setIdentifiers(identifiers); + + List appointmentList = new ArrayList<>(); + appointmentList.add(appointment); + + AppointmentServiceDefaultResponse serviceDefaultResponse = new AppointmentServiceDefaultResponse(); + when(appointmentServiceMapper.constructDefaultResponse(service)).thenReturn(serviceDefaultResponse); + + List appointmentDefaultResponse = appointmentMapper.constructResponse(appointmentList); + AppointmentDefaultResponse response = appointmentDefaultResponse.get(0); + assertEquals(appointment.getUuid(), response.getUuid()); + + List basicIdentifiers = Arrays.asList(response.getPatient().get("BasicIdentifierType").toString().split(",")); + assertTrue(basicIdentifiers.contains("identifier1")); + assertTrue(basicIdentifiers.contains("identifier2")); + assertTrue(basicIdentifiers.contains("identifier3")); + } }