Any possibility to limit a repeatable program stage?

Hi everyone,

I have two repeatable stages since I will capture the same type of data for all support visit events and loss to follow up events. But I have difficulty for applying logic for the following scenarios:

Scenario 1 : For support visit repeatable stage, after it has been filled seven times/ 7 visits, the user must be prompted to close the whole enrollment. In other words, the number of visits must be limited to seven.

Scenario 2 : For loss to follow up repeatable stage, the user must be prompted to close the whole enrollment if the patient was not found or the patient has died or if the patient is not inside his/her range area or if the number of visits is 3. (See attached image)

Your prompt response will be highly appreciated and I would welcome any advice you have on this as well.


Hi @ferdinandmussavene ,

It is possible to achieve your goals by using program Rule/program rule variables and program Rule actions WARNING and ERROR on Complete. It is a bit complex of course.

For scenario 1, you can assign values based on current and previous event to a calculated PRV.
After reaching the “limit” value, a program rule can create a warning message: Close Enrollment and an error on completion that will prevent completing the 8th event. (Alternative would be to hide Program stage after the limit is reached).

For Scenario 2:A program rule can check for the values in data elements and also create a Warning that will prompt the user to close enrollment and error on completion of the event.

Good luck,


Hi @YuryR,

If possible, I am wondering if you could help me build the program rules. For example configuring the program rule variables and actions for both scenarios. I am new to program rules.

Thanks again

Hi @ferdinandmussavene ! Sorry for keeping you on hold.

I recommend you to try with a fairly simple solution and see whether it works for you:

Scenario 1:
Create a program rule that will trigger only for the applicable Program Stage (If you only have one in the program, it does not matter).

  1. Create an expression that will look like this:
    V{program_stage_id} == ‘program Stage uid’ && V{event_count} >= 7
    This will make sure that you only count events in that particular program stage.

  2. In the program rule actions, select:
    a) Hide Program Stage (Select applicable program stage)
    b) Show Error or Error on Complete (Fill in the field for static text: eg. Number of visits is limited to 7).

Expected behaviour:
When the user creates event Nr. 8, they will be able to fill in data, but when they click complete, they will get an error with a message. It will not be possible to create new events anymore.

You can also add other program rule actions like:
Hide sections (if your data entry form uses sections) or
Hide data elements.
This way you will ensure that the form nr 8 will show without any fields and the user will not have a chance to fill in the form before receiving an error.

Scenario 2:

Similar program rule with several “OR” options.

V{program_stage_id} == ‘program Stage uid’ && V{event_count} = 3 ||

d2:hasValue(#{program rule variable for the data element in current event: FOUND_PATIENT}) && == #{program rule variable for the data element in current event: FOUND_PATIENT} == 0 ||

d2:hasValue(#{program rule variable for the data element in current event: REASONS}) && == #{program rule variable for the data element in current event: REASONS} == ‘code for option: DEATH’ ||

d2:hasValue(#{program rule variable for the data element in current event: PATIENT WITHIN AREA}) && == #{program rule variable for the data element in current event: PATIENT WITHIN AREA} == 0

Then as a Program Rule Action, you could have Show Warning.
You can also split this rule into 3 different rules with different notifications.

Hope that this can be a starting point for you.

Feel free to provide feedback and questions.

Best regards,


Hi @YuryR,

I tried the program rule for scenario 1 and it works: a message is displayed that the number of visits should be limited to 7. When I added other program actions to hide data elements and tested again, the program rule no longer displays the error on complete message and registers the 8th visit.

For scenario 2, The program rule does not work. Do we have to include some parenthesis? Below is the rule expression:



Hi. Try the following structure:
(Condition 1.1 && Condition 1.2) || (Condition 2.1 && Condition 2.1) || ( Condition 3.1 && Condition 3.1).

Brackets () might help.

Alternatively, try splitting program rules

Hi @YuryR,

I just split one of the program rules as seen below and it works, but what I want is to tag the enrollment as closed and block future data entry if patient has died.

What happens now is that the program rule action is triggered but the user can still enter more data for the same event - as it is repeatable - even if the patient has died.
In the image below, when I closed the triggered PR action and clicked on the + button I was able to register a new event though death option was selected in the previous event.

NB: The user should no longer be allowed to add more events in case a patient has died.

NB: The hide program stage rule does not hide the stage I selected. It only displays the message that the number of visits is limited to 7 (Hiding the program stage would a nice solution, too. but it is no working)

More hints, suggestions are welcome

Thanks again Yury