Skip to content

O3-5428: Validate program enrollment/completion dates against patient DOB#5886

Open
BlessedAmrita wants to merge 1 commit intoopenmrs:masterfrom
BlessedAmrita:O3-5428-program-dates-dob-validation
Open

O3-5428: Validate program enrollment/completion dates against patient DOB#5886
BlessedAmrita wants to merge 1 commit intoopenmrs:masterfrom
BlessedAmrita:O3-5428-program-dates-dob-validation

Conversation

@BlessedAmrita
Copy link

@BlessedAmrita BlessedAmrita commented Mar 4, 2026

Description of what I changed

Added DOB lower-bound validation for dateEnrolled and dateCompleted in PatientProgramValidator.

When either date falls before the patient's date of birth, the validator now rejects it with a field error. This prevents clinically impossible data entry: a patient cannot be enrolled in a program before they were born. Dates equal to the birthdate are allowed.

Changes:

  • PatientProgramValidator.java: Added birthdate lower-bound checks for both date fields after existing future-date checks, with null guards for patient and birthdate.
  • PatientProgramValidatorTest.java: Added 10 test cases (5 per date field) covering before/equal/after birthdate, null date, and null birthdate scenarios
  • messages.properties: Added error.patientProgram.enrolledDateCannotBeBeforeBirthdate and error.patientProgram.completionDateCannotBeBeforeBirthdate keys

Test scenarios (for each date field):

  • Date before patient birthdate → validation error
  • Date equal to patient birthdate → no error
  • Date after patient birthdate → no error
  • Date is null → no error
  • Patient birthdate is null → no error

Part of the Date Picker Improvements epic (O3-5424).

Issue I worked on

see https://issues.openmrs.org/browse/O3-5428

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.
  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)
  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.
  • All new and existing tests passed.
  • My pull request is based on the latest changes of the master branch.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026

@BlessedAmrita
Copy link
Author

@denniskigen @dkayiwa please review this

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.25%. Comparing base (dcf1695) to head (178c6ed).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...org/openmrs/validator/PatientProgramValidator.java 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5886      +/-   ##
============================================
- Coverage     59.26%   59.25%   -0.01%     
- Complexity     9251     9260       +9     
============================================
  Files           686      686              
  Lines         37219    37225       +6     
  Branches       5445     5448       +3     
============================================
+ Hits          22056    22057       +1     
- Misses        13201    13207       +6     
+ Partials       1962     1961       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants