Skip to content

fix: apply org unit hierarchy in event and enrollment pivot tables - #1846

Draft
HendrikThePendric wants to merge 3 commits into
masterfrom
fix/pt-engine-handle-prefixed-ou-dimensions-DHIS2-22094
Draft

HendrikThePendric wants to merge 3 commits into
masterfrom
fix/pt-engine-handle-prefixed-ou-dimensions-DHIS2-22094

Conversation

@HendrikThePendric

@HendrikThePendric HendrikThePendric commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Implements DHIS2-22094

Description

Two fixes in PivotTableEngine so org unit hierarchy can work in event and enrollment pivot tables.

  1. The org unit dimension was found by literal key. allByDimension['ou'] never matched a stage-qualified dimension (<stageId>.ou), and matched at most one org unit dimension per layout. It now matches any org unit dimension — by dimensionType where the response provides it, by unqualified dimension id otherwise.

  2. applyHierarchy looked for each org unit's id in the wrong place. metaData.items is a map keyed by id, and its values hold only a name — so item.uid is undefined. The id was already to hand: buildDimensionLookup stores it in itemIds, positionally paired with items. Reading it from the item instead overwrote itemIds with [undefined, …], which broke the row lookup and left every value cell empty whenever showHierarchy was on. Ids now come from itemIds and stay paired with their items through the sort.

Fix 2 is pre-existing and independent of fix 1, and needs no backend change — the response was never missing anything. Checked on 2.41.10, 2.42.6, 2.43.1 and 2.44-SNAPSHOT: metaData.items values are {name: 'Bo'} on both /api/analytics and the event/enrollment aggregate endpoints.

Dependency chain

This PR on its own changes nothing user-visible. The feature needs three parts:

# Where What Status
1 dhis2-core DHIS2-22119 — no hierarchy metadata returned for a stage-qualified ou open
2 this PR engine finds the org unit dimension and applies the hierarchy correctly here
3 dhis2/event-visualizer-app#384 sends showHierarchy=true on pivot requests open

Enrollment pivots need 2 + 3 only — they already send a bare ou.
Event pivots need all three; without 1 the backend returns no hierarchy to apply.

Draft until the chain is verified end to end.

🤖 Generated with Claude Code

@HendrikThePendric
HendrikThePendric marked this pull request as draft September 16, 2026 14:18
metaData.items entries carry only a name, so item.uid is undefined on
every analytics endpoint. Reading the id from there left itemIds as an
array of undefined, which broke the row lookup and rendered every value
cell empty whenever showHierarchy was on.

Take the ids from ouDimension.itemIds, where they already live, and keep
them paired with their items through the sort. sortByHierarchy becomes a
comparator so the pairs can sort together.

The hierarchy spec fixture carried a uid on its items, which no endpoint
returns; correcting it is what exposed this.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@HendrikThePendric HendrikThePendric changed the title fix: allow ou dimension to be prefixed fix: apply org unit hierarchy in event and enrollment pivot tables Sep 16, 2026
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