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,

Hi @elmoujarrade

  • My goal is to keep the field permanently hidden after the first visit, even if new events are created for the Visit stage.

Do you need to keep it hidden or just avoiding the editing? You could use the “block data entry form after completed” so even though the element reappears, the user no longer can edit it.

1 Like

Hi @nancyesp ,

Thank you for your suggestion!

In my case, I would like the field to remain permanently hidden for the first visit only, regardless of whether other visits are created. However, I still want to keep the ability to edit the data of the first visit if needed.

Let me know if there’s a way to achieve this while maintaining the flexibility to update the first visit’s data when required.

Thank you again for your support!

Best regards.

@elmoujarrade

I understand. There is a possibility but involves adding a new data element in your event which will work as an “identifier”.

Configure identifier

  1. Create a new data element (numeric/integer) “Event Number”
  2. Create a variable “data element from previous event” using that data element

#{event_number

  1. Create two rules:

3.1 Initial event
condition: V{program_stage_name} == “stage name” && !d2:hasValue(#{event_number})
action: Assign “1” to “Event Number”

3.2 Increment number (OPTIONAL)
condition: #{event_number} >= 1
action: Assign #{event_number} + 1 to “Event Number”

Configure “hide field” rule

  1. Create a new variable “data element in current event” using “Event Number”
  2. Create a rule

Condition: #{event_numberCURRENT} == 1
Action: Hide “xxxxx” data element

NOTE: This might not work correctly if you have multiple events with the same report date.

1 Like

Hi @nancyesp ,

Thank you for your support and suggestions!

I am pleased to inform you that the issue has been successfully resolved. The fields are now properly hidden for the first visit as intended.

Thank you again for your assistance—it was very helpful!

Best regards,

1 Like