How to Count Events Associated with a Program Stage and Use Program Rules for Conditional Actions?

I need to count the number of events associated with a specific program stage and use program rules to trigger actions based on that count. Specifically, I want to:

  • Count events related to a program stage.
  • Trigger actions (e.g., show/hide fields or set values) based on the event count or status.

Is it possible to achieve this with program rules? Any best practices or examples would be appreciated!

While i am looking to avoid using V{event_count} because it counts all events associated with an enrollment

Dear @hio.amakomaya ,

I am not sure whether this is the best solution to achieve it, but we use a data element “Event number” to store the number of events from a specific stage.
We use 2 program rule variable:
“Event Number previous” (which retries the value of the data Element “Event number” from last event in the given stage.
“Event number” which is the value of current DE '“Event number”

We use 2 program rules, to assign the value “1” for the first event (Condition = !d2:hasValue(#{Event Number previous}) && !d2:hasValue(#Event Number)", and another Program rule for the following events, where we assign the value ("Event Number preivous +1) to the data element “Event Number” (condition = d2:hasValue(Event number previous}) && !d2:hasValue(Event number) && (#{Event Number - Event Number previous} <2)

Please see this post where we discussed with DHIS2 team about this kind of counter:
Tracker Android Capture program rules - Visit incrementation - Support - Assistance technique - DHIS2 Community

We can then have program rules conditions based on the variable “Event number” to hide field or assign values.

Hope this helps

1 Like