Skip to content

Commit

Permalink
AM-153: In API, expand getAppointmentsByConstraints to accept a patie…
Browse files Browse the repository at this point in the history
…nt as a parameter
  • Loading branch information
mogoodrich committed Mar 12, 2014
1 parent 7a402ec commit 0244d55
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,21 @@ List<TimeSlot> getTimeSlotsByConstraintsIncludingFull(AppointmentType appointmen
List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
AppointmentType type, AppointmentStatus status) throws APIException;

/**
* Retrieves Appointments that satisfy the given constraints
*
* @param fromDate - The appointment start date
* @param toDate - The appointment end date
* @param location - The appointment location
* @param provider - The appointment provider
* @param type - The appointment type
* @param status - The appointment status
* @param patient - The patient
* @return a list of appointments that satisfy the given constraints
*/
List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
AppointmentType type, AppointmentStatus status, Patient patient) throws APIException;

/**
* Retrives the start date of the current status of a given appointment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface AppointmentDAO extends SingleClassDAO {
Appointment getLastAppointment(Patient patient);

List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Provider provider, AppointmentType type,
AppointmentStatus status) throws APIException;
AppointmentStatus status, Patient patient) throws APIException;

List<Appointment> getAppointmentsByStates(List<AppointmentStatus> states);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Appointment getLastAppointment(Patient patient) {
@Override
@Transactional(readOnly = true)
public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Provider provider,
AppointmentType appointmentType, AppointmentStatus status) throws APIException {
AppointmentType appointmentType, AppointmentStatus status, Patient patient) throws APIException {
if (fromDate != null && toDate != null && !fromDate.before(toDate))
throw new APIException("fromDate can not be later than toDate");

Expand All @@ -97,6 +97,9 @@ public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate
stringQuery += " AND appointment.status=:status";
if (appointmentType != null)
stringQuery += " AND appointment.appointmentType=:appointmentType";
if (patient != null) {
stringQuery += " AND appointment.patient=:patient";
}

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

Expand All @@ -110,6 +113,8 @@ public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate
query.setParameter("status", status);
if (appointmentType != null)
query.setParameter("appointmentType", appointmentType);
if (patient != null)
query.setParameter("patient", patient);

return query.list();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,18 @@ public Set<Location> getAllLocationDescendants(Location location, Set<Location>
}

@Override
@Transactional(readOnly = true)
public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
AppointmentType type, AppointmentStatus status) throws APIException {
return getAppointmentsByConstraints(fromDate, toDate, location, provider, type, status, null);
}

@Override
@Transactional(readOnly = true)
public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
AppointmentType type, AppointmentStatus status, Patient patient) throws APIException {

List<Appointment> appointments = appointmentDAO.getAppointmentsByConstraints(fromDate, toDate, provider, type,
status);
status, patient);

List<Appointment> appointmentsInLocation = new LinkedList<Appointment>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
*/
package org.openmrs.module.appointmentscheduling.api;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -32,12 +38,6 @@
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.openmrs.test.Verifies;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
Expand Down Expand Up @@ -344,6 +344,18 @@ public void shouldgetAllUnvoidedAppointmentsByStatus_getAppointmentsByConstraint
;
}

@Test
@Verifies(value = "Should get all unvoided appointments by patient", method = "getAppointmentsByConstraints(Date, Date, Location, Provider, AppointmentType, AppointmentStatus, Patient)")
public void shouldgetAllUnvoidedAppointmentsByPatient_getAppointmentsByConstraints() {

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

List<Appointment> appointments = service.getAppointmentsByConstraints(null, null, null, null, null, null, patient);
assertEquals(2, appointments.size());
assertEquals(patient, appointments.get(0).getPatient());
assertEquals(patient, appointments.get(1).getPatient());
}

@Test
@Verifies(value = "Should get correct appointments", method = "getAppointmentsByStatus(List<AppointmentStatus>)")
public void shouldGetCorrectAppointments_getAppointmentsByStatus() {
Expand Down

0 comments on commit 0244d55

Please sign in to comment.