Search in sources :

Example 76 with ConceptName

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

the class ConceptValidatorTest method validate_shouldFailIfATermIsMappedMultipleTimesToTheSameConcept.

@Test
public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameConcept() {
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    concept.addName(new ConceptName("my name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    ConceptMap map1 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1));
    concept.addConceptMapping(map1);
    ConceptMap map2 = new ConceptMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1));
    concept.addConceptMapping(map2);
    validator.validate(concept, errors);
    assertThat(errors, hasFieldErrors("conceptMappings[1]"));
}
Also used : ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptMap(org.openmrs.ConceptMap) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 77 with ConceptName

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

the class ConceptValidatorTest method validate_shouldPassIfTheDuplicateConceptNameIsNeitherPreferredNorFullySpecified.

@Test
public void validate_shouldPassIfTheDuplicateConceptNameIsNeitherPreferredNorFullySpecified() {
    Context.setLocale(new Locale("en", "GB"));
    Concept concept = cd4Count;
    // use a synonym as the duplicate name
    ConceptName duplicateName = concept.getSynonyms(Context.getLocale()).iterator().next();
    Assert.assertEquals(true, duplicateName.isSynonym());
    Concept anotherConcept = weight;
    anotherConcept.getFullySpecifiedName(Context.getLocale()).setName(duplicateName.getName());
    Errors errors = new BindException(anotherConcept, "concept");
    validator.validate(anotherConcept, errors);
    Assert.assertEquals(false, errors.hasErrors());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) HasFieldErrors.hasFieldErrors(org.openmrs.test.matchers.HasFieldErrors.hasFieldErrors) HasGlobalErrors.hasGlobalErrors(org.openmrs.test.matchers.HasGlobalErrors.hasGlobalErrors) ConceptName(org.openmrs.ConceptName) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 78 with ConceptName

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

the class ConceptValidatorTest method validate_shouldPassIfDifferentConceptsHaveTheSameShortNames.

@Test
public void validate_shouldPassIfDifferentConceptsHaveTheSameShortNames() {
    Context.setLocale(new Locale("en", "GB"));
    List<Concept> concepts = conceptService.getConceptsByName("HSM");
    Assert.assertEquals(1, concepts.size());
    Assert.assertEquals(true, concepts.get(0).getShortNameInLocale(Context.getLocale()).getName().equalsIgnoreCase("HSM"));
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    ConceptName conceptFullySpecifiedName = new ConceptName("holosystolic murmur", Context.getLocale());
    conceptFullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    ConceptName conceptShortName = new ConceptName("HSM", Context.getLocale());
    conceptShortName.setConceptNameType(ConceptNameType.SHORT);
    concept.addName(conceptFullySpecifiedName);
    concept.addName(conceptShortName);
    concept.addDescription(new ConceptDescription("some description", null));
    validator.validate(concept, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 79 with ConceptName

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

the class ConceptValidatorTest method validate_shouldPassIfNoneofTheConceptDescriptionsIsNull.

@Test
public void validate_shouldPassIfNoneofTheConceptDescriptionsIsNull() {
    concept.addName(new ConceptName("some name", Context.getLocale()));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setConceptClass(new ConceptClass());
    concept.setDatatype(new ConceptDatatype());
    validator.validate(concept, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 80 with ConceptName

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

the class HibernateConceptDAO method getConceptByName.

/**
 * @see org.openmrs.api.db.ConceptDAO#getConceptByName(java.lang.String)
 */
@Override
public Concept getConceptByName(final String name) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptName.class);
    Locale locale = Context.getLocale();
    Locale language = new Locale(locale.getLanguage() + "%");
    criteria.add(Restrictions.or(Restrictions.eq("locale", locale), Restrictions.like("locale", language)));
    if (Context.getAdministrationService().isDatabaseStringComparisonCaseSensitive()) {
        criteria.add(Restrictions.ilike("name", name));
    } else {
        criteria.add(Restrictions.eq("name", name));
    }
    criteria.add(Restrictions.eq("voided", false));
    criteria.createAlias("concept", "concept");
    criteria.add(Restrictions.eq("concept.retired", false));
    @SuppressWarnings("unchecked") List<ConceptName> list = criteria.list();
    LinkedHashSet<Concept> concepts = transformNamesToConcepts(list);
    if (concepts.size() == 1) {
        return concepts.iterator().next();
    } else if (list.isEmpty()) {
        log.warn("No concept found for '" + name + "'");
    } else {
        log.warn("Multiple concepts found for '" + name + "'");
        for (Concept concept : concepts) {
            for (ConceptName conceptName : concept.getNames(locale)) {
                if (conceptName.getName().equalsIgnoreCase(name)) {
                    return concept;
                }
            }
            for (ConceptName indexTerm : concept.getIndexTermsForLocale(locale)) {
                if (indexTerm.getName().equalsIgnoreCase(name)) {
                    return concept;
                }
            }
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) Criteria(org.hibernate.Criteria)

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