I’m working with the DHIS2 Tracker API and I need to retrieve a list of tracked entities (clients) that have no events at all in a specific programStage. In my application, the goal is to show only clients who are enrolled in a program but have not yet created any event in that particular programStage.
So far, I’ve been using the /api/tracker/trackedEntities endpoint with parameters like program, orgUnit, orgUnitMode=DESCENDANTS, programStage, fields=enrollments[events], and event-related filters such as eventOccurredAfter, eventOccurredBefore, and eventStatus. For example:
/api/tracker/trackedEntities?program=somePRG&orgUnit=someORG&orgUnitMode=DESCENDANTS&fields=trackedEntity,enrollments[events[event,programStage,status]]&eventOccurredAfter=2024-01-01&eventOccurredBefore=2024-12-31&eventStatus=ACTION
What I found is that I can successfully retrieve events using /api/tracker/events, and I can also retrieve tracked entities that have events. However, I cannot find any way to retrieve tracked entities that have no events at all in a specific programStage. I also tried filtering enrollments.events as empty (enrollments.events:), but that is not supported. The filter parameter only works for attributes, not for events or enrollments, and event date filters only work when events already exist.
So my question is: is there any supported way in the DHIS2 Tracker API to retrieve tracked entities that have no events in a specific programStage, or to get entities where the events list is empty for that stage? Or is the only recommended approach to fetch events separately and then exclude those tracked entities on the client side?