Recently I came to a situation where I’m creating a Program Rule to check the if the patient date_of_birth happens before the registration date on Tracker.
The Program Rule condition is something like these:
1- with V{enrollment_date}
d2:daysBetween(A{date_of_birth}, V{enrollment_date}) < 0
And in the action is Show warning with the value of V{enrollment_date} on a tracked entity attribute, and the result is as follows
2- With V{event_date}
d2:daysBetween(A{date_of_birth}, V{event_date}) < 0
And in the action is Show warning with the value of V{event_date} on a tracked entity attribute, and the result is as follows
This happens during the enrollment stage of the Tracker Program
Is there a reason why the Built In Variables are returning undefined values?
Is there any other alternative to check if the patient date of birth happens before the registration date in Tracker Program?
This was verified using DHIS2 versions 2.37.9, 2.39.5, 2.39.6
This is probably because for the event_date, it has not been saved for it to be returned so it’s returning ‘undefined’, and if this is also in the registration form for the enrollment itself then it’s the same case for enrollment_date
I tried too with V{curren_date}, and still I get the same issue, which is ‘undefind’
It seems to be an error with the built in variables dealing with dates.
Since the issue persists with the built-in date variables, here are a couple of additional suggestions you can try:
Check Date Formats: Ensure that the dates are formatted correctly according to DHIS2’s expected format (usually ‘YYYY-MM-DD’). Sometimes, incorrect date formats can cause issues with how dates are interpreted in the program rules.
Use a Custom Program Variable: If the built-in variables are not working, you might consider creating a custom program variable to manually capture the enrollment date or event date. You can then use this custom variable to perform the date comparison in your program rule.
These steps might help bypass the issue with the built-in variables. Let me know if this works for you.