use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class HibernateConceptDAO method getConcepts.
/**
* @see org.openmrs.api.db.ConceptDAO#getConcepts(java.lang.String, java.util.Locale, boolean,
* java.util.List, java.util.List)
*/
@Override
public List<Concept> getConcepts(final String name, final Locale loc, final boolean searchOnPhrase, final List<ConceptClass> classes, final List<ConceptDatatype> datatypes) throws DAOException {
final Locale locale;
if (loc == null) {
locale = Context.getLocale();
} else {
locale = loc;
}
LuceneQuery<ConceptName> conceptNameQuery = newConceptNameLuceneQuery(name, !searchOnPhrase, Collections.singletonList(locale), false, false, classes, null, datatypes, null, null);
List<ConceptName> names = conceptNameQuery.list();
return new ArrayList<>(transformNamesToConcepts(names));
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class HibernateConceptDAO method isConceptNameDuplicate.
/**
* @see org.openmrs.api.db.ConceptDAO#isConceptNameDuplicate(org.openmrs.ConceptName)
*/
@Override
public boolean isConceptNameDuplicate(ConceptName name) {
if (name.getVoided()) {
return false;
}
if (name.getConcept() != null) {
if (name.getConcept().getRetired()) {
return false;
}
// a search term is set.
if (!name.equals(name.getConcept().getName(name.getLocale()))) {
return false;
}
}
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptName.class);
criteria.add(Restrictions.eq("voided", false));
criteria.add(Restrictions.or(Restrictions.eq("locale", name.getLocale()), Restrictions.eq("locale", new Locale(name.getLocale().getLanguage()))));
if (Context.getAdministrationService().isDatabaseStringComparisonCaseSensitive()) {
criteria.add(Restrictions.eq("name", name.getName()).ignoreCase());
} else {
criteria.add(Restrictions.eq("name", name.getName()));
}
List<ConceptName> candidateNames = criteria.list();
for (ConceptName candidateName : candidateNames) {
if (candidateName.getConcept().getRetired()) {
continue;
}
if (candidateName.getConcept().equals(name.getConcept())) {
continue;
}
// If it is a default name for a concept
if (candidateName.getConcept().getName(candidateName.getLocale()).equals(candidateName)) {
return true;
}
}
return false;
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class HibernateConceptDAO method newConceptNameLuceneQuery.
private LuceneQuery<ConceptName> newConceptNameLuceneQuery(final String phrase, boolean searchKeywords, List<Locale> locales, boolean searchExactLocale, boolean includeRetired, List<ConceptClass> requireClasses, List<ConceptClass> excludeClasses, List<ConceptDatatype> requireDatatypes, List<ConceptDatatype> excludeDatatypes, Concept answersToConcept) {
final StringBuilder query = new StringBuilder();
if (!StringUtils.isBlank(phrase)) {
final Set<Locale> searchLocales;
if (locales == null) {
searchLocales = new HashSet<>(Collections.singletonList(Context.getLocale()));
} else {
searchLocales = new HashSet<>(locales);
}
query.append(newConceptNameQuery(phrase, searchKeywords, searchLocales, searchExactLocale));
}
LuceneQuery<ConceptName> luceneQuery = LuceneQuery.newQuery(ConceptName.class, sessionFactory.getCurrentSession(), query.toString()).include("concept.conceptClass.conceptClassId", transformToIds(requireClasses)).exclude("concept.conceptClass.conceptClassId", transformToIds(excludeClasses)).include("concept.datatype.conceptDatatypeId", transformToIds(requireDatatypes)).exclude("concept.datatype.conceptDatatypeId", transformToIds(excludeDatatypes));
if (answersToConcept != null) {
Collection<ConceptAnswer> answers = answersToConcept.getAnswers(false);
if (answers != null && !answers.isEmpty()) {
List<Integer> ids = new ArrayList<>();
for (ConceptAnswer conceptAnswer : answersToConcept.getAnswers(false)) {
ids.add(conceptAnswer.getAnswerConcept().getId());
}
luceneQuery.include("concept.conceptId", ids.toArray(new Object[0]));
}
}
if (!includeRetired) {
luceneQuery.include("concept.retired", false);
}
luceneQuery.skipSame("concept.conceptId");
return luceneQuery;
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ObsServiceTest method getObservationCount_shouldIncludeVoidedObservationsUsingTheSpecifiedConceptNamesAsAnswers.
/**
* @see ObsService#getObservationCount(List, boolean)
*/
@Test
public void getObservationCount_shouldIncludeVoidedObservationsUsingTheSpecifiedConceptNamesAsAnswers() {
ObsService os = Context.getObsService();
Obs o = new Obs();
o.setConcept(Context.getConceptService().getConcept(3));
o.setPerson(new Patient(2));
o.setEncounter(new Encounter(3));
o.setObsDatetime(new Date());
o.setLocation(new Location(1));
ConceptName cn1 = new ConceptName(1847);
o.setValueCodedName(cn1);
os.saveObs(o, null);
Obs o2 = new Obs();
o2.setConcept(Context.getConceptService().getConcept(3));
o2.setPerson(new Patient(2));
o2.setEncounter(new Encounter(3));
o2.setObsDatetime(new Date());
o2.setLocation(new Location(1));
ConceptName cn2 = new ConceptName(2453);
o2.setValueCodedName(cn2);
o2.setVoided(true);
os.saveObs(o2, null);
List<ConceptName> names = new LinkedList<>();
names.add(cn1);
names.add(cn2);
Assert.assertEquals(2, os.getObservationCount(names, true).intValue());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ObsServiceTest method getObservationCount_shouldReturnZeroIfNoObservationIsUsingAnyOfTheConcepNamesInTheList.
/**
* @see ObsService#getObservationCount(List, boolean)
*/
@Test
public void getObservationCount_shouldReturnZeroIfNoObservationIsUsingAnyOfTheConcepNamesInTheList() {
List<ConceptName> names = new LinkedList<>();
names.add(new ConceptName(1847));
names.add(new ConceptName(2453));
Assert.assertEquals(0, Context.getObsService().getObservationCount(names, true).intValue());
}
Aggregations