Issue with hiding a field during the first event in a Tracker program

Hello everyone,

I’m facing an issue with a program rule in DHIS2 (version 2.40.5). My goal is to hide a field during the first event only in a Tracker program. Here’s how I’ve configured it:

  1. The condition used in the rule is:
    V{event_count} == 1
    
  2. The action is to hide a specific field when this condition is met.
  3. I’ve ensured the rule is correctly saved and applied in the program.

The Problem:

  • The rule doesn’t work on either the Web version or the Android app.
  • I’ve tried synchronizing metadata and testing alternative configurations, but the field remains visible during the first event.

My Questions:

  1. Is using V{event_count} the correct approach to target the first event?
  2. Are there any alternative methods or configurations to achieve this?
  3. Are there any known bugs with program rules in this version?

Thank you in advance for your help and suggestions!

Hi @elmoujarrade!

Thank you for the report.

The condition you are using is fine. I was able to configure it and results are correct in Capture and Android App.

Which version of the Android App are you using? and Do you have multiple stages in your program? The V{event_count} variable will count any event created, no matter if you select a specific stage to trigger the rule.

2 Likes

Hi @nancyesp ,

Thank you for your response.

Yes, I have two stages in my program:

  1. Initial Report (non-repeatable)
  2. Visit (repeatable stage)

The Visit stage is the one where the rule is applied. Since the V{event_count} counts all events across all stages, it seems to be triggering incorrectly. I need the rule to only apply for the first event in the Visit stage.

I am currently using Android App version 3.0.1. Do you have any suggestions on how to make the rule stage-specific, so it applies only to the first event of the Visit stage?

Thank you for your help!

Best regards,

I believe you can’t apply the variable directly to a stage but two possible solutions could be:

  1. Assuming you will always fill the “initial report first”, your condition will change from “V{event_count} == 1” to “V{event_count} <= 2”

  2. If there is a possibility to start with the visit stages and not the report one, then you could try counting the value of a mandatory element and use that value for the condition.

Example:

  1. Identify a data element that is specific and required for the stage you want to count.

  2. Use the d2:count function in your program rule expression to count the occurrences of this data element.

d2:count(#{programStage.dataElement}) <= 1

Make sure the variable used for that data element is “Data element from the newest event in the current program”

2 Likes

Hi @nancyesp

Thank you for your suggestions!

I tested the second option, using the d2:count function with a mandatory data element specific to the Visit stage, and it worked perfectly. The rule is now correctly triggered only for the first event in the Visit stage.

Thank you again for your help—it resolved the issue!

Best regards,

1 Like

Hi @nancyesp ,

Thank you again for your previous suggestion. I implemented the second option using the d2:count function, and it initially worked for hiding the field during the first event of the Visit stage.

However, I noticed an issue during further testing:

  • When I create a second event for the Visit stage, the field reappears for both the first and second visits.
  • My goal is to keep the field permanently hidden after the first visit, even if new events are created for the Visit stage.

Could you please guide me on how to adjust the rule so the field remains permanently hidden?

Thank you in advance for your help and guidance!

Best regards,