Skip to content

fix(tracker): use v42 tracker API params for org unit filtering#386

Open
ifoche wants to merge 1 commit intodevelopmentfrom
fix/tracker-ou-params-v42
Open

fix(tracker): use v42 tracker API params for org unit filtering#386
ifoche wants to merge 1 commit intodevelopmentfrom
fix/tracker-ou-params-v42

Conversation

@ifoche
Copy link
Member

@ifoche ifoche commented Mar 3, 2026

Summary

  • Replace deprecated ouMode with orgUnitMode, orgUnit with orgUnits (plural), and semicolon delimiter with commas for /tracker/trackedEntities endpoint
  • Fixes TEI population ignoring selected org units in DHIS2 v42 (returns all accessible TEIs instead of only selected OUs, causing slow performance and incorrect data)

Related Tasks

Test plan

  • Unit tests pass (54/54)
  • TypeScript compiles cleanly
  • Manual verification: download populated tracker template on DHIS2 v42 with "Only selected organisation units" — TEIs filtered correctly

🤖 Generated with Claude Code

Replace deprecated ouMode/orgUnit params with orgUnitMode/orgUnits and
comma delimiter for /tracker/trackedEntities endpoint. Fixes TEI
population ignoring selected org units in DHIS2 v42.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bundlemon
Copy link

bundlemon bot commented Mar 3, 2026

BundleMon

No change in files bundle size

Groups updated (1)
Status Path Size Limits
Build Folder
./**/*
1.72MB (-166.5KB -8.65%) +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@ifoche
Copy link
Member Author

ifoche commented Mar 3, 2026

confirmed that it works on my side. Just one doubt. Bulk Load seems to be badly designed when it comes to this endpoint (the new endpoint for TEIs). Bulk Load is using a separate call instead of implementing this in d2-api. For that reason I have implemented the modification also in the app, which happens to work.

But we would need to do that in d2-api if we wanted to cover this. Specifically:

d2-api has two separate TEI APIs:

  • trackedEntityInstances.d.ts (legacy) - uses ouMode (correct for the old /api/trackedEntityInstances endpoint)
  • trackerTrackedEntities.d.ts (new tracker API) - also defines ouMode on line 89, but this is wrong for v42 where the actual HTTP parameter is orgUnitMode

But the app bypasses d2-api's typed tracker class entirely. At Dhis2TrackedEntityInstances.ts:549:
await api.get("/tracker/trackedEntities", filterQuery)
It uses raw api.get() instead of api.tracker.trackedEntities.get(). So d2-api's tracker types aren't used for the actual HTTP call - only the ouMode type union is borrowed from the legacy TeiOuRequest for type definitions.

The ideal design would be both:

  1. In d2-api: Update TrackedEntitiesParamsBase (line 84-113 of trackerTrackedEntities.d.ts) to rename ouMode to orgUnitMode, and have the TrackedEntities.get() method send the correct parameter name. This is the right long-term fix since it's the library's job to abstract over DHIS2 API evolution.
  2. In the app: Migrate from raw api.get("/tracker/trackedEntities", ...) to the typed api.tracker.trackedEntities.get() call, which would make the app benefit from d2-api's corrected parameter mapping automatically.

But the d2-api fix alone wouldn't help - since the app bypasses the typed class and builds its own query params, fixing d2-api would only fix the type definitions, not the actual HTTP calls the app makes.

So the pragmatic solution here: the app fix is the critical one regardless. A d2-api fix would be a good companion improvement (type correctness + making it possible to use the typed API), but it's not a prerequisite and wouldn't solve the problem by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant