Skip to content

Commit

Permalink
Merge pull request #144 from Bahmni/merge-patient-bug
Browse files Browse the repository at this point in the history
[Bug]Kavitha | fix dateless appointment when patient merge
  • Loading branch information
kavitha-sundararajan authored Dec 29, 2023
2 parents 2c2779a + 226fa9e commit 47bbea7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public List<Appointment> getAppointmentsForPatient(Integer patientId) {
@Override
public List<Appointment> getDatelessAppointments() {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Appointment.class);
criteria.createAlias("patient", "patient");
criteria.add(Restrictions.eq("patient.voided", false));
criteria.add(Restrictions.eq("patient.personVoided", false));
criteria.add(Restrictions.isNull("startDateTime"));
criteria.add(Restrictions.isNull("endDateTime"));
criteria.addOrder(Order.asc("dateCreated"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private Map createPatientMap(Patient p) {
map.put("age", p.getAge());
map.put("gender", p.getGender());
map.put("customAttributes", customAttributesMap);
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.api.AdministrationService;
import org.openmrs.Provider;
Expand Down Expand Up @@ -57,7 +58,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 @@ -613,6 +616,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 @@ -676,4 +681,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 47bbea7

Please sign in to comment.