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

Stratified report fix #315

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/calculation/DetailedResultsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
// loop over stratifications and collect episode results for the strata
let strataIndex = 1;
populationGroup.stratifier?.forEach(strata => {
const strataCode = strata.code?.text ?? `strata-${strataIndex++}`;
const strataCode = strata.code?.text ?? strata.id ?? `strata-${strataIndex++}`;

Check warning on line 465 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 (strata.criteria?.expression) {
const rawEpisodeResults = patientResults[strata.criteria?.expression];
createOrSetValueOfEpisodes(
Expand Down Expand Up @@ -523,47 +523,47 @@
const episodeResults = episodeResultsSet.find(
episodeResults => episodeResults.episodeId === episodeResource.id.value
);
if (episodeResults) {
// set population value
if (populationType) {
setResult(populationType, true, episodeResults.populationResults, population?.criteria.expression);

// set strata value
} else if (strataCode) {
if (episodeResults.stratifierResults) {
const strataResult = episodeResults.stratifierResults.find(strataResult => {
return strataResult.strataCode === strataCode;
});
if (strataResult) {
strataResult.result = true;
if (strataId) {
strataResult.strataId = strataId;
}
}
}
}

// else create a new episode using the list of all popcodes for the population
} else {
const newEpisodeResults: EpisodeResults = {
episodeId: episodeResource.id.value,
populationResults: []
};
populationGroup.population?.forEach(population => {
const newPopulationResult: PopulationResult = {
populationType: <PopulationType>MeasureBundleHelpers.codeableConceptToPopulationType(population.code),
criteriaExpression: population.criteria.expression,
result: false
};
DetailedResultsHelpers.addIdsToPopulationResult(newPopulationResult, population);
newEpisodeResults.populationResults.push(newPopulationResult);
});

if (populationGroup.stratifier) {
newEpisodeResults.stratifierResults = [];
let strataIndex = 1;
populationGroup.stratifier?.forEach(strata => {
const newStrataCode = strata.code?.text ?? `strata-${strataIndex++}`;
const newStrataCode = strata.code?.text ?? strata.id ?? `strata-${strataIndex++}`;

Check warning on line 566 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 566 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 566 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
newEpisodeResults.stratifierResults?.push({
...(strataId ? { strataId } : {}),
strataCode: newStrataCode,
Expand Down
6 changes: 3 additions & 3 deletions src/calculation/MeasureReportBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default class MeasureReportBuilder<T extends PopulationGroupResult> exten
// or s.id (newer measures)
const strata: MeasureReportGroupStratifier | undefined =
group.stratifier?.find(s => s.code && s.code[0]?.text === stratResults.strataCode) ||
group.stratifier?.find(s => s.id === stratResults.strataCode);
group.stratifier?.find(s => s.id === stratResults.strataCode); // strataCode may have an id value if code did not originally exist
const stratum = strata?.stratum?.[0];
if (stratum) {
er.populationResults?.forEach(pr => {
Expand Down Expand Up @@ -647,9 +647,9 @@ export default class MeasureReportBuilder<T extends PopulationGroupResult> exten
options: CalculationOptions
): fhir4.MeasureReport[] {
const reports: fhir4.MeasureReport[] = [];
const measure = extractMeasureFromBundle(measureBundle);
const builder = new MeasureReportBuilder(measure, options);
lmd59 marked this conversation as resolved.
Show resolved Hide resolved
executionResults.forEach(result => {
const measure = extractMeasureFromBundle(measureBundle);
const builder = new MeasureReportBuilder(measure, options);
builder.addPatientResults(result);
reports.push(builder.getReport());
});
Expand Down
74 changes: 74 additions & 0 deletions test/unit/DetailedResultsBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,80 @@ describe('DetailedResultsBuilder', () => {
])
);
});

test('it should add stratificationIds to stratification results of an individual episode for episode-based measure', () => {
const episodeMeasureStrat: fhir4.Measure = {
resourceType: 'Measure',
status: 'unknown',
extension: [
{
url: 'http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-populationBasis',
valueCode: 'Encounter'
}
],
group: [
{
population: [
{
id: 'example-population-id',
code: {
coding: [
{
system: 'http://terminology.hl7.org/CodeSystem/measure-population',
code: 'initial-population'
}
]
},
criteria: {
expression: 'ipp',
language: 'text/cql'
}
}
],
stratifier: [
{
id: 'example-stratifier-id',
criteria: {
language: 'text/cql-identifier',
expression: 'Strat1'
}
}
]
}
]
};

const group = (episodeMeasureStrat.group as [fhir4.MeasureGroup])[0];

const statementResults: StatementResults = {
ipp: [
{
id: {
value: 'example-encounter'
}
}
]
};

const { episodeResults } = DetailedResultsBuilder.createPopulationValues(
episodeMeasureStrat,
group,
statementResults
);

expect(episodeResults).toBeDefined();
expect(episodeResults).toHaveLength(1);

const episodeStratifierResults = (episodeResults as EpisodeResults[])[0].stratifierResults;

expect(episodeStratifierResults).toEqual(
expect.arrayContaining([
expect.objectContaining({
strataCode: 'example-stratifier-id'
})
])
);
});
});

describe('ELM JSON Function', () => {
Expand Down
159 changes: 159 additions & 0 deletions test/unit/MeasureReportBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const patient2Id = '08fc9439-b7ff-4309-b409-4d143388594c';

const simpleMeasure = getJSONFixture('measure/simple-measure.json') as fhir4.Measure;
const propWithStratMeasure = getJSONFixture('measure/proportion-measure-with-stratifiers.json') as fhir4.Measure;
const episodeWithStratMeasure = getJSONFixture('measure/episode-measure-with-stratifiers.json') as fhir4.Measure;
const ratioMeasure = getJSONFixture('measure/ratio-measure.json') as fhir4.Measure;
const cvMeasure = getJSONFixture('measure/cv-measure.json') as fhir4.Measure;
const cvMeasureScoringOnGroup = getJSONFixture('measure/group-score-cv-measure.json');
Expand All @@ -43,6 +44,7 @@ function buildTestMeasureBundle(measure: fhir4.Measure): fhir4.Bundle {
}
const simpleMeasureBundle = buildTestMeasureBundle(simpleMeasure);
const propWithStratMeasureBundle = buildTestMeasureBundle(propWithStratMeasure);
const episodeWithStratMeasureBundle = buildTestMeasureBundle(episodeWithStratMeasure);
const ratioMeasureBundle = buildTestMeasureBundle(ratioMeasure);
const cvMeasureBundle = buildTestMeasureBundle(cvMeasure);

Expand Down Expand Up @@ -293,6 +295,120 @@ const propWithStratExecutionResults: ExecutionResult<DetailedPopulationGroupResu
}
];

const episodeWithStratExecutionResults: ExecutionResult<DetailedPopulationGroupResult>[] = [
{
patientId: patient1Id,
detailedResults: [
{
groupId: 'group-1',
statementResults: [],
populationResults: [
{
populationType: PopulationType.NUMER,
criteriaExpression: 'Numerator',
result: false
},
{
populationType: PopulationType.DENOM,
criteriaExpression: 'Denominator',
result: true
},
{
populationType: PopulationType.IPP,
criteriaExpression: 'Initial Population',
result: true
},
{
populationType: PopulationType.DENEX,
criteriaExpression: 'Denominator Exclusion',
result: false
}
],
stratifierResults: [
{
strataCode: '93f5f1c7-8638-40a4-a596-8b5831599209',
result: false,
appliesResult: false,
strataId: '93f5f1c7-8638-40a4-a596-8b5831599209'
},
{
strataCode: '5baf37c7-8887-4576-837e-ea20a8938282',
result: false,
appliesResult: false,
strataId: '5baf37c7-8887-4576-837e-ea20a8938282'
},
{
strataCode: '125b3d95-2d00-455f-8a6e-d53614a2a50e',
result: false,
appliesResult: false,
strataId: '125b3d95-2d00-455f-8a6e-d53614a2a50e'
},
{
strataCode: 'c06647b9-e134-4189-858d-80cee23c0f8d',
result: false,
appliesResult: false,
strataId: 'c06647b9-e134-4189-858d-80cee23c0f8d'
}
],
episodeResults: [
{
episodeId: '5ca62964b8484628b8de1f2b',
populationResults: [
{
populationType: PopulationType.NUMER,
criteriaExpression: 'Numerator',
result: false
},
{
populationType: PopulationType.DENOM,
criteriaExpression: 'Denominator',
result: true
},
{
populationType: PopulationType.IPP,
criteriaExpression: 'Initial Population',
result: true
},
{
populationType: PopulationType.DENEX,
criteriaExpression: 'Denominator Exclusion',
result: false
}
],
stratifierResults: [
{
strataCode: '93f5f1c7-8638-40a4-a596-8b5831599209',
result: false,
appliesResult: false,
strataId: '93f5f1c7-8638-40a4-a596-8b5831599209'
},
{
strataCode: '5baf37c7-8887-4576-837e-ea20a8938282',
result: false,
appliesResult: false,
strataId: '5baf37c7-8887-4576-837e-ea20a8938282'
},
{
strataCode: '125b3d95-2d00-455f-8a6e-d53614a2a50e',
result: false,
appliesResult: false,
strataId: '125b3d95-2d00-455f-8a6e-d53614a2a50e'
},
{
strataCode: 'c06647b9-e134-4189-858d-80cee23c0f8d',
result: false,
appliesResult: false,
strataId: 'c06647b9-e134-4189-858d-80cee23c0f8d'
}
]
}
],
html: 'example-html'
}
]
}
];

const calculationOptions: CalculationOptions = {
measurementPeriodStart: '2021-01-01',
measurementPeriodEnd: '2021-12-31',
Expand Down Expand Up @@ -490,6 +606,49 @@ describe('MeasureReportBuilder Static', () => {
});
});

describe('Measure Report from Episode Measure with stratifiers', () => {
let measureReports: fhir4.MeasureReport[];
beforeAll(() => {
measureReports = MeasureReportBuilder.buildMeasureReports(
episodeWithStratMeasureBundle,
episodeWithStratExecutionResults,
calculationOptions
);
});

test('should generate 1 result', () => {
lmd59 marked this conversation as resolved.
Show resolved Hide resolved
expect(measureReports).toBeDefined();
expect(measureReports).toHaveLength(1);
});

test('should contain proper stratifierResults', () => {
const [mr] = measureReports;

expect(mr.group).toBeDefined();
expect(mr.group).toHaveLength(1);

const [group] = mr.group!;
const result = episodeWithStratExecutionResults[0].detailedResults?.[0];

expect(group.id).toEqual(result!.groupId);
expect(group.measureScore).toBeDefined();
expect(group.population).toBeDefined();

result!.episodeResults![0].populationResults!.forEach(pr => {
const populationResult = group.population?.find(p => p.code?.coding?.[0].code === pr.populationType);
expect(populationResult).toBeDefined();
expect(populationResult!.count).toEqual(pr.result === true ? 1 : 0);
});

result!.episodeResults![0].stratifierResults!.forEach(sr => {
const stratifierResult = group.stratifier?.find(s => s.id === sr.strataId);
expect(stratifierResult).toBeDefined();
expect(stratifierResult!.stratum?.[0].population?.length).toEqual(4);
expect(stratifierResult!.stratum?.[0].measureScore?.value).toEqual(0);
});
});
});

describe('Ratio Measure Report', () => {
let measureReports: fhir4.MeasureReport[];
beforeAll(() => {
Expand Down
Loading
Loading