I guess I’m confused. Then why can’t RadiologyOrderValidator
set the encounter property so it’s not null when OrderValidator
does its validation?
Are validators not supposed to have side effects (i.e., change the object being validated)?
I guess I’m confused. Then why can’t RadiologyOrderValidator
set the encounter property so it’s not null when OrderValidator
does its validation?
Are validators not supposed to have side effects (i.e., change the object being validated)?
I’m a little confused too, if anyone wishes to do any custom validation before the core validator or set any fields like encounter that is straight forward invoke you validator manually before calling the API’s save method from your controller or servlet etc. Otherwise, currently the API provides no way to prioritize the order in which validators should be invoked.
OrderValidator has no order in the annotation but other validators do, for instance:
@Handler(supports = { Visit.class }, order = 50)
public class VisitValidator extends BaseCustomizableValidator implements Validator {
But HandlerUtil.getHandlersForType does not sort the validators by order.
Validation should be done the API; in this case, using a custom validator along with the built-in validation. Clients of the API should not have to manage special validation steps when working with RadiologyOrders
; rather, clients should be able to treat RadiologyOrder
s like any other order and trust that the API will perform the proper business logic (including invoking any the custom validation associated with the order).
I don’t think we need tightly controlled sequencing, since >2 validators (more than core + a module-provided validator) for any given class would be an edge case. We just need to be able to guarantee that the core validation is performed last.
First off using a validator to mutate the object you are validating would be bad style. (E.g. I would certainly not expect that to be happening if I were reasoning about the behavior of the system.) @teleivo is not doing this, I just wanted to state it for the record.
I would think about it like this: