Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appliesResult to StratifierResult in detailed results output #308

Merged
merged 9 commits into from
Aug 9, 2024
17 changes: 17 additions & 0 deletions src/calculation/DetailedResultsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,27 @@ export function createPatientPopulationValues(
populationGroup.stratifier.forEach(strata => {
if (strata.criteria?.expression) {
const value = patientResults[strata.criteria?.expression];

// if the cqfm-appliesTo extension is present, then we want to consider the result of that
// population in our stratifier result
const appliesToExtension = strata.extension?.find(
e => e.url === 'http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-appliesTo'
);

let popValue = true;
if (appliesToExtension) {
const popCode = appliesToExtension.valueCodeableConcept?.coding?.[0].code;
if (popCode) {
popValue = patientResults[popCode];
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't the right place to get the results for population as the patientResults is the raw data from the engine. The define statement that provides the results might not match the code. Should look back at the populationResults that have already been collected and find by populationType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Additionally the populationResults will not be accurate at this point and should happen after the call to handlePoulationValues on line 35.

}
}
const result = isStatementValueTruthy(value);
const appliesResult = isStatementValueTruthy(value && popValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

This call to isStatementValueTruthy shouldn't be needed as the && should be done on the result and the boolean result found in the populationResults.


stratifierResults?.push({
strataCode: strata.code?.text ?? strata.id ?? `strata-${strataIndex++}`,
result,
appliesResult,
...(strata.id ? { strataId: strata.id } : {})
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/types/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ export interface StratifierResult {
* True if patient or episode is in stratifier. False if not.
*/
result: boolean;
/**
* True if patient or episode is in stratifier AND the population
* result it appliesTo is true. False if not. Only implemented for
* patient based measures currently.
*/
appliesResult?: boolean;
strataId?: string;
}

Expand Down
96 changes: 96 additions & 0 deletions test/unit/DetailedResultsBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,102 @@ describe('DetailedResultsBuilder', () => {
});
});

describe('Patient Population Values', () => {
test('should take population result into consideration when appliesTo extension exists', () => {
const populationGroup: fhir4.MeasureGroup = {
stratifier: [
{
id: 'example-strata-id',
extension: [
{
url: 'http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-appliesTo',
valueCodeableConcept: {
coding: [
{
system: 'http://terminology.hl7.org/CodeSystem/measure-population',
code: 'initial-population',
display: 'Initial Population'
}
]
}
}
],
criteria: {
expression: 'strat1',
language: 'text/cql'
}
}
]
};

const patientResults: StatementResults = {
'Initial Population': false,
Denominator: false,
'Denominator Exclusion': false,
Numerator: false,
'Numerator Exclusion': false,
strat1: true
};

const { stratifierResults } = DetailedResultsBuilder.createPatientPopulationValues(
populationGroup,
patientResults
);

expect(stratifierResults).toBeDefined();
expect(stratifierResults).toHaveLength(1);
expect(stratifierResults).toEqual(
expect.arrayContaining([
expect.objectContaining({
strataId: 'example-strata-id',
result: true,
appliesResult: false
})
])
);
});

test('does not take any population result into consideration when appliesTo extension does not exist', () => {
const populationGroupNoExtension: fhir4.MeasureGroup = {
stratifier: [
{
id: 'example-strata-id-2',
criteria: {
expression: 'strat2',
language: 'text/cql'
}
}
]
};

const patientResults: StatementResults = {
'Initial Population': false,
Denominator: false,
'Denominator Exclusion': false,
Numerator: false,
'Numerator Exclusion': false,
strat2: true
};

const { stratifierResults } = DetailedResultsBuilder.createPatientPopulationValues(
populationGroupNoExtension,
patientResults
);

expect(stratifierResults).toBeDefined();
expect(stratifierResults).toHaveLength(1);
expect(stratifierResults).toEqual(
expect.arrayContaining([
expect.objectContaining({
strataId: 'example-strata-id-2',
result: true,
appliesResult: true
})
])
);
});
});

describe('ELM JSON Function', () => {
test('should properly generate episode-based ELM JSON given name and parameter', () => {
const exampleFunctionName = 'exampleFunction';
Expand Down
Loading