Need urgent help - program rule using d2:countIfValue not working

Hi, all.

In a repeatable stage, I have a yes/no data element to track. That is, if the answer to this DE is No four consecutive times, then display a message and block program stage for future data entry. In other words, if the answer to the DE is No for 1st, 2nd, 3rd and 4th visits, display a message and block user input for the program stage). I need a counter

I did try this, but it is not working. There may a syntax problem in this rule or the PR does not make sense

V{program_stage_id} == ‘H1r8g2lxK4i’ && V{event_count} == 4 && d2:countIfValue( #{ARCO_Was the patient found}, false ) == 4

Did you try to have a program indicator count the No and then create a program rule which have in its condition the program indicator?

Hi @SDKAAA,

Below is the way I built the program indicator to count the number of No answers, but the filter is giving error. Maybe something is wrong.

Aggregation type: count

Analytics type: event

Expression: V{value_count}

Filter: ARCO_Was the patient found==No

A part from the Program indicator issue, I am wondering if you could show me how to have the program indicator as a condition in the program rule.

Thanks.

Hi @SDKAAA and every one,

I seem to have made progress but I think I am missing something, Please see and comment on my steps.

  1. I created a counter as a data element and a program variable for this DE.
  2. I created a program rule to count number of no answers.
    PR expression: d2:hasValue( V{enrollment_date} ) - to mean trigger the rule when the enrollment date is selected.
  3. I created program rule action: assign value to data element counter:
  4. expression to evaluate and assign: d2:countIfValue( DE, ‘false’ )

When entering data and selecting No for 4 consecutive visits, I see the counter working properly, but the following program rule to trigger a message if the condition is met does not work.

V{program_stage_id} == ‘program Stage uid’ && V{event_count} == 4 && counter == 4. If this condition were met, an error on complete or show error message should be triggered.

Hi everyone,

In a repeatable stage, I have a yes/no data element to track. That is, if the answer to this DE is No four consecutive times, then display a message and block program stage for future data entry. In other words, if the answer to the DE is No for 1st, 2nd, 3rd and 4th visits consecutively, display a message and block user input for the program stage). I have taken the following series of steps:

  1. I created a counter as a data element and a program variable for this DE.
  2. I created a program rule to count number of no answers.
    PR expression: d2:hasValue( V{enrollment_date} ) – which means mean trigger the rule when the enrollment date is selected.
  3. I created program rule action: assign value to data element counter:
  4. expression to evaluate and assign: d2:countIfValue( DE, ‘false’ )

When entering data and selecting No for 4 consecutive visits, I see the counter working properly, but the following program rule to trigger a message if the condition is met does not work.

V{program_stage_id} == ‘program Stage uid’ && V{event_count} == 4 && counter == 4. If this condition were met, an error on complete or show error message should be triggered.

Thanks

Thank you for your patience @fernando ! I have sent @dhis2-tracker team a message to support you.

I moved the topic you just created back to this topic so that the discussion can be continued rather than separated. Thank you @fernando !

Hi @Gassim,

Hi, has there been any progress on this?

Thanks

1 Like

@fernando thanks for following up. To improve tracker support questions we have created several groups depending on the question.

@tracker-programRules may you please check this post from Apr 27, 2021. Thank you!

I think the event count part of the expression is not needed? Try to change the expression to V{program_stage_id} == ‘program Stage uid’ && counter == 4.

Make sure in the rule that assigns that this rule has a priority - guaranteeing that the rule is triggered before the rule that looks at the value of counter.

