Search in sources :

Example 1 with ConceptMapType

use of org.openmrs.ConceptMapType in project openmrs-module-pihcore by PIH.

the class PastMedicalHistoryCheckboxTagHandlerTest method setupConcepts.

private void setupConcepts() throws Exception {
    // copied from some pihcore concept setup, but tweaked to work with standardTestDataset.xml
    ConceptDatatype coded = MetadataUtils.existing(ConceptDatatype.class, CoreConceptMetadataBundle.ConceptDatatypes.CODED);
    ConceptDatatype text = MetadataUtils.existing(ConceptDatatype.class, CoreConceptMetadataBundle.ConceptDatatypes.TEXT);
    ConceptDatatype notApplicable = MetadataUtils.existing(ConceptDatatype.class, CoreConceptMetadataBundle.ConceptDatatypes.N_A);
    ConceptClass diagnosis = MetadataUtils.existing(ConceptClass.class, "938834bf-a745-4dbd-b611-f06a9a5a3060");
    ConceptClass question = MetadataUtils.existing(ConceptClass.class, "a82ef63c-e4e4-48d6-988a-fdd74d7541a7");
    ConceptClass misc = MetadataUtils.existing(ConceptClass.class, "ecdee8a7-d741-4fe7-8e01-f79cacbe97bc");
    ConceptMapType sameAs = MetadataUtils.existing(ConceptMapType.class, CoreConceptMetadataBundle.ConceptMapTypes.SAME_AS);
    ConceptSource ciel = conceptSource("CIEL", "Columbia International eHealth Laboratory concept ID", null, CoreConceptMetadataBundle.ConceptSources.CIEL);
    conceptService.saveConceptSource(ciel);
    // these are in standardTestDataset.xml
    Concept no = conceptService.getConcept(8);
    Concept unknown = conceptService.getConcept(22);
    // need this to have a different UUID to match our dictionary
    yes = conceptService.getConcept(7);
    yes.setUuid(CommonConcepts.Concepts.YES);
    conceptService.saveConcept(yes);
    Concept pmhWhich = install(new ConceptBuilder(ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_FINDING).datatype(coded).conceptClass(diagnosis).name("1908BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "Past medical history finding", Locale.ENGLISH, ConceptNameType.FULLY_SPECIFIED).description("1470FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "Coded list of past medical history problems but not procedures which are coded under Past Surgical History.", Locale.ENGLISH).mapping(new ConceptMapBuilder("171868ABBBBBBBBBBBBBBBBBBBBBBBBBBBBB").type(sameAs).ensureTerm(ciel, "1628").build()).build());
    Concept isSymptomPresent = install(new ConceptBuilder(ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_PRESENCE).datatype(coded).conceptClass(diagnosis).name("2009BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "Sign/symptom present", Locale.ENGLISH, ConceptNameType.FULLY_SPECIFIED).answers(yes, no, unknown).mapping(new ConceptMapBuilder("171968ABBBBBBBBBBBBBBBBBBBBBBBBBBBBB").type(sameAs).ensureTerm(ciel, "1729").build()).build());
    // TODO waiting for confirmation from Andy that this is appropriate as comments
    Concept pmhComment = install(new ConceptBuilder(ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_COMMENT).datatype(text).conceptClass(question).name("108123BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "Past medical history added (text)", Locale.ENGLISH, ConceptNameType.FULLY_SPECIFIED).mapping(new ConceptMapBuilder("217354ABBBBBBBBBBBBBBBBBBBBBBBBBBBBB").type(sameAs).ensureTerm(ciel, "160221").build()).build());
    Concept pmhConstruct = install(new ConceptBuilder(ClinicalConsultationConcepts.Concepts.PAST_MEDICAL_HISTORY_CONSTRUCT).datatype(notApplicable).conceptClass(misc).name("1913BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "Past medical history", Locale.ENGLISH, ConceptNameType.FULLY_SPECIFIED).name("86916BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "PMH", Locale.ENGLISH, ConceptNameType.SHORT).setMembers(pmhWhich, isSymptomPresent, pmhComment).mapping(new ConceptMapBuilder("171873ABBBBBBBBBBBBBBBBBBBBBBBBBBBBB").type(sameAs).ensureTerm(ciel, "1633").build()).build());
}
Also used : Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptMapType(org.openmrs.ConceptMapType) ConceptBuilder(org.openmrs.module.metadatadeploy.builder.ConceptBuilder) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder) ConceptSource(org.openmrs.ConceptSource) ConceptDatatype(org.openmrs.ConceptDatatype)

Example 2 with ConceptMapType

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

the class HibernateConceptDAO method getDefaultConceptMapType.

/**
 * @see org.openmrs.api.db.ConceptDAO#getDefaultConceptMapType()
 */
@Override
public ConceptMapType getDefaultConceptMapType() throws DAOException {
    FlushMode previousFlushMode = sessionFactory.getCurrentSession().getFlushMode();
    sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL);
    try {
        // Defaults to same-as if the gp is not set.
        String defaultConceptMapType = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE);
        if (defaultConceptMapType == null) {
            throw new DAOException("The default concept map type is not set. You need to set the '" + OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE + "' global property.");
        }
        ConceptMapType conceptMapType = getConceptMapTypeByName(defaultConceptMapType);
        if (conceptMapType == null) {
            throw new DAOException("The default concept map type (name: " + defaultConceptMapType + ") does not exist! You need to set the '" + OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE + "' global property.");
        }
        return conceptMapType;
    } finally {
        sessionFactory.getCurrentSession().setFlushMode(previousFlushMode);
    }
}
Also used : DAOException(org.openmrs.api.db.DAOException) ConceptMapType(org.openmrs.ConceptMapType) FlushMode(org.hibernate.FlushMode)

Example 3 with ConceptMapType

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

the class HibernateConceptDAO method getConceptMapTypes.

/**
 * @see org.openmrs.api.db.ConceptDAO#getConceptMapTypes(boolean, boolean)
 */
@SuppressWarnings("unchecked")
@Override
public List<ConceptMapType> getConceptMapTypes(boolean includeRetired, boolean includeHidden) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptMapType.class);
    if (!includeRetired) {
        criteria.add(Restrictions.eq("retired", false));
    }
    if (!includeHidden) {
        criteria.add(Restrictions.eq("isHidden", false));
    }
    List<ConceptMapType> conceptMapTypes = criteria.list();
    conceptMapTypes.sort(new ConceptMapTypeComparator());
    return conceptMapTypes;
}
Also used : ConceptMapType(org.openmrs.ConceptMapType) ConceptMapTypeComparator(org.openmrs.util.ConceptMapTypeComparator) Criteria(org.hibernate.Criteria)

