Skip to content

Commit

Permalink
AM-158: Add Reporting module support to Appointment Scheduling module
Browse files Browse the repository at this point in the history
added location as a parameter to the BasicAppointmentQuery
  • Loading branch information
mogoodrich committed May 29, 2014
1 parent 2c3b06a commit 3af2dfe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.openmrs.module.appointmentscheduling.reporting.query.definition;

import org.openmrs.Location;
import org.openmrs.module.appointmentscheduling.Appointment;
import org.openmrs.module.reporting.definition.configuration.ConfigurationProperty;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
Expand All @@ -29,11 +30,14 @@ public class BasicAppointmentQuery extends BaseQuery<Appointment> implements App

public static final long serialVersionUID = 1L;

@ConfigurationProperty
public Date onOrAfter;
@ConfigurationProperty(required = false)
private Date onOrAfter;

@ConfigurationProperty
public Date onOrBefore;
@ConfigurationProperty(required = false)
private Date onOrBefore;

@ConfigurationProperty(required = false)
private Location location;

public Date getOnOrAfter() {
return onOrAfter;
Expand All @@ -51,4 +55,11 @@ public void setOnOrBefore(Date onOrBefore) {
this.onOrBefore = onOrBefore;
}

public Location getLocation() {
return location;
}

public void setLocation(Location location) {
this.location = location;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public AppointmentQueryResult evaluate(AppointmentQuery appointmentQuery, Evalua

// query builder excludes voided by default
query.select("appointment.appointmentId").from(Appointment.class, "appointment")
.innerJoin("appointment.timeSlot", "timeSlot")
.whereLessOrEqualTo("timeSlot.startDate", q.getOnOrBefore())
.whereGreaterOrEqualTo("timeSlot.endDate", q.getOnOrAfter());
.whereLessOrEqualTo("appointment.timeSlot.startDate", q.getOnOrBefore())
.whereGreaterOrEqualTo("appointment.timeSlot.endDate", q.getOnOrAfter())
.whereEqual("appointment.timeSlot.appointmentBlock.location", q.getLocation());


if (evaluationContext != null) {
Set<Integer> appointmentIds = AppointmentDataUtil.getAppointmentIdsForContext(evaluationContext, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Before;
import org.junit.Test;
import org.openmrs.Cohort;
import org.openmrs.api.LocationService;
import org.openmrs.module.appointmentscheduling.reporting.context.AppointmentEvaluationContext;
import org.openmrs.module.appointmentscheduling.reporting.query.AppointmentIdSet;
import org.openmrs.module.appointmentscheduling.reporting.query.AppointmentQueryResult;
Expand All @@ -24,6 +25,9 @@ public class BasicAppointmentQueryEvaluatorTest extends BaseModuleContextSensiti
@Autowired
private AppointmentQueryService appointmentQueryService;

@Autowired
private LocationService locationService;

@Before
public void setup() throws Exception {
executeDataSet("standardAppointmentTestDataset.xml");
Expand Down Expand Up @@ -92,4 +96,19 @@ public void shouldRestrictAppointmentReturnedByAppointment() throws Exception {
}


@Test
public void shouldRestrictAppointmentReturnedByLocation() throws Exception {

BasicAppointmentQuery query = new BasicAppointmentQuery();
query.setLocation(locationService.getLocation(2));

AppointmentQueryResult result = appointmentQueryService.evaluate(query, null);
assertThat(result.getMemberIds().size(), is(4));
assertTrue(result.getMemberIds().contains(7));
assertTrue(result.getMemberIds().contains(8));
assertTrue(result.getMemberIds().contains(9));
assertTrue(result.getMemberIds().contains(11));

}

}

0 comments on commit 3af2dfe

Please sign in to comment.