Search in sources :

Example 81 with ConceptName

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));
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName)

Example 82 with ConceptName

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;
}
Also used : Locale(java.util.Locale) ConceptName(org.openmrs.ConceptName) Criteria(org.hibernate.Criteria)

Example 83 with ConceptName

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;
}
Also used : Locale(java.util.Locale) ConceptAnswer(org.openmrs.ConceptAnswer) ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName) OpenmrsObject(org.openmrs.OpenmrsObject)

Example 84 with ConceptName

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());
}
Also used : Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ConceptName(org.openmrs.ConceptName) Date(java.util.Date) LinkedList(java.util.LinkedList) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 85 with ConceptName

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());
}
Also used : ConceptName(org.openmrs.ConceptName) LinkedList(java.util.LinkedList) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptName (org.openmrs.ConceptName)100 Test (org.junit.Test)78 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)71 Concept (org.openmrs.Concept)62 ConceptDescription (org.openmrs.ConceptDescription)42 ConceptDatatype (org.openmrs.ConceptDatatype)34 ConceptClass (org.openmrs.ConceptClass)33 Locale (java.util.Locale)32 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)22 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 Obs (org.openmrs.Obs)9 BindException (org.springframework.validation.BindException)8 ConceptMap (org.openmrs.ConceptMap)7 Errors (org.springframework.validation.Errors)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Patient (org.openmrs.Patient)6 Encounter (org.openmrs.Encounter)5 OrderFrequency (org.openmrs.OrderFrequency)5