Fix multi-component stratifier alignment for list + scalar#1042
Merged
lukedegruchy merged 3 commits intoJun 1, 2026
Conversation
A boolean (subject) basis stratifier with two components — one returning a per-patient List and one returning a per-patient scalar — emitted one stratum per component value with a single component, instead of one stratum per unique (list-element, scalar) tuple with both components. Root cause: collectFunctionRowKeys only collected alignment row keys from function (Map) results, so a scalar component sharing a subject with an iterable component fell back to a subject-only row key. The iterable's composite per-element keys and the scalar's subject-only key never intersected, producing disjoint single-component strata. Generalize the collector (renamed collectAlignmentRowKeys) to also gather row keys from iterable results, so scalars expand alongside list elements via the existing expandScalarToAlignmentRowKeys path. Tighten the scalar fallback: when the stratifier has multi-value components but a given subject produced none (empty Map or List), the subject contributes no stratum — matching the existing empty-list semantic. Adds single-subject and multi-subject MeasureStratifierTest cases plus a CohortBooleanMultiComponentListScalarStrat fixture that pairs the existing "Distinct Encounter Statuses" list expression with the "Gender Stratification String" scalar. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Formatting check succeeded! |
Extract per-entry work into a helper method to flatten nesting and remove duplicated qualifiedSubject/computeIfAbsent setup across the Map and Iterable branches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rs-multi-component-report-strata
|
brynrhodes
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This branch fixes a
$evaluate-measurestratifier defect (CDO-715) in which a boolean-basis stratifier composed of one multi-value (list) component and one scalar component emitted disjoint single-component strata instead of strata containing a value from every declared component. The fix generalizes the existing "function row key" alignment pass — previously applied only toMap<?, ?>(function) component results — so it also collects alignment row keys fromIterable<?>(list) component results, then expands scalar components onto those keys. As a side effect, the empty-list / empty-map case now suppresses the affected subject's stratum contribution entirely when the stratifier as a whole produces alignment rows, matching the existing single-component empty-list semantics.collectFunctionRowKeys→collectAlignmentRowKeys, with parallel handling forIterable<?>results that emits(subject | iterableElement(value, index))row keys.expandScalarToMatchFunctionRowKeys→expandScalarToAlignmentRowKeysand route scalar expansion through the unified alignment-keys map so list+scalar mixes align the same way function+scalar mixes already did.Map/ emptyList), that subject now contributes zero strata instead of falling back to a subject-only scalar row.collectAlignmentRowKeysForEntryhelper to keep cognitive complexity within Sonar limits after the new branch was added.CohortBooleanMultiComponentListScalarStrat) plus single-subject and multi-subject tests covering the (encounter-status list × gender scalar) tuple expansion across the existing test patient set.Worked example
CQL expressions (
LibrarySimple.cql) — one returns a per-patient list, the other returns a per-patient scalar:For
Patient/patient-9(two Encounters with statusesfinishedandin-progress, gendermale) these evaluate to:Measure stratifier — two components, one referencing the list expression, one referencing the scalar:
MeasureReport stratum — before the fix (broken: three single-component strata, gender never appears alongside encounter status):
MeasureReport stratum — after the fix (two strata, each carrying both components — one per
(status, gender)tuple):