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
43 changes: 43 additions & 0 deletions src/calculation/DetailedResultsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
populationResults = popAndStratResults.populationResults;
stratifierResults = popAndStratResults.stratifierResults;
populationResults = handlePopulationValues(populationResults, populationGroup, measureScoringCode);
if (stratifierResults) {
stratifierResults = handleStratificationValues(populationGroup, populationResults, stratifierResults);
}
} else {
// episode of care based measure
// collect results per episode
Expand All @@ -45,6 +48,9 @@
const popAndStratResults = createPatientPopulationValues(populationGroup, patientResults);
populationResults = popAndStratResults.populationResults;
stratifierResults = popAndStratResults.stratifierResults;
if (stratifierResults) {
stratifierResults = handleStratificationValues(populationGroup, populationResults, stratifierResults);
}
} else {
populationResults = [];
stratifierResults = [];
Expand Down Expand Up @@ -97,6 +103,9 @@
}
});
});
if (stratifierResults) {
stratifierResults = handleStratificationValues(populationGroup, populationResults, stratifierResults);
}
}
}
const detailedResult: DetailedPopulationGroupResult = {
Expand Down Expand Up @@ -305,6 +314,7 @@
if (strata.criteria?.expression) {
const value = patientResults[strata.criteria?.expression];
const result = isStatementValueTruthy(value);

stratifierResults?.push({
strataCode: strata.code?.text ?? strata.id ?? `strata-${strataIndex++}`,
result,
Expand All @@ -320,6 +330,39 @@
};
}

export function handleStratificationValues(
populationGroup: fhir4.MeasureGroup,
populationResults: PopulationResult[],
stratifierResults: StratifierResult[]
): StratifierResult[] {
if (populationGroup.stratifier) {
populationGroup.stratifier.forEach(strata => {
elsaperelli marked this conversation as resolved.
Show resolved Hide resolved
if (strata.criteria?.expression) {

Check warning on line 340 in src/calculation/DetailedResultsBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const strataResult = stratifierResults.find(strataRes => strataRes.strataId === strata.id);

if (strataResult) {
// 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;

Check warning on line 352 in src/calculation/DetailedResultsBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 352 in src/calculation/DetailedResultsBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (popCode) {
popValue = populationResults.find(pr => pr.populationType === popCode)?.result ?? true;

Check warning on line 354 in src/calculation/DetailedResultsBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 354 in src/calculation/DetailedResultsBuilder.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}
}
console.log(popValue);
elsaperelli marked this conversation as resolved.
Show resolved Hide resolved
strataResult.appliesResult = isStatementValueTruthy(popValue && strataResult.result);
elsaperelli marked this conversation as resolved.
Show resolved Hide resolved
}
}
});
}
return stratifierResults;
}

function isStatementValueTruthy(value: any): boolean {
if (Array.isArray(value) && value.length > 0) {
return true;
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
116 changes: 115 additions & 1 deletion test/unit/DetailedResultsBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as DetailedResultsBuilder from '../../src/calculation/DetailedResultsBu
import { getJSONFixture } from './helpers/testHelpers';
import { MeasureScoreType, PopulationType } from '../../src/types/Enums';
import { StatementResults } from '../../src/types/CQLTypes';
import { PopulationResult, EpisodeResults } from '../../src/types/Calculator';
import { PopulationResult, EpisodeResults, StratifierResult } from '../../src/types/Calculator';
import { ELMExpressionRef, ELMQuery, ELMTuple, ELMFunctionRef } from '../../src/types/ELMTypes';

type MeasureWithGroup = fhir4.Measure & {
Expand Down Expand Up @@ -1111,6 +1111,120 @@ describe('DetailedResultsBuilder', () => {
});
});

describe('handleStratificationValues', () => {
test('it should take population result into consider 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 populationResults: PopulationResult[] = [
{
populationType: PopulationType.IPP,
criteriaExpression: 'Initial Population',
result: false,
populationId: 'exampleId'
}
];

const stratifierResults: StratifierResult[] = [
{
strataCode: 'example-strata-id',
result: true,
strataId: 'example-strata-id'
}
];

const newStratifierResults = DetailedResultsBuilder.handleStratificationValues(
populationGroup,
populationResults,
stratifierResults
);

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

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

const populationResults: PopulationResult[] = [
{
populationType: PopulationType.IPP,
criteriaExpression: 'Initial Population',
result: false,
populationId: 'exampleId'
}
];

const stratifierResults: StratifierResult[] = [
{
strataCode: 'example-strata-id',
result: true,
strataId: 'example-strata-id'
}
];

const newStratifierResults = DetailedResultsBuilder.handleStratificationValues(
populationGroup,
populationResults,
stratifierResults
);

expect(newStratifierResults).toBeDefined();
expect(newStratifierResults).toHaveLength(1);
expect(newStratifierResults).toEqual(
expect.arrayContaining([
expect.objectContaining({
strataId: 'example-strata-id',
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