/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test(expected = IllegalArgumentException.class) public void getDrugs_shouldRejectANullSearchPhrase() { conceptService.getDrugs(null, null, false, false); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldIncludeRetiredDrugsIfIncludeRetiredIsSetToTrue() { //Should be case insensitive final String searchPhrase = "Nyq"; List<Drug> drugs = conceptService.getDrugs(searchPhrase, null, false, false); assertEquals(0, drugs.size()); drugs = conceptService.getDrugs(searchPhrase, null, false, true); assertEquals(1, drugs.size()); assertEquals(11, drugs.get(0).getDrugId().intValue()); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldGetDrugsLinkedToConceptsWithNamesThatMatchThePhraseAndRelatedLocales() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-drugSearch.xml"); final String searchPhrase = "another"; //Should look only in the exact locale if exactLocale is set to true List<Drug> drugs = conceptService.getDrugs(searchPhrase, Locale.CANADA_FRENCH, true, false); assertThat(drugs, is(empty())); //Should look in broader locale if exactLocale is set to false drugs = conceptService.getDrugs(searchPhrase, Locale.CANADA_FRENCH, false, false); assertThat(drugs, contains(hasId(3))); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldGetDrugsLinkedToConceptsWithNamesThatMatchThePhraseAndLocale() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-drugSearch.xml"); final String searchPhrase = "some"; List<Drug> drugs = conceptService.getDrugs(searchPhrase, Locale.FRENCH, true, false); assertEquals(0, drugs.size()); drugs = conceptService.getDrugs(searchPhrase, Locale.CANADA_FRENCH, true, false); assertEquals(1, drugs.size()); assertEquals(3, drugs.get(0).getDrugId().intValue()); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldGetDrugsWithNamesMatchingTheSearchPhrase() { //Should be case insensitive List<Drug> drugs = conceptService.getDrugs("tri", null, false, false); assertThat(drugs, contains(conceptService.getDrug(2))); }
/** * @see ConceptService#getDrugs(String) */ @Test public void getDrugs_shouldNotReturnDrugsThatAreRetired() { List<Drug> drugs = Context.getConceptService().getDrugs("TEST_DRUG_NAME_RETIRED" /* is retired */); Assert.assertEquals(0, drugs.size()); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldGetDrugsLinkedToConceptsWithNamesThatMatchThePhrase() { final Integer expectedDrugId = 2; List<Drug> drugs = conceptService.getDrugs("stav", null, false, false); assertEquals(1, drugs.size()); assertEquals(expectedDrugId, drugs.get(0).getDrugId()); //should match anywhere in the concept name drugs = conceptService.getDrugs("lamiv", null, false, false); assertEquals(1, drugs.size()); assertEquals(expectedDrugId, drugs.get(0).getDrugId()); }
/** * @see ConceptService#getDrugs(String) */ @Test public void getDrugs_shouldReturnDrugsByDrugId() { Integer drugId = 2; Drug drug = Context.getConceptService().getDrug(drugId); List<Drug> drugs = Context.getConceptService().getDrugs(String.valueOf(drugId)); Assert.assertTrue(drugs.contains(drug)); }
@Test public void getDrugs_shouldReturnDrugsThatAreNotRetired() { List<Drug> drugs = Context.getConceptService().getDrugs("ASPIRIN" /* is not retired */); Assert.assertFalse(drugs.get(0).getRetired()); }
/** * @see ConceptService#getDrugs(String) */ @Test public void getDrugs_shouldNotFailIfThereisNoDrugByGivenDrugId() { List<Drug> drugs = Context.getConceptService().getDrugs("123456"); Assert.assertNotNull(drugs); }
/** * @see ConceptServiceImpl#getDrugs(String, Concept, boolean, boolean, boolean, Integer, * Integer) */ @Test public void getDrugs_shouldReturnListOfMatchingDrugs() { String drugName = "ASPIRIN"; String drugUuid = "05ec820a-d297-44e3-be6e-698531d9dd3f"; Concept concept = conceptService.getConceptByUuid(drugUuid); List<Drug> drugs = conceptService.getDrugs(drugName, concept, true, true, true, 0, 100); assertTrue(drugs.contains(conceptService.getDrug(drugName))); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldGetDrugsThatHaveMappingsWithReferenceTermCodesThatMatchThePhrase() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-drugSearch.xml"); List<Drug> drugs = conceptService.getDrugs("XXX", null, true, true); assertThat(drugs, contains(hasId(11), hasId(444))); }
/** * Ensures that unique drugs are returned in situations where more than one searched fields * match e.g drug name and linked concept name match the search phrase * * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldReturnUniqueDrugs() { //sanity check that drug.name and drug.concept.name will both match the search phrase Drug drug = conceptService.getDrug("ASPIRIN"); assertEquals(drug.getName().toLowerCase(), drug.getConcept().getName().getName().toLowerCase()); List<Drug> drugs = conceptService.getDrugs("Asp", null, false, false); assertEquals(1, drugs.size()); assertEquals(3, drugs.get(0).getDrugId().intValue()); }
/** * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldReturnAllDrugsWithAMatchingTermCodeOrDrugNameOrConceptName() { executeDataSet("org/openmrs/api/include/ConceptServiceTest-drugSearch.xml"); List<Drug> drugs = conceptService.getDrugs("XXX", null, false, true); assertThat(drugs, containsInAnyOrder(conceptService.getDrug(3), conceptService.getDrug(11), conceptService .getDrug(444))); }
/** * @see ConceptService#getDrugs(String) */ @Test public void getDrugs_shouldReturnDrugsByDrugConceptId() { Integer conceptId = 792; Drug drug = Context.getConceptService().getDrug(2); // assert that given drug has concept with tested id Assert.assertNotNull(drug.getConcept()); Assert.assertEquals(drug.getConcept().getConceptId(), conceptId); List<Drug> drugs = Context.getConceptService().getDrugs(String.valueOf(conceptId)); Assert.assertTrue(drugs.contains(drug)); }
drugs = conceptService.getDrugs(query); // this method returns retired drugs, so it is not ideal
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SearchHandler#search(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public PageableResult search(RequestContext context) throws ResponseException { String query = context.getParameter(REQUEST_PARAM_QUERY); String localeString = context.getParameter(REQUEST_PARAM_LOCALE); String exactLocaleString = context.getParameter(REQUEST_PARAM_EXACT_LOCALE); Locale locale = null; boolean exactLocale = false; if (StringUtils.isNotBlank(localeString)) { locale = LocaleUtility.fromSpecification(localeString); if (locale == null) { throw new InvalidSearchException("Unknown locale:" + localeString); } } if (StringUtils.isNotBlank(exactLocaleString)) { exactLocale = Boolean.valueOf(exactLocaleString); } List<Drug> drugs = conceptService.getDrugs(query, locale, exactLocale, context.getIncludeAll()); return new NeedsPaging<Drug>(drugs, context); } }
/** * 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); } }