Search in sources :

Example 1 with DosingInstructions

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

the class DrugOrderValidator 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 asNeeded is null
 * @should fail validation if dosingType is null
 * @should fail validation if drug concept is different from order concept
 * @should fail validation if dose is null for SimpleDosingInstructions dosingType
 * @should fail validation if doseUnits is null for SimpleDosingInstructions dosingType
 * @should fail validation if route is null for SimpleDosingInstructions dosingType
 * @should fail validation if frequency is null for SimpleDosingInstructions dosingType
 * @should fail validation if dosingInstructions is null for FreeTextDosingInstructions
 *         dosingType
 * @should fail validation if numberOfRefills is null for outpatient careSetting
 * @should fail validation if quantity is null for outpatient careSetting
 * @should fail validation if doseUnits is null when dose is present
 * @should fail validation if doseUnits is not a dose unit concept
 * @should fail validation if quantityUnits is null when quantity is present
 * @should fail validation if quantityUnits it not a quantity unit concept
 * @should fail validation if durationUnits is null when duration is present
 * @should fail validation if durationUnits is not a duration unit concept
 * @should pass validation if all fields are correct
 * @should not require all fields for a discontinuation order
 * @should fail if route is not a valid concept
 * @should fail if concept is null and drug is not specified
 * @should fail if concept is null and cannot infer it from drug
 * @should pass if concept is null and drug is set
 * @should not validate a custom dosing type against any other dosing type validation
 * @should apply validation for a custom dosing type
 * @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) {
    super.validate(obj, errors);
    DrugOrder order = (DrugOrder) obj;
    if (order == null) {
        errors.reject("error.general");
    } else {
        // for the following elements Order.hbm.xml says: not-null="true"
        ValidationUtils.rejectIfEmpty(errors, "asNeeded", "error.null");
        if (order.getAction() != Order.Action.DISCONTINUE) {
            ValidationUtils.rejectIfEmpty(errors, "dosingType", "error.null");
        }
        if (order.getDrug() == null || order.getDrug().getConcept() == null) {
            ValidationUtils.rejectIfEmpty(errors, "concept", "error.null");
        }
        if (order.getConcept() != null && order.getDrug() != null && order.getDrug().getConcept() != null && !order.getDrug().getConcept().equals(order.getConcept())) {
            errors.rejectValue("drug", "error.general");
            errors.rejectValue("concept", "error.concept");
        }
        if (order.getAction() != Order.Action.DISCONTINUE && order.getDosingType() != null) {
            DosingInstructions dosingInstructions = order.getDosingInstructionsInstance();
            dosingInstructions.validate(order, errors);
        }
        validateFieldsForOutpatientCareSettingType(order, errors);
        validatePairedFields(order, errors);
        validateUnitsAreAmongAllowedConcepts(errors, order);
        validateForRequireDrug(errors, order);
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "asNeededCondition", "brandName");
    }
}
Also used : DrugOrder(org.openmrs.DrugOrder) DosingInstructions(org.openmrs.DosingInstructions)

Aggregations

DosingInstructions (org.openmrs.DosingInstructions)1 DrugOrder (org.openmrs.DrugOrder)1