O3-5425: Validate order dates against patient DOB#5887
O3-5425: Validate order dates against patient DOB#5887BlessedAmrita wants to merge 1 commit intoopenmrs:masterfrom
Conversation
|
|
@BlessedAmrita, apologies for the earlier incorrect feedback. After reviewing the maintainer's guidance more carefully, your approach of validating dates against the patient's date of birth is actually the right direction. The maintainer confirmed that the patient's DOB is the natural lower bound for these dates, which inherently catches single-digit year entries like |
| errors.rejectValue("dateActivated", "Order.error.encounterDatetimeAfterDateActivated"); | ||
| } | ||
| if (order.getPatient() != null && order.getPatient().getBirthdate() != null | ||
| && dateActivated.before(order.getPatient().getBirthdate())) { |
There was a problem hiding this comment.
One edge case to consider —> in OpenMRS, a patient's birthdate can be estimated (birthdateEstimated = true), When this is the case, the stored birthdate is not an exact date —> it is a synthetic value calculated from the patient's approximate age.
Would it could cause false rejections?
Reference - visitValidator
| } | ||
| Date scheduledDate = order.getScheduledDate(); | ||
| if (scheduledDate != null && order.getPatient() != null && order.getPatient().getBirthdate() != null | ||
| && scheduledDate.before(order.getPatient().getBirthdate())) { |
| if (scheduledDate != null && order.getPatient() != null && order.getPatient().getBirthdate() != null | ||
| && scheduledDate.before(order.getPatient().getBirthdate())) { | ||
| errors.rejectValue("scheduledDate", "Order.error.scheduledDateBeforePatientBirthdate", | ||
| "Scheduled date cannot be before patient's birthdate"); |
There was a problem hiding this comment.
You can remove the hard coded message.



Description of what I changed
Added DOB lower-bound validation for
dateActivatedandscheduledDateinOrderValidator.Since these date fields live on the base
Orderclass, placing the validation inOrderValidatormeans it automatically applies to all order types:TestOrder,DrugOrder,ReferralOrder, etc. When either date falls before the patient's date of birth, the validator rejects it with a field error. Dates equal to the birthdate are allowed.Changes:
OrderValidator.java: Added birthdate lower-bound checks invalidateDateActivated()andvalidateScheduledDate()methods, with null guards for patient and birthdateOrderValidatorTest.java: Added 10 test cases (5 per date field) covering before/equal/after birthdate, null date, and null birthdate scenariosmessages.properties: AddedOrder.error.dateActivatedBeforePatientBirthdateandOrder.error.scheduledDateBeforePatientBirthdatekeysTest scenarios (for each date field):
Part of the Date Picker Improvements epic (O3-5424).
Issue I worked on
see https://issues.openmrs.org/browse/O3-5425
Checklist: I completed these to help reviewers :)
mvn clean packageright before creating this pull request and added all formatting changes to my commit.