@Override public PageableResult search(String parentUuid, RequestContext context) throws ResponseException { String attributeType = context.getParameter("attributeType"); if (StringUtils.isBlank(attributeType) || StringUtils.isBlank(parentUuid)) { return new EmptySearchResult(); } Location parentLocation = Context.getLocationService().getLocationByUuid(parentUuid); List<LocationAttribute> results = new ArrayList<LocationAttribute>(); for (LocationAttribute activeAttribute : parentLocation.getActiveAttributes()) { if (activeAttribute.getAttributeType().getUuid().equals(attributeType)) { results.add(activeAttribute); } } return new AlreadyPaged<LocationAttribute>(context, results, false); } }
/** * @see BasePageableResult#toSimpleObject(Converter) * @verifies add property totalCount if context contains parameter totalCount which is true */ @Test public void toSimpleObject_shouldAddPropertyTotalCountIfContextContainsParameterTotalCountWhichIsTrue() throws Exception { request.addParameter("totalCount", "true"); AlreadyPaged<Order> needsPaging = new AlreadyPaged<Order>(context, orders, false, (long) orders.size()); SimpleObject result = needsPaging.toSimpleObject(converter); assertTrue(result.containsKey("totalCount")); assertThat((Long) result.get("totalCount"), is((long) orders.size())); assertThat(needsPaging.getTotalCount(), is((long) orders.size())); }
/** * @see BasePageableResult#toSimpleObject(Converter) * @verifies not add property totalCount if context does not contains parameter totalCount */ @Test public void toSimpleObject_shouldNotAddPropertyTotalCountIfContextDoesNotContainsParameterTotalCount() throws Exception { AlreadyPaged<Order> needsPaging = new AlreadyPaged<Order>(context, orders, false, (long) orders.size()); SimpleObject result = needsPaging.toSimpleObject(converter); assertFalse(result.containsKey("totalCount")); } }
/** * @see BasePageableResult#toSimpleObject(Converter) * @verifies not add property totalCount if context contains parameter totalCount which is false */ @Test public void toSimpleObject_shouldNotAddPropertyTotalCountIfContextContainsParameterTotalCountWhichIsFalse() throws Exception { request.addParameter("totalCount", "false"); AlreadyPaged<Order> needsPaging = new AlreadyPaged<Order>(context, orders, false, (long) orders.size()); SimpleObject result = needsPaging.toSimpleObject(converter); assertFalse(result.containsKey("totalCount")); }
/** * 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); }
Collections.<ConceptDatatype> emptyList(), Collections.<ConceptDatatype> emptyList(), answerTo); boolean hasMore = count > startIndex + limit; result = new AlreadyPaged<Concept>(context, results, hasMore); } else { result = new NeedsPaging<Concept>(results, context);
List<ConceptReferenceTerm> terms = conceptService.getConceptReferenceTerms(null, conceptSource, context.getStartIndex(), context.getLimit(), context.getIncludeAll()); return new AlreadyPaged<ConceptReferenceTerm>(context, terms, context.getIncludeAll()); } else if (searchType.equals(SEARCH_TYPE_EQUAL)) { if (conceptSource != null) { return new EmptySearchResult(); } else { return new AlreadyPaged<ConceptReferenceTerm>(context, Arrays.asList(term), false); return new AlreadyPaged<ConceptReferenceTerm>(context, equalTerms.subList(context.getStartIndex(), toIndex), hasMoreTerms); } else { boolean hasMoreTerms = termsCount > (context.getStartIndex() + context.getLimit()); return new AlreadyPaged<ConceptReferenceTerm>(context, terms, hasMoreTerms);
/** * Drug searches support the following query parameters: * <ul> * <li>q=(name): searches drug with name containing the query string</li> * </ul> * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(RequestContext) */ @Override protected PageableResult doSearch(RequestContext ctx) { boolean searchOnPhrase = true; boolean searchDrugConceptNames = false; boolean includeRetired = ctx.getIncludeAll(); Integer startIndex = ctx.getStartIndex(); Integer limit = ctx.getLimit(); String drugName = ctx.getParameter("q"); Integer countOfDrugs = Context.getConceptService().getCountOfDrugs(drugName, null, searchOnPhrase, searchDrugConceptNames, includeRetired); List<Drug> drugs = Context.getConceptService().getDrugs(drugName, null, searchOnPhrase, searchDrugConceptNames, includeRetired, startIndex, limit); boolean hasMore = countOfDrugs > startIndex + limit; return new AlreadyPaged<Drug>(ctx, drugs, hasMore); } }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected PageableResult doSearch(RequestContext context) { ConceptService cs = Context.getConceptService(); String query = context.getParameter("q"); if (query == null) return new EmptySearchResult(); List<ConceptReferenceTerm> terms = cs.getConceptReferenceTerms(query, null, context.getStartIndex(), context.getLimit(), context.getIncludeAll()); int count = cs.getCountOfConceptReferenceTerms(query, null, context.getIncludeAll()); boolean hasMore = count > context.getStartIndex() + context.getLimit(); return new AlreadyPaged<ConceptReferenceTerm>(context, terms, hasMore); }
/** * @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 query = context.getParameter("q"); if (query == null) { return new EmptySearchResult(); } List<Provider> providers = Context.getProviderService().getProviders(query, context.getStartIndex(), context.getLimit(), null, context.getIncludeAll()); int count = Context.getProviderService().getCountOfProviders(query, context.getIncludeAll()); boolean hasMore = count > context.getStartIndex() + context.getLimit(); return new AlreadyPaged<Provider>(context, providers, hasMore); }