Program rules basics

When creating a program (event or tracker) it is often useful to incorporate logic which allows various actions to occur depending on user input, including hiding fields or prompting the user with feedback. This tutorial will explain the basics of adding a program rule and hiding a field based on user selection.

In this example we will create a simple program rule which hides Pregnancy status if the selected Gender is Male.

In order to create a new program rule, navigate to Apps->Programs/Attributes->Programs

Select the program, followed by “View program rules” in order to go to the program rule management screen.

From the program rule management screen click on “Add new” to add in a new program rule.

Provide the rule with a name and description (for example, Hide pregnant IF gender = male). Now we can proceed to define the rules parameters.

  1. Click on “Add source field.” A pop-up will appear.
  2. Select the source type, program stage, data element, and provide a variable name. Click on “Add” when these have been defined.
  3. Select the source field, as this will move it over as a variable to the expression selection.
  4. Define your expression. In this case, we want to hide a field when gender = ‘Male’
  5. Select the action that occurs when gender = ‘Male’
  6. Add a message that describes the action. Can also be used when the action is prompting the user.
  7. Select the field in which to execute an action (in this case, hide field)
  8. Add the program rule when all is completed by clicking “Update”

For more on program rules, including creating advanced or multiple condition based rules, make sure to visit the DHIS2 documentation.

Back to tutorials