Skip to content

fix(tracker): use d2-api typed tracker API for v42 org unit params#392

Open
ifoche wants to merge 2 commits intodevelopmentfrom
fix/tracker-ou-params-d2-api-v2
Open

fix(tracker): use d2-api typed tracker API for v42 org unit params#392
ifoche wants to merge 2 commits intodevelopmentfrom
fix/tracker-ou-params-d2-api-v2

Conversation

@ifoche
Copy link
Member

@ifoche ifoche commented Mar 19, 2026

Summary

  • Replace raw api.get("/tracker/trackedEntities", ...) calls with d2-api's typed api.tracker.trackedEntities.get() method, which handles v42 parameter naming (orgUnitMode, orgUnits with commas) internally
  • Upgrade d2-api to version with v42 tracker support (depends on d2-api PR #184)
  • Remove custom TrackedEntityGetRequest, TrackedEntitiesD2ApiResponse, and backward-compat response types
  • Replace string field selectors with typed object selectors for compile-time validation

Context

This is an alternative approach to PRs #386 and #387 for fixing the v42 tracker org unit parameter issue. Instead of fixing the parameter names locally in Bulk Load, this leverages d2-api's typed tracker API which handles the v42 naming internally.

Comparison with other PRs

PR #386 (direct fix) PR #387 (version-aware) This PR (d2-api typed API)
Approach Unconditionally use v42 params Runtime version branching Use d2-api typed methods
Lines changed +6/-7 +47/-13 +100/-137 (net -37)
Type safety Manual param names Manual param names Compile-time validated
d2-api dependency None None Requires d2-api PR #184
Future-proof Must update if params change Must update version checks d2-api handles changes

Dependencies

  • Requires d2-api PR #184 to be merged and released. Currently uses the git branch.

Test plan

  • TypeScript compilation passes with no new errors in modified files
  • All 54 unit tests pass
  • Pre-commit hooks (prettier, eslint, i18n, jest) all pass
  • Manual test: download tracker template with "Only selected organisation units" on DHIS2 v42 — verify only TEIs from selected OUs appear
  • Manual test: download tracker template with "Current user organisation units (data capture)" — verify correct TEI filtering

🤖 Generated with Claude Code

ifoche and others added 2 commits March 19, 2026 10:37
Replace raw api.get("/tracker/trackedEntities", ...) calls with d2-api's
typed api.tracker.trackedEntities.get() method, which handles v42 parameter
naming (orgUnitMode, orgUnits with commas) internally.

- Upgrade d2-api to version with v42 tracker support (PR #184)
- Update d2-api imports from 2.41 to 2.42
- Refactor getTeisFromApi, getExistingTeis, getAllTrackedEntities
- Remove custom TrackedEntityGetRequest, TrackedEntitiesD2ApiResponse
- Replace string field selectors with typed object selectors
- Rename buildOrgUnitMode → buildOrgUnitParams

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ifoche

This changes are not compatible with 2.40. I'm not sure if this important or not

Endpoint Parameter v2.40 v2.41 v2.42+
/tracker/trackedEntities org unit(s) orgUnit (; separated) orgUnit (;) ⚠️ or orgUnits (,) ✅ orgUnits (,)
/tracker/trackedEntities org unit mode ouMode ouMode ⚠️ or orgUnitMode orgUnitMode
/tracker/enrollments org unit(s) orgUnit (; separated) orgUnit (;) ⚠️ or orgUnits (,) ✅ orgUnits (,)
/tracker/enrollments org unit mode ouMode ouMode ⚠️ or orgUnitMode orgUnitMode
/tracker/events org unit mode ouMode ouMode ⚠️ or orgUnitMode orgUnitMode
/tracker/ownership/transfer org unit ou ou ou ⚠️ or orgUnit

Legend: ⚠️ = deprecated (still works but will be removed) · ✅ = recommended

But the bigger blocker right now is that we can’t even run/verify it.

In local (and in GitHub Actions) the tests/compile fail with:

  • Cannot find module '@eyeseetea/d2-api/2.42' from 'src/types/d2-api.ts'

So Jest can’t resolve the @eyeseetea/d2-api/2.42 entrypoint, which indicates that adding @eyeseetea/d2-api from a GitHub branch isn’t providing the expected published module paths (/2.42, and likely also /schemas) in the way our app imports it.

Therefore we can’t confirm the v41/v42 runtime behavior.

Normally we develop against a published beta of d2-api from npm because adding dependencies directly from a GitHub branch has caused issues in the past.
Arnau told me that this is the recommended approach now.

I think is necessary:

  1. publish a d2-api beta (including the v42 tracker OU params support), and
  2. update this PR to depend on that beta version from npm (so local + GitHub Actions can compile/test)

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.

2 participants