diff --git a/api/src/main/java/org/openmrs/module/appointments/dao/AppointmentDao.java b/api/src/main/java/org/openmrs/module/appointments/dao/AppointmentDao.java index 5b9861d9..d3698d12 100644 --- a/api/src/main/java/org/openmrs/module/appointments/dao/AppointmentDao.java +++ b/api/src/main/java/org/openmrs/module/appointments/dao/AppointmentDao.java @@ -38,5 +38,5 @@ public interface AppointmentDao { List getAppointmentsForPatient(Integer patientId); - List getDatelessAppointments(AppointmentSearchRequestModel searchQuery); + List getAppointmentsWithoutDates(AppointmentSearchRequestModel searchQuery, Integer limit); } diff --git a/api/src/main/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImpl.java b/api/src/main/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImpl.java index d39a0e42..ef271ff4 100644 --- a/api/src/main/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImpl.java +++ b/api/src/main/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImpl.java @@ -9,7 +9,6 @@ import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Disjunction; 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.AppointmentSearchRequestModel; @@ -236,15 +235,15 @@ public List getAppointmentsForPatient(Integer patientId) { } @Override - public List getDatelessAppointments(AppointmentSearchRequestModel searchQuery) { + public List getAppointmentsWithoutDates(AppointmentSearchRequestModel searchQuery, Integer limit) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Appointment.class); addSearchCriteria(criteria, searchQuery); criteria.add(Restrictions.isNull("startDateTime")); criteria.add(Restrictions.isNull("endDateTime")); criteria.addOrder(Order.asc("dateCreated")); - String limit = Context.getAdministrationService().getGlobalProperty("webservices.rest.maxResultsDefault"); - if(StringUtils.isNotEmpty(limit)) - criteria.setMaxResults(Integer.parseInt(limit)); + if (limit != null) { + criteria.setMaxResults(limit); + } return criteria.list(); } diff --git a/api/src/main/java/org/openmrs/module/appointments/service/AppointmentsService.java b/api/src/main/java/org/openmrs/module/appointments/service/AppointmentsService.java index 226b7315..c679e147 100644 --- a/api/src/main/java/org/openmrs/module/appointments/service/AppointmentsService.java +++ b/api/src/main/java/org/openmrs/module/appointments/service/AppointmentsService.java @@ -108,6 +108,6 @@ public interface AppointmentsService { @Transactional @Authorized({VIEW_APPOINTMENTS, MANAGE_APPOINTMENTS}) - List searchDatelessAppointments(AppointmentSearchRequestModel searchQuery); + List searchAppointmentsWithoutDates(AppointmentSearchRequestModel searchQuery); } diff --git a/api/src/main/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImpl.java b/api/src/main/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImpl.java index e91c3789..f29cffea 100644 --- a/api/src/main/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImpl.java @@ -144,8 +144,10 @@ public Appointment validateAndSave(Supplier mapper) { } @Override - public List searchDatelessAppointments(AppointmentSearchRequestModel searchQuery) { - return appointmentDao.getDatelessAppointments(searchQuery); + public List searchAppointmentsWithoutDates(AppointmentSearchRequestModel searchQuery) { + String limitString = Context.getAdministrationService().getGlobalProperty("webservices.rest.maxResultsDefault"); + Integer limit = StringUtils.isNotEmpty(limitString) ? Integer.parseInt(limitString) : null; + return appointmentDao.getAppointmentsWithoutDates(searchQuery, limit); } private void setupTeleconsultation(Appointment appointment) { diff --git a/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java b/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java index df9ec0b8..47c33efa 100644 --- a/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java +++ b/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java @@ -310,9 +310,10 @@ public void testSearch() { assertEquals(0, result.size()); } - public void shouldReturnDateLessAppointments() { + @Test + public void shouldReturnAppointmentsWithoutDates() { AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel(); - List appointments = appointmentDao.getDatelessAppointments(searchQuery); + List appointments = appointmentDao.getAppointmentsWithoutDates(searchQuery, 20); assertNotNull(appointments); assertEquals(3, appointments.size()); } diff --git a/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java b/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java index bfd8ed4d..9fc9bc2f 100644 --- a/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java @@ -129,6 +129,11 @@ public class AppointmentsServiceImplTest { @Mock private AdministrationService administrationService; + @Mock + private AdministrationService administrationService; + + @Mock + private UserContext userContext; @InjectMocks private AppointmentsServiceImpl appointmentsService; @@ -800,9 +805,11 @@ public void shouldThrowErrorWhenTryingToChangeProviderResponseForOtherProvider() } @Test - public void shouldGetDatelessAppointments() { + public void shouldGetAppointmentsWithoutDates() { AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel(); - appointmentsService.searchDatelessAppointments(searchQuery); - verify(appointmentDao, times(1)).getDatelessAppointments(searchQuery); + when(Context.getAdministrationService()).thenReturn(administrationService); + when(administrationService.getGlobalProperty("webservices.rest.maxResultsDefault")).thenReturn("20"); + appointmentsService.searchAppointmentsWithoutDates(searchQuery); + verify(appointmentDao, times(1)).getAppointmentsWithoutDates(searchQuery, 20); } } diff --git a/omod/src/main/java/org/openmrs/module/appointments/web/controller/AppointmentController.java b/omod/src/main/java/org/openmrs/module/appointments/web/controller/AppointmentController.java index b924a714..4f6595f6 100644 --- a/omod/src/main/java/org/openmrs/module/appointments/web/controller/AppointmentController.java +++ b/omod/src/main/java/org/openmrs/module/appointments/web/controller/AppointmentController.java @@ -58,8 +58,8 @@ public List getAllAppointments(@RequestParam(value = @ResponseBody public List searchAppointments( @Valid @RequestBody AppointmentSearchRequestModel searchQuery) throws IOException { if(searchQuery.isWithoutDates()) { - List datelessAppointments = appointmentsService.searchDatelessAppointments(searchQuery); - return appointmentMapper.constructResponse(datelessAppointments); + List appointmentsWithoutDates = appointmentsService.searchAppointmentsWithoutDates(searchQuery); + return appointmentMapper.constructResponse(appointmentsWithoutDates); } List appointments = appointmentsService.search(searchQuery); diff --git a/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerIT.java b/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerIT.java index 88300dcd..402e0915 100644 --- a/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerIT.java +++ b/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerIT.java @@ -166,6 +166,15 @@ public void should_SearchForAppointmentsWithoutDates() 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\", " + diff --git a/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerTest.java b/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerTest.java index 344c0aa3..a2a19e6e 100644 --- a/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/appointments/web/controller/AppointmentControllerTest.java @@ -276,7 +276,36 @@ public void shouldSearchForAppointmentsWithoutDates() throws Exception{ List appointmentDefaultResponses = new ArrayList<>(); appointmentDefaultResponses.add(appointmentDefaultResponse); - when(appointmentsService.searchDatelessAppointments(appointmentQuery)).thenReturn(appointments); + when(appointmentsService.searchAppointmentsWithoutDates(appointmentQuery)).thenReturn(appointments); + when(appointmentMapper.constructResponse(appointments)).thenReturn(appointmentDefaultResponses); + + List appointmentResponses = appointmentController.searchAppointments(appointmentQuery); + AppointmentDefaultResponse appointmentResponse = appointmentResponses.get(0); + AppointmentDefaultResponse expectedAppointmentResponse = appointmentDefaultResponses.get(0); + assertEquals(expectedAppointmentResponse.getUuid(), appointmentResponse.getUuid()); + } + + @Test + public void shouldSearchForWaitListAppointments() throws Exception{ + List 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); + AppointmentSearchRequestModel appointmentQuery = new AppointmentSearchRequestModel(); + appointmentQuery.setStatus("WaitList"); + + + AppointmentDefaultResponse appointmentDefaultResponse = new AppointmentDefaultResponse(); + appointmentDefaultResponse.setUuid("appointmentUuid"); + + List appointmentDefaultResponses = new ArrayList<>(); + appointmentDefaultResponses.add(appointmentDefaultResponse); + + when(appointmentsService.search(appointmentQuery)).thenReturn(appointments); when(appointmentMapper.constructResponse(appointments)).thenReturn(appointmentDefaultResponses); List appointmentResponses = appointmentController.searchAppointments(appointmentQuery);