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;
}
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);
}
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);
}
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());
}
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());
}
Aggregations