Example 4 with ConceptMapType

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

the class HibernateConceptDAO method getConceptMapTypeByName.

/**
 * @see org.openmrs.api.db.ConceptDAO#getConceptMapTypeByName(java.lang.String)
 */
@Override
public ConceptMapType getConceptMapTypeByName(String name) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptMapType.class);
    criteria.add(Restrictions.ilike("name", name, MatchMode.EXACT));
    return (ConceptMapType) criteria.uniqueResult();
}
Also used : ConceptMapType(org.openmrs.ConceptMapType) Criteria(org.hibernate.Criteria)

Example 5 with ConceptMapType

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

the class ConceptMapTypeValidator method validate.

/**
 * Checks that a given concept map type object is valid.
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail if the concept map type object is null
 * @should fail if the name is null
 * @should fail if the name is an empty string
 * @should fail if the name is a white space character
 * @should fail if the concept map type name is a duplicate
 * @should pass if the name is unique amongst all concept map type names
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) {
    if (obj == null || !(obj instanceof ConceptMapType)) {
        throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + ConceptMapType.class);
    }
    ConceptMapType conceptMapType = (ConceptMapType) obj;
    String name = conceptMapType.getName();
    if (!StringUtils.hasText(name)) {
        errors.rejectValue("name", "ConceptMapType.error.nameRequired", "The name property is required for a concept map type");
        return;
    }
    name = name.trim();
    ConceptMapType duplicate = Context.getConceptService().getConceptMapTypeByName(name);
    if (duplicate != null && !OpenmrsUtil.nullSafeEquals(duplicate.getUuid(), conceptMapType.getUuid())) {
        errors.rejectValue("name", "ConceptMapType.duplicate.name", "Duplicate concept map type name: " + name);
    }
    ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason");
}
Also used : ConceptMapType(org.openmrs.ConceptMapType)

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