Search in sources :

Example 26 with ConceptMapType

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"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Errors(org.springframework.validation.Errors) ConceptMapType(org.openmrs.ConceptMapType) ConceptReferenceTermMap(org.openmrs.ConceptReferenceTermMap) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with ConceptMapType

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;
}
Also used : Drug(org.openmrs.Drug) DAOException(org.openmrs.api.db.DAOException) ConceptMapType(org.openmrs.ConceptMapType) Criteria(org.hibernate.Criteria)

Example 28 with ConceptMapType

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

Example 29 with ConceptMapType

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

Example 30 with ConceptMapType

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

Aggregations

ConceptMapType (org.openmrs.ConceptMapType)34 Test (org.junit.Test)26 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 BindException (org.springframework.validation.BindException)10 Errors (org.springframework.validation.Errors)10 Drug (org.openmrs.Drug)8 ConceptSource (org.openmrs.ConceptSource)6 Criteria (org.hibernate.Criteria)3 ArrayList (java.util.ArrayList)2 Concept (org.openmrs.Concept)2 ConceptClass (org.openmrs.ConceptClass)2 ConceptDatatype (org.openmrs.ConceptDatatype)2 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)2 DrugReferenceMap (org.openmrs.DrugReferenceMap)2 DAOException (org.openmrs.api.db.DAOException)2 ConceptBuilder (org.openmrs.module.metadatadeploy.builder.ConceptBuilder)2 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 FlushMode (org.hibernate.FlushMode)1