diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs2_0/EncounterSearchHandler2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs2_0/EncounterSearchHandler2_0.java index b6ea522bb..fc35b805c 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs2_0/EncounterSearchHandler2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs2_0/EncounterSearchHandler2_0.java @@ -9,14 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.search.openmrs2_0; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import java.util.*; import org.openmrs.Encounter; import org.openmrs.EncounterType; import org.openmrs.Patient; +import org.openmrs.Visit; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -31,6 +29,7 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.EncounterTypeResource1_8; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.VisitResource1_9; import org.openmrs.parameter.EncounterSearchCriteria; import org.openmrs.parameter.EncounterSearchCriteriaBuilder; import org.springframework.stereotype.Component; @@ -58,7 +57,8 @@ public SearchConfig getSearchConfig() { public PageableResult search(RequestContext context) throws ResponseException { String patientUuid = context.getRequest().getParameter("patient"); String encounterTypeUuid = context.getRequest().getParameter("encounterType"); - + String[] visitsUuid=context.getRequest().getParameter("visits").split(","); + String dateFrom = context.getRequest().getParameter(DATE_FROM); String dateTo = context.getRequest().getParameter(DATE_TO); @@ -69,13 +69,24 @@ public PageableResult search(RequestContext context) throws ResponseException { Patient.class)).getByUniqueId(patientUuid); EncounterType encounterType = ((EncounterTypeResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(EncounterType.class)).getByUniqueId(encounterTypeUuid); + + Collection visits = new ArrayList<>(); + if(visitsUuid.length>0) { + + for (String uuid : visitsUuid) { + Visit visit = ((VisitResource1_9) Context.getService(RestService.class).getResourceBySupportedClass(Visit.class)).getByUniqueId(uuid); + visits.add(visit); + } + } if (patient != null) { EncounterSearchCriteriaBuilder encounterSearchCriteriaBuilder = new EncounterSearchCriteriaBuilder() .setPatient(patient).setFromDate(fromDate).setToDate(toDate).setIncludeVoided(false); if (encounterType != null) { encounterSearchCriteriaBuilder.setEncounterTypes(Arrays.asList(encounterType)); } - + if (!visits.isEmpty()){ + encounterSearchCriteriaBuilder.setVisits(visits); + } EncounterSearchCriteria encounterSearchCriteria = encounterSearchCriteriaBuilder.createEncounterSearchCriteria(); List encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);