ODK calculations: empty integer evaluate to 0

Migrating from ODK based platforms, I have realized that some calculations are differently handled in CHT.

For instance an empty integer is evaluated to zero.
If I have an integer, say height, and have a calculation later on that checks for instance if a child is smaller than a threshold:
${height}<90

This is evaluated to TRUE.

In ODK it would be FALSE because ${height} is empty. See also here in ODK docs

CHT equals an empty integer with 0

Could you point me to a reference, documentation where those differences are mentioned so I can adapt my XLS forms?

Many thanks.

@raf thank you for bringing this up!

This behavior seems to be a bug in the CHT. I have logged a new issue: Empty integer values in Enketo forms evaluate to 0 · Issue #7222 · medic/cht-core · GitHub where I note that it is possible this is fixed by our pending enketo upgrade.

Generally speaking, I think the goal is for CHT to properly implement the ODK spec with no surprising differences to the base functionality. The CHT adds some additional functionality that can be leveraged by forms (documented here), but I do not know of any behavior differences from the basic ODK functionality that are intentionally included in the CHT.

Dear @jkuester,
Thank you for helping me out. While waiting for this to be fixed, I have applied this workaround. It might be useful to someone else.
as ${height} < 90 evaluates to true if height is empty, one must write

${height} < 90 and ${height}!=''

to get the same behaviour as in ODK.

1 Like

Dear @jkuester,
as you told me that CHT is supposed to implement ODK specs 1:1 (and then building on top of it), let me mention another discrepancy that I have detected:
CHT fails to execute calculations that start with a negative number.
For instance, if we have a variable var1and we have a calculate field with the following formula:
-5 * ${var1} + 20, then it will not be executed, and the form does not load.

One must write 20 - 5 * ${var1} for it to work.

Best regards.

1 Like

@raf this seems related to this issue which is fixed in openrosa-xpath-evaluator v2. CHT is currently on the 1.x release but should be upgraded once this lands.

2 Likes

Hi @derick,
Thank you very much for this info, that sounds great!