From c101aa2ab278d45e332f3bc22623646227e02365 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Mon, 18 Nov 2024 13:10:05 -0500 Subject: [PATCH] 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); + } +}