Admin tool of the week: Program Rule Validator Tool

:information_source: Admin tool of the week: this post is part of a weekly series featuring small, open-source maintenance tools from the HISP Centre for DHIS2 system administrators. Read about the series.

The problem

Tracker and event programs collect program rules over the years. Rules are added and removed, data elements are changed, and a program can be configured by several people over time. Two kinds of problems build up:

  • Rules that DHIS2 cannot evaluate. A typo in a condition, such as !== instead of !=, or a reference to a variable that no longer exists. The rule then does nothing, and nobody notices until a field that should be hidden is shown, or a value that should be assigned is empty.
  • Program rule variables that no rule uses. They are left behind when rules are deleted or rewritten. They make the program harder to maintain, and every Android device still downloads them.

The Maintenance and Metadata Management apps check one expression at a time, when you edit it. There is no list of all the broken rules on an instance.

What the tool does

Program Rule Validator Tool checks all program rules of the programs you choose, and shows the results in three tabs:

  • Invalid conditions. Rules whose condition DHIS2 cannot evaluate, with the message from the DHIS2 expression parser, for example expected name at line:1 character:15.
  • Invalid actions. Rules with an action expression, such as the value in an Assign value action, that DHIS2 cannot evaluate.
  • Unused program rule variables. Variables that no rule in their program refers to. You can filter by program, tick the ones you want to remove, and delete them in one go. Before deleting, you can download the variables as a metadata file.

Each row has an Edit link that opens the rule or variable in the Metadata Management or Maintenance app.

Validate all programs, look at the invalid conditions and actions, then filter the unused variables to one program and delete three of them

Try it on the demo instance

You can try the tool without installing anything: open implement.im.dhis2.org/tools/apps/tool-program-rule-validator and log in as tools / District1#. The demo is a copy of the Sierra Leone database, and the problems it finds are real ones from that database. Click Validate all to see them.

The demo user can delete unused variables. Please try the delete on one or two at most, so other visitors still have something to find.

Use with care

  • A delete cannot be undone in the tool. Click Download backup in the confirmation first. To restore the variables, import that file in the Import/Export app.
  • A rule that builds a variable name while it runs, for example with d2:concatenate, is not detected, so its variable is listed as unused. Check the list before you delete.
  • The validation messages come from DHIS2 and are sometimes short, for example 1 error(s), 0 warning(s).
  • Metadata Management can show an invalid action as valid. Its expression builder shows Valid expression for every action expression, including ones that this tool lists under Invalid actions. This is a bug in Metadata Management (DHIS2-22589). Condition expressions are checked correctly in both.
  • The tool sends one request to DHIS2 for each expression. On an instance with thousands of rules, run it at a quiet time.
  • Try it on a copy of your database before you use it on a production server.

Get it

  • Supported DHIS2 versions: 2.41 and later (tested on 2.41, 2.42 and 2.43).
  • Download: the latest .zip from the releases page on GitHub, then install it in the App Management app (Upload app). You can also install it from the DHIS2 Admin Toolbox app.
  • Documentation and source: github.com/dhis2-utils/tool-program-rule-validator (see the user guide)
  • Authorities: access to the app (“toolprogramrulevalidator app”) to check the rules. The tool checks only the programs the user can see. Deleting variables also needs Manage program rule (F_PROGRAM_RULE_MANAGEMENT).
  • Already using an earlier version? Upgrade to 1.1.0: earlier versions could list some variables as unused when a rule used them inside a function such as d2:count. Version 1.1.0 is installed as separate app if you have used a previous version, so uninstall the old “Program Rule Validator Tool” app after installing 1.1.0 if upgrading.

Questions, bugs or ideas? Reply below.

Click here to receive notifications for #admin-tool-weekly topics: