Hi All,
I’m having a problem using d2:round in the calculation of an assign value action in a Program Rule. I’m just trying to calculate BMI by rounding the outcome of Weight over Height squared. See error below.
I can get around this by first assigning Weight/Height squared to a PRV, then having a second Program Rule assign d2:round(PRV) to the BMI data element, but it seems weird that d2:round cannot handle this in one program rule as I had originally defined it.
The problem was that it was not possible to have nested expressions passed as an argument to the d2:functions. In short, the parenthesis inside the calculation makes the evaluation fail.
Until the bug fix is rolled out, a workaround can be to make the calculation #/(#*#) in a separate rule, and assign this to a calculated variable. If you create a new program rule variable called for example #{bmi}, you can assign the variable #{bmi} by the calculation above. Remember to set a rule of priority 1, so the helper variable #{bmi} gets assigned before your current rule.
With the current program rule variable #{bmi} set, you can change your current rule to d2:round(#{bmi}) - and this should work.