From 982d9738521fe316706d2762b5726e10a4c177a7 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Mon, 18 Nov 2024 13:23:53 -0600 Subject: [PATCH] MAT-7915 filtering out invalid strat population values --- src/api/CalculationService.ts | 45 ++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/api/CalculationService.ts b/src/api/CalculationService.ts index 88f75062..ee1ee08f 100644 --- a/src/api/CalculationService.ts +++ b/src/api/CalculationService.ts @@ -12,6 +12,7 @@ import { Population, PopulationExpectedValue, TestCase, + StratificationExpectedValue, } from "@madie/madie-models"; import { Bundle, ValueSet } from "fhir/r4"; import * as _ from "lodash"; @@ -290,7 +291,8 @@ export class CalculationService { return results; } - isGroupPass(groupPopulation: GroupPopulation) { + isGroupPass(groupPopulation: GroupPopulation, measureGroup: Group) { + // console.log("isGroupPass: for group: "+measureGroup.id); let groupPass = true; if (groupPopulation) { const patientBased = @@ -313,12 +315,20 @@ export class CalculationService { // verify stratification & stratified populations passing if they exist if (groupPopulation.stratificationValues) { let validStratPopValues = []; - groupPopulation.stratificationValues.forEach((stratValues) => { - const filtered = stratValues.populationValues?.filter( - (populationValue) => populationValue.expected !== null - ); - validStratPopValues.push(filtered); - }); + groupPopulation.stratificationValues.forEach( + (stratValues: StratificationExpectedValue) => { + stratValues.populationValues?.forEach((popValue) => { + const validPopValues = this.getValidStratPopulationValues( + measureGroup, + stratValues.id, + popValue + ); + if (validPopValues && validPopValues.length > 0) { + validStratPopValues.push(validPopValues); + } + }); + } + ); return validStratPopValues.every((strata) => { // verify stratified populations passing return strata.every((population) => @@ -334,6 +344,24 @@ export class CalculationService { return groupPass; } + getValidStratPopulationValues( + measureGroup: Group, + stratId: string, + popValue: PopulationExpectedValue + ): PopulationExpectedValue[] { + let valiePopValue = []; + measureGroup.stratifications?.forEach((strat) => { + if (strat.id === stratId) { + strat.associations?.forEach((association) => { + if (association === popValue.name) { + valiePopValue.push(popValue); + } + }); + } + }); + return valiePopValue; + } + processTestCaseResults( testCase: TestCase, measureGroups: Group[], @@ -470,7 +498,8 @@ export class CalculationService { }); }); // need to do work here. - allGroupsPass = allGroupsPass && this.isGroupPass(tcGroupPopulation); + allGroupsPass = + allGroupsPass && this.isGroupPass(tcGroupPopulation, measureGroup); } updatedTestCase.executionStatus = allGroupsPass ? ExecutionStatusType.PASS