Also, when assigning a value to a data element, and this data element also is connected to a variable(I assume DE counter is linked to #{counter} or similar) - the assign rule should be set up to assign BOTH to the data element, AND to the program rule variable. In fact, there is many cases where you do not need a data element at all, and could just use a calculated vale type program rule variable called #{counter}

Hi, @Markus,

Sorry, but I did not understand this part well:

The rule you mention in point 2 above:

  1. I created a program rule to count number of no answers.
    PR expression: d2:hasValue( V{enrollment_date} ) – which means mean trigger the rule when the enrollment date is selected.

Make sure in this rule that you assign for example “1” in the priority field of this program rule. Making it priority 1 will make sure it runs before all other rules with either lower priority, or no priority. Priority is entered in the first screen creating or editing the program rule. The reason you need priority is that you have another rule(showing an error on complete) that relies on the program rule for assigning counter to run before it.

In your assign action from point 3 above:

  1. I created program rule action: assign value to data element counter:

Make sure to assign both to the data element, and also to the program rule variable that belongs to this program rule variable:

1 Like

Hi @Markus,

I have followed the steps you mentioned, but things still do not work. I am wondering if you could explain to me how a calculated value type works by using a program rule variable called #{counter} .i,e a step by step explanation.

I created a counter data element because I hadn’t found any way to achieve what I wanted. I think using a calculated value will make things easier for me.

Thanks again

1 Like

Hey @fernando
To include the #{counter} in your expressions, you have to have a program rule variable with the name counter in your program rule variables list. I assume you already have this variable in the list of program rule variables? You can change the variable source type to “Calculated value”, then it will serve as a place for your program rules to assign values that is needed by other program rules.

This is a bit advanced, let me try to compile a complete recipe for how I would approach it:

  • make a program rule variable called counter, with the source type “Calculated value”
  • make a program rule variable called dataElementX, with the source type “Data element in the newest event in the current program”, and connect to a data element X where you are sure that the data element is collected in every stage - in your case above you referred to this data element as “DE”.
  • make a rule that has priority 1 that assigns the number of repeated events to the variable #{counter}. The assign action should assign #{counter} and the expression should be d2:countIfValue( #{dataElementX}, ‘false’ ) - if you only want to count the cases where “No” was selected.
  • make a rule that has expression #{counter} >= 4 and action “hide program stage” to hide the stage you do not want to add more than 4 instances of.

Perhaps it could be helpful if you take screenshots of the rules, actions and variables involved here? Then someone might be able to spot what is causing the problem.

Markus

1 Like

Hi @Markus,

I have followed all the steps you have mentioned, but the PR is still not working. I am attaching the screen shots. I just tested it on demo:

  1. I created a test program stage with one compulsory data element which if the answer is NO four consecutive times, the test program stage must be hidden.

  2. created a counter program variable with source type 'calculated value

  3. Created a program rule variable called Yellow fever dose as shown in image 1 , with the source type “Data element in the newest event in the current program”

  4. Created a PR with priority 1 that assigns the number of repeated events:


  1. Created a rule that has expression #{counter} >= 4 and action “hide program stage” to hide the test program stage


NB: Here one demo, I just created one program stage to test the PR, but my program has five program stages and the PR should be valid across all program stages.

Thanks

Hi @fernando! I replicated it in https://play.dhis2.org/2.35.6 and the stage is hiding when the YesNo question is answered with 4 ‘falses’.

I created a PR with a displayText action just to make sure the counter was behaving correctly.

  1. Variables


  2. Rules
    Count ‘No’



Hide Stage
image

  1. Results

Hope this helps.

Nancy.

4 Likes

Hi @nancyesp,

I have just logged into demo to see what you had replicated so that I could see if I was missing something, but unfortunately it has been deleted. What puzzles me is that despite following all the steps you mentioned in your screenshots, the PR to hide the program stage is still not working. Would you mind replicating the PR in demo, so that I can log in again to see what I may be missing?

Thanks

Hi @fernando!

The program is in https://play.dhis2.org/2.35.6 now. Also, when changing a PR, try cleaning cache or using an incognito window just in case.

I’m also attaching the json file in case you need to import it in another server.
XX Test program.json (36.0 KB)

Let me know how it goes.

1 Like

Hi @nancyesp , @Markus,

Thank you for your help. I think the problem is with DHIS 2 version 2.34.4 which I am using, but the same happened when I logged into demo 2.34.4 and tested the PR, it does not work. Today I tested the same program rule in demo version 2.35.6 and it works properly. Does this have anything to do with DHIS 2 version?

@nancyesp. regarding the json file, How can I import it into my server, I opened it and I saw that it has to do with the program, program stage, username, data element and program rules as you created in demo. What kind of modifications do I have to make to the file before importing it?

Thanks

@fernando,

I did not find a specific jira ticket but it looks like might be a problem (in 2.34) with the assign action.

To import, you’ll need to make sure to remove all the default cat combo IDs and all the references IDs to Org Units or TETs not existing in your server.