Tracker Android Capture program rules - Visit incrementation

Hi,

For a tracker program we had running on DIHIS2 Version 2.38 with older Android capture version (prior to version 3.0), whe were using a program rules variable and program rules to increment the visit number Data element for each new event in a repetition stage (Follow-up stage).

We were using the following program rule variables and data elements for the “Follow-Up stage” (repeatable):

Data Element = Test Visit Number

  • List item value Type = POSITIVE INTEGER, domain TRACKER)

Program Rule variable: = “Session Number Previous”

  • Source Type = Data element from previous event
  • Date element = Test Visit Number

Program rules:
"Assign Session number for first follow-up visit
Condition = !d2:hasValue(#{Session Number Previous})
Action = Assign Value “1” to DE “Test Visit Number”

Asign Session Number visit > 1
Condition = d2:hasValue(#{Session Number Previous})
Action Assign Value “#{Session Number Previous}+1” to DE “Test Visit Number”

The rule was working well previsously, but we are facing the errror message “There is a loop in your program rules, please contact ytour administrator”. on Android Capture 3.0.1.

On play, it seems to work ok for the first and second event in follow up stage. But for the third event, after changing the event date (in the past after the second event date), I have the “loop” error message, and the visit numer is random number.

If I close the event, and open it again the visit numer is back to 3 (expected value for third event).

We used to have the same program rule on 2.38 and never faced this issue.
Was there any change in the Android rule engine which could explain this behaviour?

I did set up a test program on Play to reproduce the issue, it is available here:
DHIS 2 Maintenance

I also add screenshot from Android Caputr Training 3.0.1

Thanks in advance for your help.


Another may be interesting insight is that we can create the second and third Events for “Follow up” stage using Tracker Capture App, but I get error messages when trying to add the second event using new Capture App. please see screenshot below.

From android Application (3.0.1 Training), we get error messages for synchro when the “Session number” don’t match with the value they should have. If I open and close each event in the correct order, the Session numbers get realigned and i can save (As long as i don’t have 2 events on the same day).


.

Hi @gregory, thank you for reaching out and creating a test program to recreate this, it helped a lot for troubleshooting the issue.
I am not sure why it didn’t fail in other versions but it does make sense that it would go into a loop, as the second program rule condition will check whether previous visit number has value, and add one to the current visit, and then check whether it has value and add one and so on.
By adding a few more checks to the condition to set the value it does work as expected.

new program rule condition:

d2:hasValue(#{Session Number Previous}) && !d2:hasValue(#{Sesion Number}) && ((#{Sesion Number} - #{Session Number Previous}) < 2)

I have however detected an unexpected behaviour where after modifying the event date where the Visit number field becomes editable which is not correct. And would break the assignment addition for visit number data element if the user modifies it and it does not fulfill the new program rule condition.

image
image

I have created an issue to resolve this in Jira you can track it here

Don’t hesitate to get in touch if you encounter any other issues.

Regards

Xavier Molloy

1 Like

Many thanks @Xavi for your quick support on this, much appreciated.

I will test this afternoon and come back to you with the results. I am still trying to understand the last condition (session number - session number previous<2), and trying to understand the potential impact when updating one of the first events after having creating multiple events.

If there is a better way (and more generally used) way to increment visit numbers, I am interested in using it instead of our current method.

Regards

I just did somes tests, and i confirm this is working except for the assigned Visit number fields being iedtable after updating event date (as you mentioned).

But at least, the Loop error mesage disappeard, thanks for this

1 Like

That condition is simply to verify that the loop does not happen, an example would be the following:
you are entering the 3rd event for example, visit number for previous event would be 2 , visit number for the third event is empty so the program rule will assign the value of previous event visit number plus 1 which would be 3.
As soon as the value is assigned the program rule will run again. In previous scenario it would continuously add one with each reassignment causing the loop.

!d2:hasValue(#{Sesion Number}) will ensure that the value is only assigned once and (session number - session number previous<2) will ensure that it never goes into a loop if the new visit number is not consecutive to the previous event visit number, for example if current event visit number is 4 and previous event visit number is 2, 4-2 = 2 which is not smaller than 2 so it will not assign a new value to the current event visit number.

To be fair it might not be needed I would have to double check this but it’s more of a failsafe mechanism :slightly_smiling_face:

I will look into whether there is another way of incrementing visit numbers and get back to you.

Kind regards

I can confirm that there is no other way to automatically increase by one a data set when creating an event other than with program rules :slightly_smiling_face:

Hi @Xavi
Many thanks for the additional explainations.

Regarding the “editable” field for visits, we can consider it as a bug, which should be corrected in one of the next android Release?

Would you knwo when is the next release planned, and if this point will be corrected or not? I am trying to plan whether I should inform the users or if the correction will be out before this form deployment planned at the beginning of november.
Thanks in advance

Hi @gregory , we are certainly going to try and fix the for the upcoming release which is planned for the 11th of November, however I cannot ensure that it will be fixed before this release (3.1.0) or for the patch release (3.1.1). Regardless of this, if your form deployment is planned for the beginning of November I think you should inform the users of this.

Sorry for any inconvenience we may cause you and the users and don’t hesitate to get in touch if you have any other problems or questions.

Kind regards.

Hi @Xavi Thanks for the update. Have a good day.