Skip to content

Commit

Permalink
BAH-3350: Appointments: search endpoint stack traces when a patient h…
Browse files Browse the repository at this point in the history
…as more than one identifier of the same time (#142)
  • Loading branch information
mogoodrich authored Dec 19, 2023
1 parent 660c597 commit 4165b8f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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<PatientIdentifier> 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<Appointment> appointmentList = new ArrayList<>();
appointmentList.add(appointment);

AppointmentServiceDefaultResponse serviceDefaultResponse = new AppointmentServiceDefaultResponse();
when(appointmentServiceMapper.constructDefaultResponse(service)).thenReturn(serviceDefaultResponse);

List<AppointmentDefaultResponse> appointmentDefaultResponse = appointmentMapper.constructResponse(appointmentList);
AppointmentDefaultResponse response = appointmentDefaultResponse.get(0);
assertEquals(appointment.getUuid(), response.getUuid());

List<String> basicIdentifiers = Arrays.asList(response.getPatient().get("BasicIdentifierType").toString().split(","));
assertTrue(basicIdentifiers.contains("identifier1"));
assertTrue(basicIdentifiers.contains("identifier2"));
assertTrue(basicIdentifiers.contains("identifier3"));
}
}

0 comments on commit 4165b8f

Please sign in to comment.