Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]Kavitha | fix dateless appointment when patient merge #144

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}
Loading