How to automate patient tracking

Hi all,

Use case

When completing a certain number of events in a repeatable stage, I would like to display a message that says you have reached stage number X and block user input if he tries to schedule more events for a tracked entity.

As for a repeatable stage, a user can enter an unknown number of events. How to have a label that displays a number (1,2, etc) for each event the user completes and block user input after a certain number is reached.

Please any help is welcome.

Hi there @fernando

I understand you would like to use a program rule to display a warning or block user input if a maximum number of events has been reached.

I was not able to find precisely what you are looking for: calculate within a program rule the total number of events for a particular program stage in the enrollment.

However, it is possible to calculate the total number of values for a particular data element across the enrollment, and show that as a warning. I would recommend you calculate this for one of the required data elements in your program stage (or any auto-assigned value within the stage).

Example: on Play 2.36.3, the RMNCH program. A warning box is under the first data element in the stage showing the total number of values for “diastolic blood pressure” in the enrollment.

Set the program rule condition to “true” and the program rule expression uses d2:count function

You could use similar method to show an error if d2:count({required_data_element_id}) exceeds maximum allowed stages.

Note you could also substitute the d2:count(<required_data_element_id>) for V{event_count}. This would calculate the total number of events in the enrollment across all stages – even those without a value for the “required” data element.


Hi @brian,

What I want below is to calculate a total number of events for a particular program stage and block or hide it if maximum allowed stages is exceeded.

So, Could you, please, explain to me how the PR should be for the following text ? I did no understand this part well

Also, I did not understand very well the use of V{event_count} as you described here. The bolded part in particular


Hi @fernando - sorry my previous reply was a bit brief!

In the repeatable stage “Antenatal care visit” there is a data element called “diagnostic blood pressure” (DBP). Let us assume this DBP data element is required, and is only shown in antenatal care visit, and not in the other stages.

While we cannot calculate the total number of events for the antenatal care program stage in program rules directly, we can calculate the total number of values for this required data element using the d2:count() function,

This program rule blocks all Antenatal care stage events after there are DBP values in four separate Antenatal care stages (note the “program stage” dropdown menu).

Condition: d2:count(#{diastolicbloodpressure}) > 3
Action: Hide Program Stage - Antenatal Care Visit

Similarly, a program rule action to “show error” would inform the user when they have reached the maximum number of antenatal care stages, and cannot add any more.

Using V{event_count} would calculate the total number of events in the enrollment. Not just antenatal care events, or events with a value for DBP. This is not relevant for your use case, but may be useful for future readers :slight_smile:


Hi @brian,

Thank you for your clear explanation.


Thanks @brian! (: And @fernando, it would be great if you mark it as solved if it! :+1: Thanks!