List of usage examples for org.springframework.validation ValidationUtils rejectIfEmpty
public static void rejectIfEmpty(Errors errors, String field, String errorCode)
From source file:org.openmrs.module.radiology.validator.RadiologyDiscontinuedOrderValidator.java
public void validate(Object obj, Errors errors) { final Order order = (Order) obj; if (order == null) { errors.reject("error.general"); } else {// ww w . j av a 2s.c o m ValidationUtils.rejectIfEmpty(errors, "orderer", "error.null"); ValidationUtils.rejectIfEmpty(errors, "orderReasonNonCoded", "error.null"); } }
From source file:org.openmrs.module.radiology.validator.RadiologyOrderValidator.java
/** * Checks the form object for any inconsistencies/errors * //from w ww . j av a2s . c o m * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) * @should fail validation if radiologyOrder is null * @should fail validation if voided is null * @should fail validation if concept is null * @should fail validation if patient is null * @should fail validation if orderer is null * @should fail validation if urgency is null * @should fail validation if action is null * @should fail validation if dateActivated after dateStopped * @should fail validation if dateActivated after autoExpireDate * @should fail validation if scheduledDate is set and urgency is not set as ON_SCHEDULED_DATE * @should fail validation if scheduledDate is null when urgency is ON_SCHEDULED_DATE * @should pass validation if the class of the order is a subclass of orderType.javaClass * @should pass validation if all fields are correct * @should not allow a future dateActivated */ public void validate(Object obj, Errors errors) { final RadiologyOrder radiologyOrder = (RadiologyOrder) obj; if (radiologyOrder == null) { errors.reject("error.general"); } else { // for the following elements Order.hbm.xml says: not-null="true" ValidationUtils.rejectIfEmpty(errors, "voided", "error.null"); ValidationUtils.rejectIfEmpty(errors, "concept", "Concept.noConceptSelected"); ValidationUtils.rejectIfEmpty(errors, "patient", "error.null"); ValidationUtils.rejectIfEmpty(errors, "orderer", "error.null"); ValidationUtils.rejectIfEmpty(errors, "urgency", "error.null"); ValidationUtils.rejectIfEmpty(errors, "action", "error.null"); // Order.encounter and // Order.orderType // have not null constraint as well, but are set in RadiologyService.saveRadiologyOrder validateDateActivated(radiologyOrder, errors); validateScheduledDate(radiologyOrder, errors); } }
From source file:org.openmrs.SimpleDosingInstructions.java
/** * @see DosingInstructions#validate(DrugOrder, org.springframework.validation.Errors) * @param order/*from w w w .j a va2 s.c om*/ * @param errors * @should reject a duration unit with a mapping of an invalid type */ @Override public void validate(DrugOrder order, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "dose", "DrugOrder.error.doseIsNullForDosingTypeSimple"); ValidationUtils.rejectIfEmpty(errors, "doseUnits", "DrugOrder.error.doseUnitsIsNullForDosingTypeSimple"); ValidationUtils.rejectIfEmpty(errors, "route", "DrugOrder.error.routeIsNullForDosingTypeSimple"); ValidationUtils.rejectIfEmpty(errors, "frequency", "DrugOrder.error.frequencyIsNullForDosingTypeSimple"); if (order.getAutoExpireDate() == null && order.getDurationUnits() != null && Duration.getCode(order.getDurationUnits()) == null) { errors.rejectValue("durationUnits", "DrugOrder.error.durationUnitsNotMappedToSnomedCtDurationCode"); } }
From source file:org.openmrs.validator.ConceptDrugValidator.java
/** * Checks that a given <code>Drug</code> object is valid. * * @param obj the Object to validate//from w w w. j a va 2s.com * @param errors holds the validation errors * @throws IllegalArgumentException Runtime Exception if the supplied argument is * null or not of type <code>Drug</code> * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if a concept is not specified */ public void validate(Object obj, Errors errors) throws IllegalArgumentException { if (obj == null || !(obj instanceof Drug)) { throw new IllegalArgumentException( "The parameter obj should not be null and must be of type" + Drug.class); } log.debug("request to validate drug having concept: " + ((Drug) obj).getConcept()); ValidationUtils.rejectIfEmpty(errors, "concept", "ConceptDrug.error.conceptRequired"); }
From source file:org.openmrs.validator.DrugOrderValidator.java
/** * Checks the form object for any inconsistencies/errors * /* w w w .ja va 2 s . c om*/ * @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 */ 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); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "asNeededCondition", "brandName"); } }
From source file:org.openmrs.validator.DrugOrderValidator.java
private void validateForRequireDrug(Errors errors) { //Reject if global property is set to specify a formulation for drug order boolean requireDrug = Context.getAdministrationService() .getGlobalPropertyValue(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, false); if (requireDrug) { ValidationUtils.rejectIfEmpty(errors, "drug", "DrugOrder.error.drugIsRequired"); }/*ww w .ja v a 2s . c o m*/ }
From source file:org.openmrs.validator.DrugOrderValidator.java
private void validateFieldsForOutpatientCareSettingType(DrugOrder order, Errors errors) { if (order.getAction() != Order.Action.DISCONTINUE && order.getCareSetting() != null && order.getCareSetting().getCareSettingType().equals(CareSetting.CareSettingType.OUTPATIENT)) { ValidationUtils.rejectIfEmpty(errors, "quantity", "DrugOrder.error.quantityIsNullForOutPatient"); ValidationUtils.rejectIfEmpty(errors, "numRefills", "DrugOrder.error.numRefillsIsNullForOutPatient"); }//from w w w.j av a 2 s . c om }
From source file:org.openmrs.validator.DrugOrderValidator.java
private void validatePairedFields(DrugOrder order, Errors errors) { if (order.getDose() != null) { ValidationUtils.rejectIfEmpty(errors, "doseUnits", "DrugOrder.error.doseUnitsRequiredWithDose"); }//from ww w .ja v a 2s . c o m if (order.getQuantity() != null) { ValidationUtils.rejectIfEmpty(errors, "quantityUnits", "DrugOrder.error.quantityUnitsRequiredWithQuantity"); } if (order.getDuration() != null) { ValidationUtils.rejectIfEmpty(errors, "durationUnits", "DrugOrder.error.durationUnitsRequiredWithDuration"); } }
From source file:org.openmrs.validator.EncounterRoleValidator.java
/** * Validates the given EncounterRole. Currently checks if name * of the encounter role is given or not. * @param obj The encounter role to validate. * @param errors Errors//from w ww . ja v a2s . co m * @see org.springframework.validation.Validator#validate(Object, * org.springframework.validation.Errors) * @should fail if the name of the encounter role is not set */ public void validate(Object obj, Errors errors) throws APIException { if (log.isDebugEnabled()) log.debug(this.getClass().getName() + ".validate..."); if (obj == null || !(obj instanceof EncounterRole)) throw new IllegalArgumentException( "The parameter obj should not be null and must be of type " + EncounterRole.class); EncounterRole encounterRole = (EncounterRole) obj; if (encounterRole != null) { ValidationUtils.rejectIfEmpty(errors, "name", "error.null"); } }
From source file:org.openmrs.validator.OrderFrequencyValidator.java
/** * Checks the order frequency object for any inconsistencies/errors * /*from w w w.j a va2s . c om*/ * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if orderFrequency is null * @should fail if concept is null * @should fail if the concept is not of class frequency * @should fail if concept is used by another frequency * @should pass for a valid new order frequency * @should pass for a valid existing order frequency * @should be invoked when an order frequency 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) { OrderFrequency orderFrequency = (OrderFrequency) obj; if (orderFrequency == null) { errors.reject("error.general"); } else { ValidationUtils.rejectIfEmpty(errors, "concept", "Concept.noConceptSelected"); Concept concept = orderFrequency.getConcept(); if (concept != null) { if (!ConceptClass.FREQUENCY_UUID.equals(concept.getConceptClass().getUuid())) { errors.rejectValue("concept", "OrderFrequency.concept.shouldBeClassFrequency"); } OrderFrequency of = Context.getOrderService().getOrderFrequencyByConcept(concept); if (of != null && !of.equals(orderFrequency)) { errors.rejectValue("concept", "OrderFrequency.concept.shouldNotBeShared"); } } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "retireReason"); } }