use of org.openmrs.ConceptMapType in project openmrs-core by openmrs.
the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTermBOfAConceptReferenceTermMapIsNotSet.
/**
* @see ConceptReferenceTermValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfTermBOfAConceptReferenceTermMapIsNotSet() {
ConceptReferenceTerm term = new ConceptReferenceTerm();
term.setName("name");
term.setCode("code");
term.setConceptSource(Context.getConceptService().getConceptSource(1));
Set<ConceptReferenceTermMap> maps = new LinkedHashSet<>();
maps.add(new ConceptReferenceTermMap(null, new ConceptMapType(1)));
term.setConceptReferenceTermMaps(maps);
Errors errors = new BindException(term, "term");
new ConceptReferenceTermValidator().validate(term, errors);
Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[0].termB"));
}
use of org.openmrs.ConceptMapType in project openmrs-core by openmrs.
the class HibernateConceptDAO method getDrugByMapping.
/**
* @see org.openmrs.api.db.ConceptDAO#getDrugs
*/
@Override
public Drug getDrugByMapping(String code, ConceptSource conceptSource, Collection<ConceptMapType> withAnyOfTheseTypesOrOrderOfPreference) throws DAOException {
Criteria criteria = createSearchDrugByMappingCriteria(code, conceptSource, true);
// match with any of the supplied collection or order of preference of conceptMapTypes
if (!withAnyOfTheseTypesOrOrderOfPreference.isEmpty()) {
for (ConceptMapType conceptMapType : withAnyOfTheseTypesOrOrderOfPreference) {
criteria.add(Restrictions.eq("map.conceptMapType", conceptMapType));
List<Drug> drugs = criteria.list();
if (drugs.size() > 1) {
throw new DAOException("There are multiple matches for the highest-priority ConceptMapType");
} else if (drugs.size() == 1) {
return drugs.get(0);
}
// reset for the next execution to avoid unwanted AND clauses on every found map type
criteria = createSearchDrugByMappingCriteria(code, conceptSource, true);
}
} else {
List<Drug> drugs = criteria.list();
if (drugs.size() > 1) {
throw new DAOException("There are multiple matches for the highest-priority ConceptMapType");
} else if (drugs.size() == 1) {
return drugs.get(0);
}
}
return null;
}
use of org.openmrs.ConceptMapType in project openmrs-core by openmrs.
the class ConceptServiceTest method purgeConceptMapType_shouldDeleteTheSpecifiedConceptMapTypeFromTheDatabase.
/**
* @see ConceptService#purgeConceptMapType(ConceptMapType)
*/
@Test
public void purgeConceptMapType_shouldDeleteTheSpecifiedConceptMapTypeFromTheDatabase() {
// sanity check
ConceptMapType mapType = Context.getConceptService().getConceptMapType(1);
Assert.assertNotNull(mapType);
Context.getConceptService().purgeConceptMapType(mapType);
Assert.assertNull(Context.getConceptService().getConceptMapType(1));
}
use of org.openmrs.ConceptMapType in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConceptMapType_shouldUpdateAnExistingConceptMapType.
/**
* @see ConceptService#saveConceptMapType(ConceptMapType)
*/
@Test
public void saveConceptMapType_shouldUpdateAnExistingConceptMapType() {
ConceptMapType mapType = Context.getConceptService().getConceptMapType(1);
// sanity checks
Assert.assertNull(mapType.getDateChanged());
Assert.assertNull(mapType.getChangedBy());
mapType.setName("random name");
mapType.setDescription("random description");
ConceptMapType editedMapType = Context.getConceptService().saveConceptMapType(mapType);
Context.flushSession();
Assert.assertEquals("random name", editedMapType.getName());
Assert.assertEquals("random description", editedMapType.getDescription());
// date changed and changed by should have been updated
Assert.assertNotNull(editedMapType.getDateChanged());
Assert.assertNotNull(editedMapType.getChangedBy());
}
use of org.openmrs.ConceptMapType in project openmrs-core by openmrs.
the class ConceptServiceTest method getDrugsByMapping_shouldGetAListOfAllDrugsThatMatchOnAllTheParameterValues.
/**
* @see ConceptService#getDrugsByMapping(String, org.openmrs.ConceptSource,
* java.util.Collection, boolean)
*/
@Test
public void getDrugsByMapping_shouldGetAListOfAllDrugsThatMatchOnAllTheParameterValues() {
executeDataSet(GET_DRUG_MAPPINGS);
List<ConceptMapType> conceptMapTypeList = new ArrayList<>();
conceptMapTypeList.add(conceptService.getConceptMapType(1));
ConceptSource source = conceptService.getConceptSource(1);
List<Drug> drugs = conceptService.getDrugsByMapping("WGT234", source, conceptMapTypeList, false);
assertEquals(1, drugs.size());
assertTrue(containsId(drugs, 2));
}
Aggregations