O3-5430: Validate obs datetime against patient DOB#5892
O3-5430: Validate obs datetime against patient DOB#5892BlessedAmrita wants to merge 1 commit intoopenmrs:masterfrom
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5892 +/- ##
============================================
+ Coverage 59.26% 59.28% +0.02%
- Complexity 9251 9258 +7
============================================
Files 686 686
Lines 37219 37223 +4
Branches 5445 5447 +2
============================================
+ Hits 22056 22066 +10
+ Misses 13201 13196 -5
+ Partials 1962 1961 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| errors.rejectValue("obsDatetime", "error.null"); | ||
| } | ||
|
|
||
| if (obs.getObsDatetime() != null && obs.getPerson() != null && obs.getPerson().getBirthdate() != null |
There was a problem hiding this comment.
Probably Wrong field being validated.
The ticket is specifically about the Expiration date and Next dose date fields in the Immunization App. Those values are stored in valueDatetime, not obsDatetime. obsDatetime is the timestamp of when the observation was recorded — that's a different concept entirely. Please change the validation to check valueDatetime against the patient's birthdate instead.
| * <strong>Should</strong> fail validation if field lengths are not correct | ||
| * <strong>Should</strong> not validate if obs is voided | ||
| * <strong>Should</strong> not validate a voided child obs | ||
| * <strong>Should</strong> fail for a null object |
There was a problem hiding this comment.
//
strong>Should</strong> fail validation if valueDatetime is before the patient's date of birth
strong>Should</strong> pass validation if valueDatetime is on or after the patient's date of birth
strong>Should</strong> pass validation if valueDatetime is set but person has no birthdate
//
| * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) | ||
| */ | ||
| @Test | ||
| void validate_shouldRejectObsDatetimeBeforePatientBirthdate() { |
There was a problem hiding this comment.
should be public.
| if (obs.getObsDatetime() != null && obs.getPerson() != null && obs.getPerson().getBirthdate() != null | ||
| && obs.getObsDatetime().before(obs.getPerson().getBirthdate())) { | ||
| errors.rejectValue("obsDatetime", "Obs.error.obsDatetimeBeforePatientBirthdate", | ||
| "Obs datetime cannot be before the patient's date of birth"); |
There was a problem hiding this comment.
remove hard coded message.



Description of what I changed
Added DOB lower-bound validation for
obsDatetimeinObsValidator.The
obsDatetimefield is validated against the patient's date of birth preventing, thus clinically impossible entries.Changes:
ObsValidator.java: Added birthdate lower-bound check forobsDatetimeusingobs.getPerson().getBirthdate()with null guardsObsValidatorTest.java: Added 5 test cases for DOB validation scenariosmessages.properties: AddedObs.error.obsDatetimeBeforePatientBirthdatekeyTest scenarios:
obsDatetimebefore patient birthdate → validation errorobsDatetimeequal to patient birthdate → no errorobsDatetimeafter patient birthdate → no errorobsDatetimeis null → no DOB errorPart of the Date Picker Improvements epic (O3-5424).
Issue I worked on
see https://issues.openmrs.org/browse/O3-5430
Checklist: I completed these to help reviewers :)
mvn clean packageright before creating this pull request andadded all formatting changes to my commit.