From 7a81ffc98310bd0658446aff6da197954122ba2e Mon Sep 17 00:00:00 2001 From: Nate Moraca Date: Thu, 21 Sep 2023 18:18:06 -0400 Subject: [PATCH] add collection check on strats for HR and update test --- .../services/HumanReadableService.java | 13 ++++++---- .../services/HumanReadableServiceTest.java | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java index 35f6e29f..f72ecef8 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50; import org.hl7.fhir.convertors.conv40_50.VersionConvertor_40_50; import org.hl7.fhir.exceptions.FHIRException; @@ -197,10 +198,14 @@ private void sortParameters( madieMeasure.getGroups().stream() .forEach( (g) -> - strats.addAll( - g.getStratifications().stream() - .map(s -> s.getCqlDefinition()) - .collect(Collectors.toList()))); + { + if (CollectionUtils.isNotEmpty(g.getStratifications())) { + strats.addAll( + g.getStratifications().stream() + .map(s -> s.getCqlDefinition()) + .collect(Collectors.toList())); + } + }); } Collections.sort( diff --git a/src/test/java/gov/cms/madie/madiefhirservice/services/HumanReadableServiceTest.java b/src/test/java/gov/cms/madie/madiefhirservice/services/HumanReadableServiceTest.java index f39cd50a..aba37991 100644 --- a/src/test/java/gov/cms/madie/madiefhirservice/services/HumanReadableServiceTest.java +++ b/src/test/java/gov/cms/madie/madiefhirservice/services/HumanReadableServiceTest.java @@ -6,8 +6,14 @@ import gov.cms.madie.madiefhirservice.utils.ResourceFileUtil; import gov.cms.madie.madiefhirservice.utils.ResourceUtils; import gov.cms.madie.models.common.Version; +import gov.cms.madie.models.measure.Group; import gov.cms.madie.models.measure.Measure; +import gov.cms.madie.models.measure.MeasureGroupTypes; import gov.cms.madie.models.measure.MeasureMetaData; +import gov.cms.madie.models.measure.MeasureScoring; +import gov.cms.madie.models.measure.Population; +import gov.cms.madie.models.measure.PopulationType; +import org.hl7.fhir.MeasureGroup; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r4.model.Attachment; import org.hl7.fhir.r4.model.Bundle; @@ -24,6 +30,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Date; +import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -53,6 +60,22 @@ class HumanReadableServiceTest implements ResourceFileUtil { @BeforeEach void setUp() { + Group measureGroup1 = Group.builder() + .id("GroupId1") + .groupDescription("some random group") + .measureGroupTypes(List.of(MeasureGroupTypes.OUTCOME)) + .scoring(MeasureScoring.COHORT.toString()) + .populations(List.of( + Population.builder() + .id("PopId1") + .name(PopulationType.INITIAL_POPULATION) + .definition("Initial Population") + .description(null) + .build() + )) + .build(); + measureGroup1.setStratifications(null); + madieMeasure = Measure.builder() .id("madie-test-id") @@ -67,6 +90,7 @@ void setUp() { .copyright("test_copyright") .disclaimer("test_disclaimer") .build()) + .groups(List.of(measureGroup1)) .build(); measure =