Skip to content

Commit

Permalink
AM-169: getAppointmentsByConstraints should sort appointments by time…
Browse files Browse the repository at this point in the history
… slot (earliest first)
  • Loading branch information
mogoodrich committed Oct 1, 2014
1 parent fdc65ff commit a9ed51f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ Set<Location> getAllLocationDescendants(Location location,
* @param type - The appointment type
* @param status - The appointment status
* @return a list of appointments that satisfy the given constraints
* @should sort by associated time slot
*/
@Authorized(AppointmentUtils.PRIV_VIEW_APPOINTMENTS)
List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate,
Expand All @@ -802,6 +803,7 @@ List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate,
* @param status - The appointment status
* @param patient - The patient
* @return a list of appointments that satisfy the given constraints
* @should sort by associated time slot
*/
@Authorized(AppointmentUtils.PRIV_VIEW_APPOINTMENTS)
List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate,
Expand All @@ -819,6 +821,7 @@ List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate,
* @param patient - The patient
* @param appointmentStatuses - The appointment status list
* @return a list of appointments that satisfy the given constraints
* @should sort by associated time slot
*/
@Authorized(AppointmentUtils.PRIV_VIEW_APPOINTMENTS)
List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public List<Appointment> getAppointmentsByConstraints(Date fromDate,
stringQuery += " AND appointment.patient=:patient";
}

stringQuery += " ORDER BY appointment.timeSlot.startDate";

Query query = super.sessionFactory.getCurrentSession().createQuery(
stringQuery);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ public void shouldGetAllUnvoidedAppointmentsByType_getAppointmentsByConstraints(
assertEquals(7, appointments.size());

type = service.getAppointmentType(3);
Appointment specificAppointment = service.getAppointment(4);
Appointment specificAppointment = service.getAppointment(5);
appointments = service.getAppointmentsByConstraints(null, null, null,
null, type, null);
null, type, null); // apt #5 should be first because we are sorting by time slot
assertEquals(specificAppointment, appointments.iterator().next());
assertEquals(3, appointments.size());
}
Expand Down Expand Up @@ -402,6 +402,27 @@ public void shouldgetAllUnvoidedAppointmentsByPatientAndStatus_getAppointmentsBy
assertEquals(patient, appointments.get(3).getPatient());
}

@Test
public void shouldProperlySortAppointmentsByTimeSlotDate_getAppointmentsByConstraints() {

Patient patient = Context.getPatientService().getPatient(1);

List<AppointmentStatus> appointmentStatuses = Arrays.asList(
AppointmentStatus.SCHEDULED, AppointmentStatus.RESCHEDULED);

List<Appointment> appointments = service.getAppointmentsByConstraints(
null, null, null, null, null, patient, appointmentStatuses);

assertNotNull(appointments);
assertEquals(4, appointments.size());

// verify they are in order
assertEquals(new Integer(6), appointments.get(0).getId());
assertEquals(new Integer(1), appointments.get(1).getId());
assertEquals(new Integer(4), appointments.get(2).getId());
assertEquals(new Integer(7), appointments.get(3).getId());
}

@Test
@Verifies(value = "Should get correct appointments", method = "getAppointmentsByStatus(List<AppointmentStatus>)")
public void shouldGetCorrectAppointments_getAppointmentsByStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ public void shouldFetchAppointmentsByPatient() throws Exception {
List<Map<String, String>> appointments = (List<Map<String, String>>) deserialize(
handle(req)).get("results");
Assert.assertEquals(2, appointments.size());
Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183606",
appointments.get(0).get("uuid"));
Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183602",
appointments.get(0).get("uuid"));
Assert.assertEquals("c0c579b0-8e59-401d-8a4a-976a0b183606",
appointments.get(1).get("uuid"));

}

@Test
Expand Down

0 comments on commit a9ed51f

Please sign in to comment.