Background
There are many factors that go into determining whether or not an order is valid, including many different context-specific details (what's being ordered, type of order, care setting, orderer) and often incorporating implementation-specific business rules.
Basic Validation
All orders
- Patient
- Encounter
- Care Setting
- Concept (what is being ordered)
- Instructions
- Orderer
- urgency
- startDate
- action
- orderType
Assumed defaults
- Order ID – assigned by the API
- Urgency – API assumes ROUTINE
- Action –API assumes NEW
- Start date – API assumes date created
- Creator – API assumes current user
- Date created – API assumes now
Drug orders
- Dosing type
- asNeeded
- Instructions corresponding to dosing type
- Simple:
dose
,dose units
,route
,frequency
, andas_needed
(defaults to false) - Free text:
orders.instructions
Other dosing types (i.e., not simple or free text):
drug_order.dosing_instructions
- Simple:
- For outpatient care setting: quantity, quantity units, and number of refills (not required for inpatient drug orders)
Other Validation Rules
- For discontinuation orders, concept and its previous order's concept must be the same
- The dateStopped of a previous order should be the same as the start date of the revised or discontinued order
- Cannot order retired orderables e.g retired drugs or concepts? In case of retrospective data entry dateStarted should come before dateRetired
- Unit concepts(quantity, duration and dose units) should be of units concept class(es)
- Frequency concepts should be of frequency concept class
order.startDate can't be before its encounter's encounterDatetime
the order being revised or the previous can't be a DC order
Patient can't be on the same order at the same time, for drug orders, exception is the patient can be on different formulations but same concept.
Class type for DC and drug order should match, same for revision
scheduled_date can only be specified with the correct urgency, currently the only supported urgency is ON_SCHEDULED_DATE but there could be others added
order.startDate can't be in the future
- order.orderType.javaClassAsClass should match order.class, subclasses are allowed
Not sure how all this will work with retrospective data entry of orders
Extensible Validation
Ultimately, implementations will need to be able to introduce their own business rules for order validation. Some examples of common business rules:
- Requirements may vary based on the care settings (e.g., outpatient drugs must specify quantity & refills, while inpatient drugs do not)
- Some specific drugs cannot be refilled
- Some radiology tests require that laterality be specified, while many others laterality does not apply
Validator Chaining
In order to accommodate implementation-specific business rules that may vary based on context, OpenMRS should implement some basic "out-of-the-box" business rules in a manner that can be adapted by implementations. A validator chain would invoke 1-to-N order validators, passing the current order along with the ordering context (Encounter, CareSetting, Orderer, User) and collect a list of validation errors that could be passed back to the user.
Other Validation Rules