/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected AlreadyPaged<Patient> doSearch(RequestContext context) { return new ServiceSearcher<Patient>(PatientService.class, "getPatients", "getCountOfPatients").search( context.getParameter("q"), context); }
/** * Finds and invokes a search method whose name is given by searchMethod and whose signature * includes one String, two Integers, and any number of boolean or Booleans * * @param service * @param query * @param context * @return */ private List<T> doPagedSearch(OpenmrsService service, String query, RequestContext context) { try { for (Method candidate : serviceClass.getMethods()) { if (candidate.getName().equals(searchMethod) && hasRightParameterTypes(candidate, 1, 2)) return invokePagedSearchMethod(service, candidate, query, context); } } catch (Exception ex) { throw new RuntimeException(searchMethod + " failed", ex); } throw new RuntimeException("Cannot find suitable method"); }
/** * Finds and invokes a count method whose name is given by countMethod and whose signature * includes one String, and any number of boolean or Booleans * * @param service * @param query * @param context * @return */ private int doCount(OpenmrsService service, String query, RequestContext context) { try { for (Method candidate : serviceClass.getMethods()) { if (candidate.getName().equals(countMethod) && hasRightParameterTypes(candidate, 1, 0)) { return invokeCountMethod(service, candidate, query, context); } } } catch (Exception ex) { throw new RuntimeException(countMethod + " failed", ex); } throw new RuntimeException("Cannot find suitable method"); }
/** * Makes service calls to get the count and search results for the given query, and packages * those up as an AlreadyPaged search result * * @param query * @param context * @return */ public AlreadyPaged<T> search(String query, RequestContext context) { OpenmrsService service = Context.getService(serviceClass); List<T> results; Integer count; results = doPagedSearch(service, query, context); count = doCount(service, query, context); boolean hasMore = count > context.getStartIndex() + context.getLimit(); return new AlreadyPaged<T>(context, results, hasMore); }
/** * Gets encounters for the given patient (paged according to context if necessary) only if a * patient parameter exists in the request set on the {@link RequestContext} otherwise searches * for encounters that match the specified query * * @param context * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected PageableResult doSearch(RequestContext context) { String patientUuid = context.getRequest().getParameter("patient"); if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult(); List<Encounter> encs = Context.getEncounterService().getEncountersByPatient(patient); return new NeedsPaging<Encounter>(encs, context); } return new ServiceSearcher<Encounter>(EncounterService.class, "getEncounters", "getCountOfEncounters").search( context.getParameter("q"), context); }