Provide the number of previous event an Entity have been take part of in a Tracker Form

Hello :wave:

I am trying to finish to set up a Tracker program that have as entity Person and I wish to create a program rule that will assign to a Data Element the number of previous events this Person have taken part to ie : “How many time this Person already came to a visit?”.

I am not sure it could be calculated without being a program indicator and inserted as read-only field in the form that user should fill at each event (not the enrolment). Especially if the field should be seen in the Capture App. As I am not sure how to implement it, I can’t validate if this could also be supported by the Capture App.

Thanks in advance :pray:

1 Like

Hi @ekhalil

Welcome to the community! :tada:

Yes, that’s called event count and you can use a program rule to assign the value to a data element.

Please create the program rule, select the program, and then select the ‘trigger for program stage’ to be the program stage you want to count the number of events in.

Then in the program condition, you could make the expression:

V{program_stage_name} == 'test2022stageA'

And finally the action is ‘assign value’ select the data element and the value choose:

V{event_count} - 1

Note, I added minus 1 because it counts the first event so if you want to count only previous events and not the first event then minus 1. Additionally, because we minus 1, it shows 0 in the first event, so it makes since to create a program rule to hide the field ‘previous visits’ if the value is equal to 0.

Hope this helps! :+1:

Thanks!

Hey @Gassim, thanks for the answer that’s exactly what I was looking for and found why I had some trouble to make it work. The event, in the case of my configuration, should be on different date or the counter will not work and not update itself. But instead of using event_count as the base number to add too, I am use the value from a previous event in a Programe rule variable to which I add one in a program rule. Maybe could also be the reason.

Hi @ekhalil

Thanks! I want to understand a bit more, so the “event_count” didn’t work when the event is in the same date so the workaround was using a program variable?

Thanks!

So not sure how I was doing it (and if there were an issue about the set up) but yes, event_count was not being upgrade if the event were at the same date. The workaround was to set a program variable to zero when event_count = 0 and when > 1 a program rule increasing the program variable by one. One of the potential issue was maybe conflicting program rules in my own configuration. I will try to reproduce this later on the play.dhis to check later.

2 Likes

Thanks @ekhalil! I have marked your instructions as a workaround for others who might face the same issue.

1 Like