Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hl7.fhir.r4.model.StringType;
import org.opencds.cqf.fhir.cr.measure.MeasureStratifierType;
import org.opencds.cqf.fhir.cr.measure.common.GroupDef;
import org.opencds.cqf.fhir.cr.measure.common.StratifierComponentDef;
import org.opencds.cqf.fhir.cr.measure.common.StratifierDef;
import org.opencds.cqf.fhir.cr.measure.common.StratumDef;
import org.opencds.cqf.fhir.cr.measure.common.StratumPopulationDef;
Expand Down Expand Up @@ -149,40 +150,32 @@ private static void buildStratum(
Set<StratumValueDef> values,
List<MeasureGroupPopulationComponent> populations,
GroupDef groupDef) {
boolean isComponent = values.size() > 1;
// Drive output structure from the Measure definition, not the runtime value count:
// a stratifier declared with `Measure.stratifier.component[]` always emits values into
// `stratum.component[].value` per FHIR, even when it has only a single component.
boolean isComponent = !stratifierDef.components().isEmpty();
for (StratumValueDef valuePair : values) {
StratumValueWrapper value = valuePair.value();
var componentDef = valuePair.def();
// Set Stratum value to indicate which value is displaying results
// ex. for Gender stratifier, code 'Male'
if (value.getValueClass().equals(CodeableConcept.class)) {
if (isComponent) {
StratifierGroupComponentComponent sgcc = new StratifierGroupComponentComponent();
// component stratifier example: code: "gender", value: 'M'
// value being stratified: 'M'
sgcc.setValue(expressionResultToCodableConcept(value));
// code specified from componentDef: "gender"
sgcc.setCode(
new CodeableConcept().setText(componentDef.code().text()));
// set component on MeasureReport
stratum.addComponent(sgcc);
stratum.addComponent(buildStratumComponent(componentDef, expressionResultToCodableConcept(value)));
} else {
// non-component stratifiers only set stratified value, code is set on stratifier object
// value being stratified: 'M'
stratum.setValue((CodeableConcept) value.getValue());
}
} else if (isComponent) {
// component stratifier example: code: "gender", value: 'M'
StratifierGroupComponentComponent sgcc = new StratifierGroupComponentComponent();
// value being stratified: 'M'
sgcc.setValue(expressionResultToCodableConcept(value));
// code specified from componentDef: "gender"
sgcc.setCode(new CodeableConcept().setText(componentDef.code().text()));
// set component on MeasureReport
stratum.addComponent(sgcc);
stratum.addComponent(buildStratumComponent(componentDef, expressionResultToCodableConcept(value)));
} else if (MeasureStratifierType.VALUE == stratifierDef.getStratifierType()
|| MeasureStratifierType.NON_SUBJECT_VALUE == stratifierDef.getStratifierType()) {
// non-component stratifiers (single-component or non-component) only set stratified value
// non-component value stratifiers only set stratified value
// value being stratified: 'M', '35', etc.
stratum.setValue(expressionResultToCodableConcept(value));
}
Expand Down Expand Up @@ -230,6 +223,18 @@ private static CodeableConcept expressionResultToCodableConcept(StratumValueWrap
return new CodeableConcept().setText(value.getValueAsString());
}

private static StratifierGroupComponentComponent buildStratumComponent(
StratifierComponentDef componentDef, CodeableConcept value) {
StratifierGroupComponentComponent sgcc = new StratifierGroupComponentComponent();
sgcc.setId(componentDef.id());
sgcc.setValue(value);
// component code text comes from Measure.stratifier.component[].code.text; may be null
if (componentDef.code() != null) {
sgcc.setCode(new CodeableConcept().setText(componentDef.code().text()));
}
return sgcc;
}

// TODO: LD: take the StratumDef and use it to figure out the subject ID intersection instead of
// the provided list of subjectIds
// Simplified by Claude Sonnet 4.5 to use calculated values from StratumPopulationDef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public static String getStratumDefText(StratifierDef stratifierDef, StratumDef s
public static boolean matchesStratumValue(
StratifierGroupComponent reportStratum, StratumDef stratumDef, StratifierDef stratifierDef) {

if (stratumDef.isComponent()) {
// A stratifier defined with `Measure.stratifier.component[]` always emits component-shaped
// strata, even for a single component — gate on the definition, not the runtime value count.
if (!stratifierDef.components().isEmpty()) {
return matchesComponentStratumValues(reportStratum, stratumDef);
}

Expand Down
Loading
Loading