From 28972c37b29e329408471cb6ddc2489fb78bdd6e Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Tue, 12 Nov 2024 15:06:50 -0500 Subject: [PATCH 1/7] MAT-5932 add stratification to QI Core testcase export for patient basis measures --- .../services/TestCaseBundleService.java | 74 +++++++++++++------ .../utils/FhirResourceHelpers.java | 58 +++++++++++++-- 2 files changed, 103 insertions(+), 29 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java index 84aef4ca..5b9f1ca5 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -23,19 +23,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import gov.cms.madie.models.dto.TestCaseExportMetaData; +import gov.cms.madie.models.measure.TestCaseStratificationValue; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; -import org.hl7.fhir.r4.model.BooleanType; -import org.hl7.fhir.r4.model.Bundle; - -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.MarkdownType; -import org.hl7.fhir.r4.model.MeasureReport; -import org.hl7.fhir.r4.model.Meta; -import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r4.model.Resource; -import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.*; + import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestClientException; @@ -259,7 +251,8 @@ private List buildMeasureReportGroupC String populationDisplay = testCasePopulationValue.getName().getDisplay(); int expectedValue = - getExpectedValue(testCasePopulationValue.getExpected()); + FhirResourceHelpers.getExpectedValue( + testCasePopulationValue.getExpected()); return (new MeasureReport.MeasureReportGroupPopulationComponent()) .setCode( FhirResourceHelpers.buildCodeableConcept( @@ -271,23 +264,56 @@ private List buildMeasureReportGroupC .collect(Collectors.toList()); measureReportGroupComponent.setPopulation(measureReportGroupPopulationComponents); } + + if (population.getStratificationValues() != null) { + var measureReportGroupStratifierComponents = + population.getStratificationValues().stream() + .map( + testCaseStratificationValue -> { + + // code + List code = new ArrayList(); + code.add( + new CodeableConcept() + .setText(testCaseStratificationValue.getName())); + + return (new MeasureReport.MeasureReportGroupStratifierComponent()) + .setCode(code) + .setStratum(buildStratum(testCaseStratificationValue)); + }) + .collect(Collectors.toList()); + measureReportGroupComponent.setStratifier(measureReportGroupStratifierComponents); + } return measureReportGroupComponent; }) .collect(Collectors.toList()); } - /** - * @param expectedValue expected value for a population, can be a string or boolean - * @return an equivalent integer - */ - private int getExpectedValue(Object expectedValue) { - if (expectedValue == null || StringUtils.isBlank(expectedValue.toString())) { - return 0; - } else if (expectedValue instanceof Boolean) { - return (Boolean) expectedValue ? 1 : 0; - } else { - return Integer.parseInt(expectedValue.toString()); - } + private List buildStratum( + TestCaseStratificationValue testCaseStratificationValue) { + + // stratum + List stratum = + new ArrayList(); + + MeasureReport.StratifierGroupComponent stratifierGroupComponent = + new MeasureReport.StratifierGroupComponent(); + + // when value is true + stratifierGroupComponent.setValue(new CodeableConcept().setText("true")); + stratifierGroupComponent.setPopulation( + FhirResourceHelpers.buildStratum(testCaseStratificationValue, true)); + stratum.add(stratifierGroupComponent); + + // when value is false (i.e., inverted ) + MeasureReport.StratifierGroupComponent stratifierGroupComponentForInvertedValue = + new MeasureReport.StratifierGroupComponent(); + stratifierGroupComponentForInvertedValue.setValue(new CodeableConcept().setText("false")); + stratifierGroupComponentForInvertedValue.setPopulation( + FhirResourceHelpers.buildStratum(testCaseStratificationValue, false)); + stratum.add(stratifierGroupComponentForInvertedValue); + + return stratum; } /** diff --git a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java index c56b1dd8..5410f2d3 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java @@ -1,16 +1,17 @@ package gov.cms.madie.madiefhirservice.utils; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.Period; -import org.hl7.fhir.r4.model.Resource; +import gov.cms.madie.madiefhirservice.constants.UriConstants; +import gov.cms.madie.models.measure.TestCaseStratificationValue; +import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.r4.model.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; @Component public class FhirResourceHelpers { @@ -62,6 +63,53 @@ public static CodeableConcept buildCodeableConcept(String code, String system, S return codeableConcept; } + /** + * @param expectedValue expected value for a population, can be a string or boolean + * @return an equivalent integer + */ + public static int getExpectedValue(Object expectedValue) { + if (expectedValue == null || StringUtils.isBlank(expectedValue.toString())) { + return 0; + } else if (expectedValue instanceof Boolean) { + return (Boolean) expectedValue ? 1 : 0; + } else { + return Integer.parseInt(expectedValue.toString()); + } + } + + public static int getExpectedInverseValue(int expectedValue) { + if (expectedValue == 0) { + return 1; + } + return 0; + } + + public static List buildStratum( + TestCaseStratificationValue testCaseStratificationValue, boolean valueIndex) { + var measureTestCaseStratificationComponents = + testCaseStratificationValue.getPopulationValues().stream() + .map( + populationValue -> { + MeasureReport.StratifierGroupPopulationComponent + stratifierGroupPopulationComponent = + new MeasureReport.StratifierGroupPopulationComponent(); + String populationCode = populationValue.getName().toCode(); + String populationDisplay = populationValue.getName().getDisplay(); + + stratifierGroupPopulationComponent.setId(populationValue.getId()); + stratifierGroupPopulationComponent.setCode( + buildCodeableConcept( + populationCode, UriConstants.POPULATION_SYSTEM_URI, populationDisplay)); + stratifierGroupPopulationComponent.setCount( + valueIndex == false + ? getExpectedInverseValue(getExpectedValue(populationValue.getExpected())) + : getExpectedValue(populationValue.getExpected())); + return stratifierGroupPopulationComponent; + }) + .collect(Collectors.toList()); + return measureTestCaseStratificationComponents; + } + public static Coding buildCoding(String code, String system, String display) { return new Coding().setCode(code).setSystem(system).setDisplay(display); } From 436adaec74c2feabee4c3a861cc2d5cbbd777661 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Tue, 12 Nov 2024 15:18:06 -0500 Subject: [PATCH 2/7] MAT-5932 refactored code --- .../madie/madiefhirservice/utils/FhirResourceHelpers.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java index 5410f2d3..ac3fcab2 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java @@ -100,10 +100,12 @@ public static List buildStratu stratifierGroupPopulationComponent.setCode( buildCodeableConcept( populationCode, UriConstants.POPULATION_SYSTEM_URI, populationDisplay)); + stratifierGroupPopulationComponent.setCount( - valueIndex == false - ? getExpectedInverseValue(getExpectedValue(populationValue.getExpected())) - : getExpectedValue(populationValue.getExpected())); + valueIndex + ? getExpectedValue(populationValue.getExpected()) + : getExpectedInverseValue( + getExpectedValue(populationValue.getExpected()))); return stratifierGroupPopulationComponent; }) .collect(Collectors.toList()); From b141c71f28d5d616769453f576c6a2804db2400d Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Fri, 15 Nov 2024 10:01:05 -0500 Subject: [PATCH 3/7] MAT-5932 added straticiation definition to the exported file --- .../services/TestCaseBundleService.java | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java index 5b9f1ca5..3dbefbc2 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -23,11 +23,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import gov.cms.madie.models.dto.TestCaseExportMetaData; -import gov.cms.madie.models.measure.TestCaseStratificationValue; +import gov.cms.madie.models.measure.*; +import gov.cms.madie.models.measure.Group; +import gov.cms.madie.models.measure.Measure; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.model.Reference; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestClientException; @@ -43,8 +46,6 @@ import gov.cms.madie.madiefhirservice.utils.FhirResourceHelpers; import gov.cms.madie.models.common.BundleType; import gov.cms.madie.models.dto.ExportDTO; -import gov.cms.madie.models.measure.Measure; -import gov.cms.madie.models.measure.TestCase; import gov.cms.madie.packaging.utils.PackagingUtility; import gov.cms.madie.packaging.utils.PackagingUtilityFactory; import lombok.RequiredArgsConstructor; @@ -171,7 +172,7 @@ private MeasureReport buildMeasureReport( getUTCDates(measure.getMeasurementPeriodStart()), getUTCDates(measure.getMeasurementPeriodEnd()))); - measureReport.setGroup(buildMeasureReportGroupComponents(testCase)); + measureReport.setGroup(buildMeasureReportGroupComponents(testCase, measure.getGroups())); measureReport.setEvaluatedResource(buildEvaluatedResource(testCaseBundle)); return measureReport; } @@ -233,7 +234,7 @@ private List buildModifierExtension() { } private List buildMeasureReportGroupComponents( - TestCase testCase) { + TestCase testCase, List groups) { if (CollectionUtils.isEmpty(testCase.getGroupPopulations())) { return List.of(); } @@ -270,16 +271,21 @@ private List buildMeasureReportGroupC population.getStratificationValues().stream() .map( testCaseStratificationValue -> { - - // code List code = new ArrayList(); code.add( new CodeableConcept() - .setText(testCaseStratificationValue.getName())); - - return (new MeasureReport.MeasureReportGroupStratifierComponent()) - .setCode(code) - .setStratum(buildStratum(testCaseStratificationValue)); + .setText( + getStratificationDefinition( + groups, + population.getGroupId(), + testCaseStratificationValue.getId()))); + + var stratifierComponent = + new MeasureReport.MeasureReportGroupStratifierComponent() + .setCode(code) + .setStratum(buildStratum(testCaseStratificationValue)); + stratifierComponent.setId(testCaseStratificationValue.getId()); + return stratifierComponent; }) .collect(Collectors.toList()); measureReportGroupComponent.setStratifier(measureReportGroupStratifierComponents); @@ -289,6 +295,23 @@ private List buildMeasureReportGroupC .collect(Collectors.toList()); } + private String getStratificationDefinition( + List groups, String populationId, String testCaseStratificationId) { + Group filteredGroup = + groups.stream() + .filter(group -> group.getId().equals(populationId)) + .findFirst() + .orElse(null); + if (filteredGroup != null) { + return filteredGroup.getStratifications().stream() + .filter(stratification -> stratification.getId().equals(testCaseStratificationId)) + .map(selectedStratification -> selectedStratification.getCqlDefinition()) + .findFirst() + .orElse(null); + } + return null; + } + private List buildStratum( TestCaseStratificationValue testCaseStratificationValue) { From a7e97d5f26d44798b711d2e64e8ac4be0aa9b914 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Fri, 15 Nov 2024 10:50:22 -0500 Subject: [PATCH 4/7] MAT-5932 refactored code to move stratifications into seperate functions --- .../services/TestCaseBundleService.java | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java index 3dbefbc2..6592115d 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -242,7 +242,6 @@ private List buildMeasureReportGroupC .map( population -> { var measureReportGroupComponent = new MeasureReport.MeasureReportGroupComponent(); - if (population.getPopulationValues() != null) { var measureReportGroupPopulationComponents = population.getPopulationValues().stream() @@ -266,35 +265,41 @@ private List buildMeasureReportGroupC measureReportGroupComponent.setPopulation(measureReportGroupPopulationComponents); } - if (population.getStratificationValues() != null) { - var measureReportGroupStratifierComponents = - population.getStratificationValues().stream() - .map( - testCaseStratificationValue -> { - List code = new ArrayList(); - code.add( - new CodeableConcept() - .setText( - getStratificationDefinition( - groups, - population.getGroupId(), - testCaseStratificationValue.getId()))); - - var stratifierComponent = - new MeasureReport.MeasureReportGroupStratifierComponent() - .setCode(code) - .setStratum(buildStratum(testCaseStratificationValue)); - stratifierComponent.setId(testCaseStratificationValue.getId()); - return stratifierComponent; - }) - .collect(Collectors.toList()); - measureReportGroupComponent.setStratifier(measureReportGroupStratifierComponents); + // adding stratification for patient basis + if (population.getStratificationValues() != null + && StringUtils.equalsIgnoreCase("boolean", population.getPopulationBasis())) { + measureReportGroupComponent.setStratifier( + buildGroupStratifierComponentForPatientBasisMeasures( + population, groups, population.getGroupId())); } return measureReportGroupComponent; }) .collect(Collectors.toList()); } + private List + buildGroupStratifierComponentForPatientBasisMeasures( + TestCaseGroupPopulation population, List groups, String populationGroupId) { + return population.getStratificationValues().stream() + .map( + testCaseStratificationValue -> { + List code = new ArrayList(); + code.add( + new CodeableConcept() + .setText( + getStratificationDefinition( + groups, populationGroupId, testCaseStratificationValue.getId()))); + + var stratifierComponent = + new MeasureReport.MeasureReportGroupStratifierComponent() + .setCode(code) + .setStratum(buildStratum(testCaseStratificationValue)); + stratifierComponent.setId(testCaseStratificationValue.getId()); + return stratifierComponent; + }) + .collect(Collectors.toList()); + } + private String getStratificationDefinition( List groups, String populationId, String testCaseStratificationId) { Group filteredGroup = From 99f1204ad8e4df319a8ef4b38881c30b6a251263 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Mon, 18 Nov 2024 11:20:10 -0500 Subject: [PATCH 5/7] MAT-5932 refactored code to add stratifications for non patient based measures --- .../services/TestCaseBundleService.java | 79 ++++++++++++------- .../utils/FhirResourceHelpers.java | 16 ++-- 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java index 6592115d..3c9d1c87 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -266,34 +266,46 @@ private List buildMeasureReportGroupC } // adding stratification for patient basis - if (population.getStratificationValues() != null - && StringUtils.equalsIgnoreCase("boolean", population.getPopulationBasis())) { - measureReportGroupComponent.setStratifier( - buildGroupStratifierComponentForPatientBasisMeasures( - population, groups, population.getGroupId())); + if (population.getStratificationValues() != null) { + if (StringUtils.equalsIgnoreCase("boolean", population.getPopulationBasis())) { + measureReportGroupComponent.setStratifier( + buildGroupStratifierComponent( + population, groups, population.getGroupId(), true)); + } else { + measureReportGroupComponent.setStratifier( + buildGroupStratifierComponent( + population, groups, population.getGroupId(), false)); + } } return measureReportGroupComponent; }) .collect(Collectors.toList()); } - private List - buildGroupStratifierComponentForPatientBasisMeasures( - TestCaseGroupPopulation population, List groups, String populationGroupId) { + private List buildGroupStratifierComponent( + TestCaseGroupPopulation population, + List groups, + String populationGroupId, + boolean isPatientBased) { return population.getStratificationValues().stream() .map( testCaseStratificationValue -> { List code = new ArrayList(); - code.add( - new CodeableConcept() - .setText( - getStratificationDefinition( - groups, populationGroupId, testCaseStratificationValue.getId()))); + var codeText = + isPatientBased + ? getStratificationDefinition( + groups, populationGroupId, testCaseStratificationValue.getId()) + : testCaseStratificationValue.getName(); + code.add(new CodeableConcept().setText(codeText)); var stratifierComponent = new MeasureReport.MeasureReportGroupStratifierComponent() .setCode(code) - .setStratum(buildStratum(testCaseStratificationValue)); + .setStratum( + buildStratum( + testCaseStratificationValue, + isPatientBased, + testCaseStratificationValue.getName())); stratifierComponent.setId(testCaseStratificationValue.getId()); return stratifierComponent; }) @@ -318,7 +330,9 @@ private String getStratificationDefinition( } private List buildStratum( - TestCaseStratificationValue testCaseStratificationValue) { + TestCaseStratificationValue testCaseStratificationValue, + boolean isPatientBased, + String testCaseStratificationName) { // stratum List stratum = @@ -327,20 +341,27 @@ private List buildStratum( MeasureReport.StratifierGroupComponent stratifierGroupComponent = new MeasureReport.StratifierGroupComponent(); - // when value is true - stratifierGroupComponent.setValue(new CodeableConcept().setText("true")); - stratifierGroupComponent.setPopulation( - FhirResourceHelpers.buildStratum(testCaseStratificationValue, true)); - stratum.add(stratifierGroupComponent); - - // when value is false (i.e., inverted ) - MeasureReport.StratifierGroupComponent stratifierGroupComponentForInvertedValue = - new MeasureReport.StratifierGroupComponent(); - stratifierGroupComponentForInvertedValue.setValue(new CodeableConcept().setText("false")); - stratifierGroupComponentForInvertedValue.setPopulation( - FhirResourceHelpers.buildStratum(testCaseStratificationValue, false)); - stratum.add(stratifierGroupComponentForInvertedValue); - + if (isPatientBased) { + // when value is true + stratifierGroupComponent.setValue(new CodeableConcept().setText("true")); + stratifierGroupComponent.setPopulation( + FhirResourceHelpers.buildStratumPopulation(testCaseStratificationValue, true, true)); + stratum.add(stratifierGroupComponent); + + // when value is false (i.e., inverted ) + MeasureReport.StratifierGroupComponent stratifierGroupComponentForInvertedValue = + new MeasureReport.StratifierGroupComponent(); + stratifierGroupComponentForInvertedValue.setValue(new CodeableConcept().setText("false")); + stratifierGroupComponentForInvertedValue.setPopulation( + FhirResourceHelpers.buildStratumPopulation(testCaseStratificationValue, false, true)); + stratum.add(stratifierGroupComponentForInvertedValue); + } else { + // Non-patient based measures + stratifierGroupComponent.setValue(new CodeableConcept().setText(testCaseStratificationName)); + stratifierGroupComponent.setPopulation( + FhirResourceHelpers.buildStratumPopulation(testCaseStratificationValue, true, false)); + stratum.add(stratifierGroupComponent); + } return stratum; } diff --git a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java index ac3fcab2..92a52d8f 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java @@ -84,8 +84,10 @@ public static int getExpectedInverseValue(int expectedValue) { return 0; } - public static List buildStratum( - TestCaseStratificationValue testCaseStratificationValue, boolean valueIndex) { + public static List buildStratumPopulation( + TestCaseStratificationValue testCaseStratificationValue, + boolean valueIndex, + boolean isPatientBased) { var measureTestCaseStratificationComponents = testCaseStratificationValue.getPopulationValues().stream() .map( @@ -102,10 +104,12 @@ public static List buildStratu populationCode, UriConstants.POPULATION_SYSTEM_URI, populationDisplay)); stratifierGroupPopulationComponent.setCount( - valueIndex - ? getExpectedValue(populationValue.getExpected()) - : getExpectedInverseValue( - getExpectedValue(populationValue.getExpected()))); + isPatientBased + ? (valueIndex + ? getExpectedValue(populationValue.getExpected()) + : getExpectedInverseValue( + getExpectedValue(populationValue.getExpected()))) + : Integer.parseInt(populationValue.getExpected().toString())); return stratifierGroupPopulationComponent; }) .collect(Collectors.toList()); From 5c40754bd068c6bf15dceb4c7bc2d9b126a8be73 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Mon, 18 Nov 2024 12:10:42 -0500 Subject: [PATCH 6/7] MAT-5932 refactored code to add meaasureScore and groupIds --- .../services/TestCaseBundleService.java | 35 +++++++++++-------- .../utils/FhirResourceHelpers.java | 6 ++-- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java index 3c9d1c87..fc37c86b 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -242,29 +242,36 @@ private List buildMeasureReportGroupC .map( population -> { var measureReportGroupComponent = new MeasureReport.MeasureReportGroupComponent(); + measureReportGroupComponent.setId(population.getGroupId()); + // adding populations if (population.getPopulationValues() != null) { var measureReportGroupPopulationComponents = population.getPopulationValues().stream() .map( testCasePopulationValue -> { - String populationCode = testCasePopulationValue.getName().toCode(); - String populationDisplay = - testCasePopulationValue.getName().getDisplay(); - int expectedValue = - FhirResourceHelpers.getExpectedValue( - testCasePopulationValue.getExpected()); - return (new MeasureReport.MeasureReportGroupPopulationComponent()) - .setCode( - FhirResourceHelpers.buildCodeableConcept( - populationCode, - UriConstants.POPULATION_SYSTEM_URI, - populationDisplay)) - .setCount(expectedValue); + var groupComponent = + (new MeasureReport.MeasureReportGroupPopulationComponent()) + .setCode( + FhirResourceHelpers.buildCodeableConcept( + testCasePopulationValue.getName().toCode(), + UriConstants.POPULATION_SYSTEM_URI, + testCasePopulationValue.getName().getDisplay())) + .setCount( + FhirResourceHelpers.getExpectedValue( + testCasePopulationValue.getExpected())); + groupComponent.setId(testCasePopulationValue.getId()); + return groupComponent; }) .collect(Collectors.toList()); measureReportGroupComponent.setPopulation(measureReportGroupPopulationComponents); } - + // adding measure score + measureReportGroupComponent.setMeasureScore( + new Quantity() + .setValue( + StringUtils.equalsIgnoreCase("boolean", population.getPopulationBasis()) + ? 1.0 + : 0)); // adding stratification for patient basis if (population.getStratificationValues() != null) { if (StringUtils.equalsIgnoreCase("boolean", population.getPopulationBasis())) { diff --git a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java index 92a52d8f..5f939b35 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java @@ -95,13 +95,13 @@ public static List buildStratu MeasureReport.StratifierGroupPopulationComponent stratifierGroupPopulationComponent = new MeasureReport.StratifierGroupPopulationComponent(); - String populationCode = populationValue.getName().toCode(); - String populationDisplay = populationValue.getName().getDisplay(); stratifierGroupPopulationComponent.setId(populationValue.getId()); stratifierGroupPopulationComponent.setCode( buildCodeableConcept( - populationCode, UriConstants.POPULATION_SYSTEM_URI, populationDisplay)); + populationValue.getName().toCode(), + UriConstants.POPULATION_SYSTEM_URI, + populationValue.getName().getDisplay())); stratifierGroupPopulationComponent.setCount( isPatientBased From c101aa2ab278d45e332f3bc22623646227e02365 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Mon, 18 Nov 2024 13:10:05 -0500 Subject: [PATCH 7/7] MAT-5932 added test cases --- .../services/TestCaseBundleService.java | 5 +- .../utils/FhirResourceHelpers.java | 2 +- .../utils/FhirResourceHelpersTest.java | 139 ++++++++++++++++++ 3 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/test/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpersTest.java diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java index fc37c86b..053fc8ee 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -280,8 +280,7 @@ private List buildMeasureReportGroupC population, groups, population.getGroupId(), true)); } else { measureReportGroupComponent.setStratifier( - buildGroupStratifierComponent( - population, groups, population.getGroupId(), false)); + buildGroupStratifierComponent(population, null, null, false)); } } return measureReportGroupComponent; @@ -366,7 +365,7 @@ private List buildStratum( // Non-patient based measures stratifierGroupComponent.setValue(new CodeableConcept().setText(testCaseStratificationName)); stratifierGroupComponent.setPopulation( - FhirResourceHelpers.buildStratumPopulation(testCaseStratificationValue, true, false)); + FhirResourceHelpers.buildStratumPopulation(testCaseStratificationValue, null, false)); stratum.add(stratifierGroupComponent); } return stratum; diff --git a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java index 5f939b35..21a1f327 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java @@ -86,7 +86,7 @@ public static int getExpectedInverseValue(int expectedValue) { public static List buildStratumPopulation( TestCaseStratificationValue testCaseStratificationValue, - boolean valueIndex, + Boolean valueIndex, boolean isPatientBased) { var measureTestCaseStratificationComponents = testCaseStratificationValue.getPopulationValues().stream() diff --git a/src/test/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpersTest.java b/src/test/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpersTest.java new file mode 100644 index 00000000..d1f56f7c --- /dev/null +++ b/src/test/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpersTest.java @@ -0,0 +1,139 @@ +package gov.cms.madie.madiefhirservice.utils; + +import gov.cms.madie.models.measure.PopulationType; +import gov.cms.madie.models.measure.TestCasePopulationValue; +import gov.cms.madie.models.measure.TestCaseStratificationValue; +import org.hl7.fhir.r4.model.MeasureReport; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class FhirResourceHelpersTest { + @Test + void testexpectedInverseValue() { + assertEquals(1, FhirResourceHelpers.getExpectedInverseValue(0)); + assertEquals(0, FhirResourceHelpers.getExpectedInverseValue(1)); + } + + @Test + void testBuildStratumPopulationForValueIndexOfTrue() { + TestCaseStratificationValue stratValue1 = + TestCaseStratificationValue.builder().name("Strata-1").expected(1).build(); + stratValue1.setPopulationValues( + List.of( + TestCasePopulationValue.builder() + .id("1") + .name(PopulationType.INITIAL_POPULATION) + .expected(1) + .build(), + TestCasePopulationValue.builder() + .id("2") + .name(PopulationType.DENOMINATOR) + .expected(1) + .build(), + TestCasePopulationValue.builder() + .id("3") + .name(PopulationType.NUMERATOR) + .expected(0) + .build())); + + List stratifierGroupPopulationComponents = + FhirResourceHelpers.buildStratumPopulation(stratValue1, true, true); + + assertEquals(stratifierGroupPopulationComponents.size(), 3); + assertEquals( + stratifierGroupPopulationComponents.get(0).getCode().getCoding().get(0).getCode(), + "initial-population"); + assertEquals(stratifierGroupPopulationComponents.get(0).getCount(), 1); + assertEquals( + stratifierGroupPopulationComponents.get(1).getCode().getCoding().get(0).getCode(), + "denominator"); + assertEquals(stratifierGroupPopulationComponents.get(1).getCount(), 1); + assertEquals( + stratifierGroupPopulationComponents.get(2).getCode().getCoding().get(0).getCode(), + "numerator"); + assertEquals(stratifierGroupPopulationComponents.get(2).getCount(), 0); + } + + @Test + void testBuildStratumPopulationForValueIndexOfFalse() { + TestCaseStratificationValue stratValue1 = + TestCaseStratificationValue.builder().name("Strata-1").expected(1).build(); + stratValue1.setPopulationValues( + List.of( + TestCasePopulationValue.builder() + .id("1") + .name(PopulationType.INITIAL_POPULATION) + .expected(1) + .build(), + TestCasePopulationValue.builder() + .id("2") + .name(PopulationType.DENOMINATOR) + .expected(1) + .build(), + TestCasePopulationValue.builder() + .id("3") + .name(PopulationType.NUMERATOR) + .expected(0) + .build())); + + List stratifierGroupPopulationComponents = + FhirResourceHelpers.buildStratumPopulation(stratValue1, false, true); + + assertEquals(stratifierGroupPopulationComponents.size(), 3); + assertEquals( + stratifierGroupPopulationComponents.get(0).getCode().getCoding().get(0).getCode(), + "initial-population"); + assertEquals(stratifierGroupPopulationComponents.get(0).getCount(), 0); + assertEquals( + stratifierGroupPopulationComponents.get(1).getCode().getCoding().get(0).getCode(), + "denominator"); + assertEquals(stratifierGroupPopulationComponents.get(1).getCount(), 0); + assertEquals( + stratifierGroupPopulationComponents.get(2).getCode().getCoding().get(0).getCode(), + "numerator"); + assertEquals(stratifierGroupPopulationComponents.get(2).getCount(), 1); + } + + @Test + void testBuildStratumPopulationForNonPatientBasedMeasures() { + TestCaseStratificationValue stratValue1 = + TestCaseStratificationValue.builder().name("Strata-1").expected(1).build(); + stratValue1.setPopulationValues( + List.of( + TestCasePopulationValue.builder() + .id("1") + .name(PopulationType.INITIAL_POPULATION) + .expected(5) + .build(), + TestCasePopulationValue.builder() + .id("2") + .name(PopulationType.DENOMINATOR) + .expected(4) + .build(), + TestCasePopulationValue.builder() + .id("3") + .name(PopulationType.NUMERATOR) + .expected(2) + .build())); + + List stratifierGroupPopulationComponents = + FhirResourceHelpers.buildStratumPopulation(stratValue1, null, false); + + assertEquals(stratifierGroupPopulationComponents.size(), 3); + assertEquals( + stratifierGroupPopulationComponents.get(0).getCode().getCoding().get(0).getCode(), + "initial-population"); + assertEquals(stratifierGroupPopulationComponents.get(0).getCount(), 5); + assertEquals( + stratifierGroupPopulationComponents.get(1).getCode().getCoding().get(0).getCode(), + "denominator"); + assertEquals(stratifierGroupPopulationComponents.get(1).getCount(), 4); + assertEquals( + stratifierGroupPopulationComponents.get(2).getCode().getCoding().get(0).getCode(), + "numerator"); + assertEquals(stratifierGroupPopulationComponents.get(2).getCount(), 2); + } +}