Counting Duplicate Enrollments Based on Attribute in DHIS2 Tracker Program

Hi everyone,

I’m currently working on a DHIS2 implementation where I need to detect and count duplicate entries for a specific attribute across all enrollments within a Tracker program. Here is the specific scenario I’m dealing with:

  • Program Type: Tracker
  • Attribute: TB - Numero TB
  • Requirement: I need to check if there are any duplicates of TB - Numero TB across all enrollments and, if so, mark an indicator TB - Numero TB en double with the value “Yes”.

I initially tried using the following program rule condition:

d2:hasValue(‘TB - Numero TB’) && d2:countIfValue(‘TB - Numero TB’, ‘#{TB - Numero TB}’) > 1

However, I encountered the error:

Invalid ProgramVariable option: ‘TB’

Upon simplifying the condition to just check if TB - Numero TB has a value, it worked:

d2:hasValue(‘TB - Numero TB’)

This led me to believe that the issue lies in how d2:countIfValue works within the scope of the current enrollment. My understanding is that the program rules might be limited to the current enrollment and do not evaluate across all enrollments in the program.

Questions:

  1. Is there a built-in way to count occurrences of an attribute value across all enrollments within a DHIS2 Tracker program?
  2. If not, what would be the best approach to achieve this? Are there any examples of using external scripts or custom apps to handle such validation?
  3. Has anyone else encountered and solved a similar issue? Any advice or pointers would be greatly appreciated.

Thank you for your help!

Best regards,

Hi @elmoujarrade

You can enforce that certain attributes to be unique in the system so that there are no duplicates in the system. Are they allowed in purpose?