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