Logical operators night not be working

Hi All,

In a tracker program, I have one repeatable stage that is configured as follow:

Data element 1: Participant attendance that has an option set attached to it. The options in the option set are: (Session 1, Session 2, Session 3, Session 4, Session 5, Session 6, Session 7 and Session 8).

Data element 2: Attended, which is Yes/No DE

Data element 3: Received, which is also a Yes/No DE

I want to get the following result from the program rule:

If Participant attendance is Session 3 and Attended is No or If Participant attendance is Session 6 and Attended is No, then Show DE Received Cartao Quero.

This is the rule I created in the DHIS 2, but it is not working.

Thanks

Hey @dmbantu, thank you for your question! Could you please copy the rule as text and paste it to make it easier to check? Thank you! (:smiley:

Hi @Gassim.

Here is the rule:

!d2:hasValue( #{Participant attendance} ) ||(#{Participant attendance} != ‘Session 3’ &&#{Attended} == false) || (#{Participant attendance} != ‘Session 6’ && #{Attended} == false)

Thanks

1 Like

Thanks @dmbantu! It doesn’t seem like there’s any syntax issue and the logic makes perfect since. I will write a couple of suggestions by priority and hope that we will be able to find the solution. Please first use the browser cache cleaner app to clean all the cache, and I’d also use the data administration app > Maintenance to “clear application cache” and “reload apps”.

If it’s not then please test with the rule you created. Would you like to try and see if each one of these conditions work on it’s own. We want to understand the issue so what I mean is if you test first
!d2:hasValue( #{Participant attendance} ) and see if it hides the field
if it does then try the second one (#{Participant attendance} != ‘Session 3’ &&#{Attended} == false)
and then (#{Participant attendance} != ‘Session 6’ && #{Attended} == false)

If none of the conditions work separately then maybe use the program rule condition as it is, and then we’ll definitely have to check the logs to know what’s the issue.

Thanks!

Hi @Gassim,

1 Like

It might be that the boolean values are stored as numbers in the database to make calculations faster. According to the user guide on Boolean fields, Yes is translated to numeric 1, No to numeric 0.
I haven’t tested it myself but it is worth a try.

!d2:hasValue( #{Participant attendance} ) ||(#{Participant attendance} != ‘Session 3’ &&#{Attended} == 0) || (#{Participant attendance} != ‘Session 6’ && #{Attended} == 0)

Best Regards,
Paul

Thanks @dmbantu for testing it out! :smiley: And thank you @Paul for your suggestion, and I hope it works; however, if it doesn’t then we also need to know how come

doesn’t work? And my other question @dmbantu does #{Attended} == false work? [it shouldn’t if it’s value is 0/1]

Did you try maybe moving !d2 to the end?
(#{Participant attendance} != 'Session 3') || (#{Participant attendance} != 'Session 6') || !d2:hasValue( #{Participant attendance})

And… if all work separately, how about creating a separate program rule for each condition?!