I’m working on a chronic-care tracker program and ran into something others might know a way to solve.
Our enrollment program indicators include things like “lost to follow-up” (no visit in 12 months). The trouble is that a patient who has died also has no visits, so they end up counted as lost to follow-up.
We close the enrollment when a patient dies, so my first idea was to add V{enrollment_status} == 'ACTIVE' to the filter. That doesn’t work well, though, because it uses the current status. Once a patient’s enrollment is closed, they disappear from all the old reports too, even for periods when they were alive and in care. For example, if enrollment is completed in April 2026, it will be excluded from January 2026 reports too which is obviously wrong.
Currently, what partially worked for me is this filter:
In plain words: count the patient if they’re still active, or if their enrollment was closed after the period ended. Old reports stay the same. Surprisingly, the docs (Programs - DHIS2 Documentation) say V{completed_date} is the event completion date. But in enrollment-type program indicators it’s actually the enrollment completion date (I’ve reported it here: Jira).
But this workaround is not ideal because of two issues:
Enrollment completion date in Capture app is forced as the current date, so if for example the patient passed away 2 months ago, we can’t complete the enrollment with completion date of 2 months ago.
This workaround doesn’t work for cancelled enrollments and they are included in the program indicator.
So, in brief, how can we exclude completed/cancelled enrollments from reporting periods only after the completion/cancellation date and not from reporting periods before the completion/cancellation.
Thank you for taking the time to report this. I see the docs specifically mention that the V{completed_date} returns “completion date of event which triggered this rule” so the PR needs to be tied to a program stage in order to return the completion date of the event.
Since the PI is an enrollment type program indicator, the V{completed_date} will return the completion date of the enrollment.
I have a workaround suggestion that I would like to propose. How about utilizing the d2:lastEventDate found in PR and assign the date of the last event to a DE (Last Event Date)? This means you will be able to use the DE that contains the date of the last event and avoid the V{completion_date}.
What do you think of this workaround? So that instead of the following PI filter:
You will compate DE{Last EVENT Date} > > V{analytics_period_end};
and since the last event date is exactly the last event date, it will continue to appear in the reporting periods before the completion/cancellation regardless.
Please let me know if this works or if I might have missed anything. Thanks!
Regarding the docs, I was referring to definition of completed_date in “Variables to use in a program indicator expression or filter” table and not the “Standard variables to use in program rule expressions” table: Programs - DHIS2 Documentation
Regarding using d2:lastEventDate, we do not create an event for completion or cancellation of enrollments. Our users simply use below menu in the Capture app to complete or cancel an enrollment:
Sorry for the confusion in my last reply. I was actually wondering if we could make use of Program Rules first to make a record of the last event date? Actually, I want to understand are you looking for the ‘last event date’ or the enrollment ‘completion date’? I assumed that having a ‘last event date’ data element might help but I think I might not have understood the entire scenario properly.
A TEI is enrolled in the program
The visits continue until (new events each time):
A) TEI stops visiting (which after 12 months of no visits, is marked as ‘lost to follow-up’)? [maybe here was can create the PR!]
B) TEI dies (which then at the clinic they simply ‘complete the enrollment’?)
So what I don’t understand is if the workflow for both ‘lost to follow-up’ vs ‘died/transferred’ is the same, how do you differentiate exactly?
Wouldn’t it make sense to add a Tracked Entity Attribute (TEA) ‘died’ so that it’s easier to exclude the TEIs that die? In other words, when looking at the form of a specific TEI (regardless of the PIs), how do you differentiate if the TEIs died or is lost to follow-up?