Search in sources :

Example 1 with ConceptClass

use of org.openmrs.ConceptClass 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 ConceptClass

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

the class ConceptClassValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if user is null or empty or whitespace
 * @should fail validation if name is already exist in non retired concept class
 * @should pass validation if description is null or empty or whitespace
 * @should pass validation if all required fields have proper values
 * @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) {
    ConceptClass cc = (ConceptClass) obj;
    if (cc == null) {
        errors.rejectValue("conceptClass", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
        if (!errors.hasErrors()) {
            ConceptClass exist = Context.getConceptService().getConceptClassByName(cc.getName());
            if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(cc.getUuid(), exist.getUuid())) {
                errors.rejectValue("name", "conceptclass.duplicate.name");
            }
        }
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason");
    }
}
Also used : ConceptClass(org.openmrs.ConceptClass)

Example 3 with ConceptClass

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

the class OrderTypeValidator method validate.

/**
 * Validates an Order object
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail if the orderType object is null
 * @should fail if name is null
 * @should fail if name is empty
 * @should fail if name is whitespace
 * @should fail if name is a duplicate
 * @should fail if conceptClass is a duplicate
 * @should fail if parent is among its descendants
 * @should fail if parent is also a direct child
 * @should pass if all fields are correct for a new order type
 * @should pass if all fields are correct for an existing order type
 * @should be invoked when an order type is saved
 * @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 OrderType)) {
        throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + OrderType.class);
    } else {
        OrderType orderType = (OrderType) obj;
        String name = orderType.getName();
        if (!StringUtils.hasText(name)) {
            errors.rejectValue("name", "error.name");
            return;
        }
        if (orderType.getParent() != null && OrderUtil.isType(orderType, orderType.getParent())) {
            errors.rejectValue("parent", "OrderType.parent.amongDescendants", new Object[] { orderType.getName() }, "Parent of " + orderType.getName() + " is among its descendants");
        }
        OrderType duplicate = Context.getOrderService().getOrderTypeByName(name);
        if (duplicate != null && !orderType.equals(duplicate)) {
            errors.rejectValue("name", "OrderType.duplicate.name", "Duplicate order type name: " + name);
        }
        for (OrderType ot : Context.getOrderService().getOrderTypes(true)) {
            if (ot != null) {
                // If this was an edit, skip past the order we are actually validating
                if (orderType.equals(ot)) {
                    continue;
                }
                int index = 0;
                for (ConceptClass cc : ot.getConceptClasses()) {
                    if (cc != null && orderType.getConceptClasses().contains(cc)) {
                        errors.rejectValue("conceptClasses[" + index + "]", "OrderType.duplicate", new Object[] { cc.getName(), orderType.getName() }, cc.getName() + " is already associated to another order type:" + orderType.getName());
                    }
                    index++;
                }
            }
        }
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason", "javaClassName");
    }
}
Also used : ConceptClass(org.openmrs.ConceptClass) OrderType(org.openmrs.OrderType)

Example 4 with ConceptClass

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

the class ConceptClassValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see ConceptClassValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    ConceptClass cc = new ConceptClass();
    cc.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    cc.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    cc.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with ConceptClass

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

the class ConceptClassValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

/**
 * @see ConceptClassValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    ConceptClass cc = new ConceptClass();
    cc.setName("name");
    cc.setDescription("some text");
    Errors errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptClass (org.openmrs.ConceptClass)55 Test (org.junit.Test)50 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)46 ConceptDatatype (org.openmrs.ConceptDatatype)38 ConceptName (org.openmrs.ConceptName)33 ConceptDescription (org.openmrs.ConceptDescription)31 Concept (org.openmrs.Concept)27 Locale (java.util.Locale)12 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)12 BindException (org.springframework.validation.BindException)9 Errors (org.springframework.validation.Errors)9 OrderType (org.openmrs.OrderType)5 HashSet (java.util.HashSet)4 ConceptMap (org.openmrs.ConceptMap)3 ConceptNumeric (org.openmrs.ConceptNumeric)3 ConceptBuilder (org.openmrs.module.emrapi.test.builder.ConceptBuilder)3 ConceptComplex (org.openmrs.ConceptComplex)2 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptSearchResult (org.openmrs.ConceptSearchResult)2 ConceptSource (org.openmrs.ConceptSource)2