Search in sources :

Example 1 with ConceptSearchResult

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

the class HibernateConceptDAO method getConcepts.

/**
 * @see ConceptDAO#getConcepts(String, List, boolean, List, List, List, List, Concept, Integer,
 *      Integer)
 */
@Override
public List<ConceptSearchResult> getConcepts(final String phrase, final List<Locale> locales, final boolean includeRetired, final List<ConceptClass> requireClasses, final List<ConceptClass> excludeClasses, final List<ConceptDatatype> requireDatatypes, final List<ConceptDatatype> excludeDatatypes, final Concept answersToConcept, final Integer start, final Integer size) throws DAOException {
    LuceneQuery<ConceptName> query = newConceptNameLuceneQuery(phrase, true, locales, false, includeRetired, requireClasses, excludeClasses, requireDatatypes, excludeDatatypes, answersToConcept);
    ListPart<ConceptName> names = query.listPart(start, size);
    List<ConceptSearchResult> results = new ArrayList<>();
    for (ConceptName name : names.getList()) {
        results.add(new ConceptSearchResult(phrase, name.getConcept(), name));
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Example 2 with ConceptSearchResult

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

the class ConceptServiceImplTest method getConcepts_shouldGiveAListOfConceptSearchResultForTheMatchingConcepts.

/**
 * @see ConceptServiceImpl#getConcepts(String, Locale, boolean)
 */
@Test
public void getConcepts_shouldGiveAListOfConceptSearchResultForTheMatchingConcepts() {
    Locale locale = new Locale("en", "GB");
    String phrase = "CD4 COUNT";
    List<ConceptSearchResult> res = conceptService.getConcepts(phrase, locale, true);
    assertEquals(res.get(0).getConceptName().getName(), phrase);
}
Also used : Locale(java.util.Locale) ConceptSearchResult(org.openmrs.ConceptSearchResult) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with ConceptSearchResult

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

the class ConceptServiceImplTest method findConceptAnswers_shouldReturnAListOfAllMatchingConceptSearchResults.

/**
 * @see ConceptServiceImpl#findConceptAnswers(String, Locale, Concept)
 */
@Test
public void findConceptAnswers_shouldReturnAListOfAllMatchingConceptSearchResults() {
    Locale locale = new Locale("en", "GB");
    String phrase = "CD4 COUNT";
    int conceptId = 5497;
    List<ConceptSearchResult> concepts = conceptService.findConceptAnswers(phrase, locale, conceptService.getConcept(conceptId));
    assertEquals(concepts.get(0).getConceptName().getName(), phrase);
}
Also used : Locale(java.util.Locale) ConceptSearchResult(org.openmrs.ConceptSearchResult) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with ConceptSearchResult

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

the class ConceptServiceTest method getOrderableConcepts_shouldGetOrderableConcepts.

/**
 * @see ConceptService#getOrderableConcepts(String, java.util.List, boolean, Integer, Integer)
 */
@Test
public void getOrderableConcepts_shouldGetOrderableConcepts() {
    // In current data set order_type_map table contains conceptClass 1 and 3.
    // Using that adding two concepts to test the functionality
    ConceptService cs = Context.getConceptService();
    ConceptClass cc1 = cs.getConceptClass(1);
    ConceptClass cc3 = cs.getConceptClass(3);
    Locale locale = Locale.ENGLISH;
    ConceptDatatype dt = cs.getConceptDatatype(4);
    Concept c1 = new Concept();
    ConceptName cn1a = new ConceptName("ONE TERM", locale);
    c1.addName(cn1a);
    c1.addDescription(new ConceptDescription("some description", null));
    c1.setConceptClass(cc1);
    c1.setDatatype(dt);
    cs.saveConcept(c1);
    Concept c2 = new Concept();
    ConceptName cn2a = new ConceptName("ONE TO MANY", locale);
    c2.addName(cn2a);
    c2.addDescription(new ConceptDescription("some description", null));
    c2.setConceptClass(cc3);
    c2.setDatatype(dt);
    cs.saveConcept(c2);
    updateSearchIndex();
    List<ConceptSearchResult> conceptSearchResultList = Context.getConceptService().getOrderableConcepts("one", Collections.singletonList(locale), true, null, null);
    assertEquals(2, conceptSearchResultList.size());
}
Also used : Locale(java.util.Locale) OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptSearchResult(org.openmrs.ConceptSearchResult) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 5 with ConceptSearchResult

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

the class ConceptDAOTest method getConcepts_shouldReturnCorrectResultsForConceptWithNamesThatContainsWordsWithMoreWeight.

/**
 * @see {@link
 *      ConceptDAO#getConcepts(String,List<Locale>,null,List<ConceptClass>,List<ConceptClass
 *      >,List<ConceptDatatype>,List<ConceptDatatype>,Concept,Integer,Integer)}
 */
@SuppressWarnings("unchecked")
@Test
@Ignore
public void getConcepts_shouldReturnCorrectResultsForConceptWithNamesThatContainsWordsWithMoreWeight() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-words.xml");
    Concept conceptWithMultipleMatchingNames = dao.getConcept(3000);
    // recalculate the weights just in case the logic for calculating the weights is changed
    ConceptService cs = Context.getConceptService();
    cs.updateConceptIndex(conceptWithMultipleMatchingNames);
    cs.updateConceptIndex(dao.getConcept(4000));
    List<ConceptSearchResult> searchResults = dao.getConcepts("trust", Collections.singletonList(Locale.ENGLISH), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null, null, null);
    Assert.assertEquals(2, searchResults.size());
    // the first concept is the one with a word with the highest weight
    Assert.assertEquals(conceptWithMultipleMatchingNames, searchResults.get(0).getConcept());
    // For conceptId=3000, its search result should ALWAYS match on 'TRUST ME' because it is shorter THAN 'TRUST ALWAYS'
    Assert.assertEquals(9998, searchResults.get(0).getConceptName().getConceptNameId().intValue());
}
Also used : Concept(org.openmrs.Concept) ConceptSearchResult(org.openmrs.ConceptSearchResult) ConceptService(org.openmrs.api.ConceptService) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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