Skip to content

Commit

Permalink
UHM-1137, return distinct appointment blocks filtered by appointment …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
cioan committed Apr 1, 2014
1 parent 8ac12a1 commit 809512b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.openmrs.module.appointmentscheduling.api.db.hibernate;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Order;
Expand Down Expand Up @@ -84,6 +83,7 @@ public List<AppointmentBlock> getAppointmentBlocks(Date fromDate, Date toDate, S

criteria.addOrder(Order.asc("startDate"));
criteria.addOrder(Order.asc("endDate"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

List<AppointmentBlock> appointmentBlocks = criteria.list();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.springframework.web.util.WebUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;

@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE
+ "/appointmentblock", supportedClass = AppointmentBlock.class, supportedOpenmrsVersions = "1.9.*")
Expand Down Expand Up @@ -116,7 +120,7 @@ protected NeedsPaging<AppointmentBlock> doGetAll(RequestContext context) {
* @param appointmentType - Type of the appointment this block must support
* @param fromDate - (optional) earliest start date.
* @param toDate - (optional) latest start date.
* @param provider - (optional) the appointment block's provider.
* @param context - (optional) the appointment block's provider.
* @param location - (optional) the appointment block's location. (or predecessor location)t
* @return
*/
Expand All @@ -129,8 +133,16 @@ protected PageableResult doSearch(RequestContext context) {
Date endDate = context.getParameter("toDate") != null ? (Date) ConversionUtil.convert(
context.getParameter("toDate"), Date.class) : null;

AppointmentType appointmentType = context.getParameter("appointmentType") != null ? Context.getService(
AppointmentService.class).getAppointmentTypeByUuid(context.getParameter("appointmentType")) : null;
context.getParameter("appointmentType");

List<AppointmentType> types = null;
String[] appointmentTypes = context.getRequest().getParameterValues("appointmentType");
if (appointmentTypes != null && appointmentTypes.length > 0) {
types = new ArrayList<AppointmentType>();
for (String appointmentType : appointmentTypes) {
types.add(Context.getService(AppointmentService.class).getAppointmentTypeByUuid(appointmentType));
}
}

Provider provider = context.getParameter("provider") != null ? Context.getProviderService().getProviderByUuid(
context.getParameter("provider")) : null;
Expand All @@ -139,8 +151,8 @@ protected PageableResult doSearch(RequestContext context) {
String location = context.getParameter("location") != null ? Context.getLocationService()
.getLocationByUuid(context.getParameter("location")).getId().toString() : null;

return new NeedsPaging<AppointmentBlock>(Context.getService(AppointmentService.class).getAppointmentBlocks(
startDate, endDate, location, provider, appointmentType), context);
return new NeedsPaging<AppointmentBlock>(Context.getService(AppointmentService.class).getAppointmentBlocksByTypes(
startDate, endDate, location, provider, types), context);

}

Expand Down

0 comments on commit 809512b

Please sign in to comment.