Search in sources :

Example 11 with ConceptSearchResult

use of org.openmrs.ConceptSearchResult in project openmrs-core by openmrs.

the class ConceptServiceTest method getConcepts_shouldReturnPreferredNamesHigher.

/**
 * @see ConceptService#getConcepts(String,List,boolean,List,List,List,List,Concept,Integer,Integer)
 */
@Test
public void getConcepts_shouldReturnPreferredNamesHigher() {
    Concept hivProgram = conceptService.getConceptByName("hiv program");
    ConceptName synonym = new ConceptName("synonym", Context.getLocale());
    hivProgram.addName(synonym);
    conceptService.saveConcept(hivProgram);
    Concept mdrTbProgram = conceptService.getConceptByName("mdr-tb program");
    synonym = new ConceptName("synonym", Context.getLocale());
    synonym.setLocalePreferred(true);
    mdrTbProgram.addName(synonym);
    conceptService.saveConcept(mdrTbProgram);
    updateSearchIndex();
    List<ConceptSearchResult> concepts = conceptService.getConcepts("synonym", null, false, null, null, null, null, null, null, null);
    assertThat(concepts, contains(hasConcept(is(mdrTbProgram)), hasConcept(is(hivProgram))));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) ConceptSearchResult(org.openmrs.ConceptSearchResult) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 12 with ConceptSearchResult

use of org.openmrs.ConceptSearchResult in project openmrs-core by openmrs.

the class ConceptServiceTest method getConcepts_shouldNotReturnConceptsWithMatchingNamesThatAreVoided.

/**
 * @see ConceptService#getConcepts(String,List<Locale>,null,List<ConceptClass>,List<
 *      ConceptClass>,List<ConceptDatatype>,List<ConceptDatatype>,Concept,Integer,Integer)
 */
@Test
public void getConcepts_shouldNotReturnConceptsWithMatchingNamesThatAreVoided() {
    Concept concept = conceptService.getConcept(7);
    List<ConceptSearchResult> results = conceptService.getConcepts("VOIDED", Collections.singletonList(Locale.ENGLISH), false, null, null, null, null, null, null, null);
    for (ConceptSearchResult result : results) {
        assertThat(result.getConcept(), not(concept));
    }
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptSearchResult(org.openmrs.ConceptSearchResult) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 13 with ConceptSearchResult

use of org.openmrs.ConceptSearchResult in project openmrs-core by openmrs.

the class ConceptServiceTest method getConcepts_shouldFindConceptByFullCode.

/**
 * @see ConceptService#getConcepts(String,List,boolean,List,List,List,List,Concept,Integer,Integer)
 */
@Test
public void getConcepts_shouldFindConceptByFullCode() {
    // given
    String code1 = "CD41003";
    String code2 = "7345693";
    Concept concept = conceptService.getConceptByMapping(code2, "SNOMED CT");
    // when
    List<ConceptSearchResult> concepts1 = conceptService.getConcepts(code1, Collections.singletonList(Context.getLocale()), false, null, null, null, null, null, null, null);
    List<ConceptSearchResult> concepts2 = conceptService.getConcepts(code2, Collections.singletonList(Context.getLocale()), false, null, null, null, null, null, null, null);
    // then
    assertThat(concepts1, contains(hasConcept(is(concept))));
    assertThat(concepts2, contains(hasConcept(is(concept))));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptSearchResult(org.openmrs.ConceptSearchResult) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 14 with ConceptSearchResult

use of org.openmrs.ConceptSearchResult in project openmrs-core by openmrs.

the class ConceptServiceTest method getConcepts_shouldReturnASearchResultForPhraseWithStopWords.

/**
 * @see ConceptService#getConcepts(String, List, boolean, List, List, List, List, Concept, Integer, Integer)
 */
@Test
public void getConcepts_shouldReturnASearchResultForPhraseWithStopWords() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-names.xml");
    conceptService.saveConceptStopWord(new ConceptStopWord("OF", Locale.US));
    List<ConceptSearchResult> searchResults = conceptService.getConcepts("tuberculosis of knee", Collections.singletonList(new Locale("en", "US")), false, null, null, null, null, null, null, null);
    Assert.assertEquals(1, searchResults.size());
    Assert.assertEquals("Tuberculosis of Knee", searchResults.get(0).getConceptName().getName());
}
Also used : Locale(java.util.Locale) ConceptStopWord(org.openmrs.ConceptStopWord) ConceptSearchResult(org.openmrs.ConceptSearchResult) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 15 with ConceptSearchResult

use of org.openmrs.ConceptSearchResult in project openmrs-core by openmrs.

the class ConceptServiceTest method getConcepts_shouldPassWithAndOrNotWords.

/**
 * @see ConceptService#getConcepts(String, List, boolean, List, List, List, List, Concept, Integer, Integer)
 */
@Test
public void getConcepts_shouldPassWithAndOrNotWords() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-names.xml");
    // search phrase with AND
    List<ConceptSearchResult> searchResults = conceptService.getConcepts("AND SALBUTAMOL INHALER", Collections.singletonList(new Locale("en", "US")), false, null, null, null, null, null, null, null);
    Assert.assertEquals(1, searchResults.size());
    assertThat(searchResults.get(0).getWord(), is("AND SALBUTAMOL INHALER"));
    // search phrase with OR
    searchResults = conceptService.getConcepts("SALBUTAMOL OR INHALER", Collections.singletonList(new Locale("en", "US")), false, null, null, null, null, null, null, null);
    Assert.assertEquals(1, searchResults.size());
    assertThat(searchResults.get(0).getWord(), is("SALBUTAMOL OR INHALER"));
    // search phrase with NOT
    searchResults = conceptService.getConcepts("SALBUTAMOL INHALER NOT", Collections.singletonList(new Locale("en", "US")), false, null, null, null, null, null, null, null);
    Assert.assertEquals(1, searchResults.size());
    assertThat(searchResults.get(0).getWord(), is("SALBUTAMOL INHALER NOT"));
}
Also used : Locale(java.util.Locale) ConceptSearchResult(org.openmrs.ConceptSearchResult) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptSearchResult (org.openmrs.ConceptSearchResult)16 Test (org.junit.Test)10 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)10 Locale (java.util.Locale)8 Concept (org.openmrs.Concept)8 ArrayList (java.util.ArrayList)5 SimpleObject (org.openmrs.ui.framework.SimpleObject)5 ConceptName (org.openmrs.ConceptName)4 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)4 Method (java.lang.reflect.Method)2 Ignore (org.junit.Ignore)2 ConceptClass (org.openmrs.ConceptClass)2 ConceptDatatype (org.openmrs.ConceptDatatype)2 ConceptSource (org.openmrs.ConceptSource)2 ConceptService (org.openmrs.api.ConceptService)2 CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)2 IOException (java.io.IOException)1 ConceptDescription (org.openmrs.ConceptDescription)1 ConceptStopWord (org.openmrs.ConceptStopWord)1 DiagnosesFragmentController (org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController)1