Assign a value to a data element by using Program Rule

Can we assign values to data elements based on certain conditions using program rules.
For Example:
Create a program rule in DHIS2 to assign a value of ‘Non-Detectable’ to a result interpretation data element when the lab value is less than 2.4 and ‘Detectable’ when lab value is greater then 2.4

Dear @Osama_Yaqoob,
indeed, it’s possible to have it!

To be able to achive it you need to create two differents program rules: one for the assignation of the value “Non-Detectable” and another one for the value “Detectable” and assign both of them to the Data Element for which you want to assign the value.

The step to follow are:

  1. Create a Program Rule variables of the DE that need to be evaluated (in you case the one providing the numeric value)
  2. Create a program rule and assign in the expression the condition for which you want the program rule to be triggered (for example to trigger the program rule to assign the value of “Non-detectable” the formula should be: “d2:hasValue( ‘code of the program rule variable’ ) && #{code of the program rule variable}<=2.4
    It’s important to have the function “d2:hasValue” in order to trigger the program rule only in case there are values
  3. As program rule actions assign the action “Assign value”, the data element to assign and in the expression to evaluate and assign the text to appear (can be a value from another Data Element or a static trext

You can find more detailed information in the DHIS2 user guide