Skip to content

Commit

Permalink
Kavitha | add date check and tests for waitlist appointments
Browse files Browse the repository at this point in the history
  • Loading branch information
kavitha-sundararajan committed Feb 26, 2024
1 parent c121103 commit 63f7c4e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.sql.JoinType;
import org.openmrs.api.context.Context;
import org.openmrs.module.appointments.dao.AppointmentDao;
import org.openmrs.module.appointments.model.Appointment;
import org.openmrs.module.appointments.model.AppointmentSearchRequest;
Expand Down Expand Up @@ -160,13 +161,20 @@ public List<Appointment> search(AppointmentSearchRequest appointmentSearchReques
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Appointment.class);

criteria.add(Restrictions.eq("voided", false));
criteria.addOrder(Order.asc("startDateTime"));
if (appointmentSearchRequest.getStartDate() != null) {
criteria.addOrder(Order.asc("startDateTime"));
} else {
criteria.addOrder(Order.asc("dateCreated"));
}
setDateCriteria(appointmentSearchRequest, criteria);
setPatientCriteria(appointmentSearchRequest, criteria);
setLimitCriteria(appointmentSearchRequest, criteria);
setProviderCriteria(appointmentSearchRequest, criteria);
setStatusCriteria(appointmentSearchRequest, criteria);

String limit = Context.getAdministrationService().getGlobalProperty("webservices.rest.maxResultsDefault");
if(StringUtils.isNotEmpty(limit))
criteria.setMaxResults(Integer.parseInt(limit));
return criteria.list();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ public void should_SearchForDatelessAppointments() throws Exception {
assertEquals(200, response.getStatus());
}

@Test
public void should_SearchForWaitListAppointments() throws Exception {
String content = "{ \"status\": \"WaitList\" }";

MockHttpServletResponse response = handle(newPostRequest("/rest/v1/appointment/search", content));
assertNotNull(response);
assertEquals(200, response.getStatus());
}

@Test
public void shouldCreateAuditEventsWhenDetailsChangesOnEditAppointment() throws Exception {
String content = "{ \"uuid\": \"c36006e5-9fbb-4f20-866b-0ece245615a7\", " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,36 @@ public void shouldSearchForDatelessAppointments() throws Exception{
assertEquals(expectedAppointmentResponse.getUuid(), appointmentResponse.getUuid());
}

@Test
public void shouldSearchForWaitListAppointments() throws Exception{
List<Appointment> appointments = new ArrayList<>();
Appointment appointment = new Appointment();
appointment.setUuid("appointmentUuid");
appointment.setStatus(AppointmentStatus.WaitList);
Patient patient = new Patient();
patient.setUuid("somePatientUuid");
appointment.setPatient(patient);
appointments.add(appointment);
AppointmentQuery appointmentQuery = new AppointmentQuery();
appointmentQuery.setStatus("WaitList");


AppointmentDefaultResponse appointmentDefaultResponse = new AppointmentDefaultResponse();
appointmentDefaultResponse.setUuid("appointmentUuid");

List<AppointmentDefaultResponse> appointmentDefaultResponses = new ArrayList<>();
appointmentDefaultResponses.add(appointmentDefaultResponse);

when(appointmentMapper.mapQueryToAppointment(appointmentQuery)).thenReturn(appointment);
when(appointmentsService.search(appointment)).thenReturn(appointments);
when(appointmentMapper.constructResponse(appointments)).thenReturn(appointmentDefaultResponses);

List<AppointmentDefaultResponse> appointmentResponses = appointmentController.searchAppointments(appointmentQuery);
AppointmentDefaultResponse appointmentResponse = appointmentResponses.get(0);
AppointmentDefaultResponse expectedAppointmentResponse = appointmentDefaultResponses.get(0);
assertEquals(expectedAppointmentResponse.getUuid(), appointmentResponse.getUuid());
}

@Test
public void shouldSaveAnAppointment() throws Exception{
AppointmentRequest appointmentRequest = new AppointmentRequest();
Expand Down

0 comments on commit 63f7c4e

Please sign in to comment.