In 2024, I’ve been pushing the boundaries of DHIS2 to develop more complex and extensive programs. Recently, I encountered a challenge while configuring an Event Program that required a program rule to hide a specific data element based on a calculated condition.
The logic was simple:
If Element A - Element B = (±)5, then Data Element C should be filled.
However, DHIS2 doesn’t have a built-in function for recognizing the plus-minus (±) sign, making this a tricky problem to solve. Since any subtraction that results in a negative value can be reversed to become positive (e.g., 15 - 24 = -9 but 24 - 15 = +9), I needed to structure the rule logically to achieve the intended outcome.
The Solution:
Instead of relying on a ± function, I designed the following program rule formula:
(#Element A - #Element B) > 5 && (#Element B - #Element A) > 5
This ensures that if DHIS2 calculates a negative value in the first expression, it will rerun the calculation in reverse, producing a positive integer, thereby maintaining the intended logic.
This approach worked, but I’m sure there are other ways to achieve the same result. If you have experience with similar DHIS2 program rules, I’d love to hear your insights! Let’s innovate together.