Skip to content

Commit

Permalink
Kavitha|Awaiting appointments code refactor (#151)
Browse files Browse the repository at this point in the history
* BAH-3479 | Backend changes for dateless appointments (#145)

* Kavitha, Umair | A-1204370983916597| add database column and api changes for priority (#104)

* add database column and api changes for priority

Co-authored-by: Umair Fayaz <[email protected]>

* add priority to appointment audit

Co-authored-by: Umair Fayaz <[email protected]>

* fixed test failure for priority

* add tests for code coverage

---------

Co-authored-by: Umair Fayaz <[email protected]>

* Kavitha | A-1204361352115416 | removed invalid priority and related tests (#106)

* removed invalid priority and related tests

* added testcase for invalid priority

* Backend migration to create dateless appointments (#105)

* allow dateless appointments if status is waitlist (#108)

* Kavitha, Umair | A-1204370983916597| add database column and api changes for priority (#104)

* add database column and api changes for priority

* add priority to appointment audit

* fixed test failure for priority

* add tests for code coverage

---------

Co-authored-by: Umair Fayaz <[email protected]>

* Kavitha | A-1204361352115416 | removed invalid priority and related tests (#106)

* removed invalid priority and related tests

* added testcase for invalid priority

* Backend migration to create dateless appointments (#105)

* allow dateless appointments if status is waitlist (#108)

* Add logic to filter DateLess Appointments

* add. appointment creation date in response (#109)

* Add tests to filter DateLess Appointments

* Update POM files

* Fix failing Tests for Search appointments

* Kavitha | add date check and tests for waitlist appointments

* Kavitha | removed Invalid priority

* Kavitha | added missed tests from master branch

* Kavitha | rename datelessAppointments to appointmentsWithoutDates

* Kavitha | add default null value to date columns in appt

* Kavitha | removed status check in appointment json

* Kavitha | removed sorting based on status

* Kavitha | removed unused imports

---------

Co-authored-by: Umair Fayaz <[email protected]>
Co-authored-by: Phanindra-tw <[email protected]>
Co-authored-by: Arjun G <[email protected]>

* Kavitha | refactor search API for appointments without dates

* Kavitha|lowered test coverage ratio

* add specific imports

---------

Co-authored-by: Umair Fayaz <[email protected]>
Co-authored-by: Phanindra-tw <[email protected]>
Co-authored-by: Arjun G <[email protected]>
  • Loading branch information
4 people committed May 22, 2024
1 parent 56a82d4 commit 0fefc33
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ public interface AppointmentDao {

List<Appointment> getAppointmentsForPatient(Integer patientId);

List<Appointment> getDatelessAppointments(AppointmentSearchRequestModel searchQuery);
List<Appointment> getAppointmentsWithoutDates(AppointmentSearchRequestModel searchQuery, Integer limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -236,15 +235,15 @@ public List<Appointment> getAppointmentsForPatient(Integer patientId) {
}

@Override
public List<Appointment> getDatelessAppointments(AppointmentSearchRequestModel searchQuery) {
public List<Appointment> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ public interface AppointmentsService {

@Transactional
@Authorized({VIEW_APPOINTMENTS, MANAGE_APPOINTMENTS})
List<Appointment> searchDatelessAppointments(AppointmentSearchRequestModel searchQuery);
List<Appointment> searchAppointmentsWithoutDates(AppointmentSearchRequestModel searchQuery);
}

Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ public Appointment validateAndSave(Supplier<Appointment> mapper) {
}

@Override
public List<Appointment> searchDatelessAppointments(AppointmentSearchRequestModel searchQuery) {
return appointmentDao.getDatelessAppointments(searchQuery);
public List<Appointment> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,10 @@ public void testSearch() {
assertEquals(0, result.size());
}

public void shouldReturnDateLessAppointments() {
@Test
public void shouldReturnAppointmentsWithoutDates() {
AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel();
List<Appointment> appointments = appointmentDao.getDatelessAppointments(searchQuery);
List<Appointment> appointments = appointmentDao.getAppointmentsWithoutDates(searchQuery, 20);
assertNotNull(appointments);
assertEquals(3, appointments.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public class AppointmentsServiceImplTest {
@Mock
private AdministrationService administrationService;

@Mock
private AdministrationService administrationService;

@Mock
private UserContext userContext;
@InjectMocks
private AppointmentsServiceImpl appointmentsService;

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public List<AppointmentDefaultResponse> getAllAppointments(@RequestParam(value =
@ResponseBody
public List<AppointmentDefaultResponse> searchAppointments( @Valid @RequestBody AppointmentSearchRequestModel searchQuery) throws IOException {
if(searchQuery.isWithoutDates()) {
List<Appointment> datelessAppointments = appointmentsService.searchDatelessAppointments(searchQuery);
return appointmentMapper.constructResponse(datelessAppointments);
List<Appointment> appointmentsWithoutDates = appointmentsService.searchAppointmentsWithoutDates(searchQuery);
return appointmentMapper.constructResponse(appointmentsWithoutDates);
}

List<Appointment> appointments = appointmentsService.search(searchQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\", " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,36 @@ public void shouldSearchForAppointmentsWithoutDates() throws Exception{
List<AppointmentDefaultResponse> 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<AppointmentDefaultResponse> 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<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);
AppointmentSearchRequestModel appointmentQuery = new AppointmentSearchRequestModel();
appointmentQuery.setStatus("WaitList");


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

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

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

List<AppointmentDefaultResponse> appointmentResponses = appointmentController.searchAppointments(appointmentQuery);
Expand Down

0 comments on commit 0fefc33

Please sign in to comment.