From 4957757e1c46630ee67388214d842104598774d8 Mon Sep 17 00:00:00 2001 From: Greg Akins Date: Wed, 11 Oct 2023 08:53:36 -0400 Subject: [PATCH] MAT-6206: Adding ability to export TestCases as type 'Collection' --- .../resources/MeasureBundleController.java | 25 +++---- .../resources/TestCaseBundleController.java | 6 +- .../services/MeasureBundleService.java | 9 ++- .../services/TestCaseBundleService.java | 70 +++---------------- .../utils/FhirResourceHelpers.java | 49 ++++++++++--- .../TestCaseBundleControllerMvcTest.java | 65 ++++++++++------- .../ResourceValidationServiceTest.java | 26 ++++--- .../services/TestCaseBundleServiceTest.java | 68 +++++++++++------- 8 files changed, 159 insertions(+), 159 deletions(-) diff --git a/src/main/java/gov/cms/madie/madiefhirservice/resources/MeasureBundleController.java b/src/main/java/gov/cms/madie/madiefhirservice/resources/MeasureBundleController.java index 601fa437..fc554c07 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/resources/MeasureBundleController.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/resources/MeasureBundleController.java @@ -1,33 +1,26 @@ package gov.cms.madie.madiefhirservice.resources; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.MethodOutcome; -import gov.cms.madie.madiefhirservice.services.ExportService; -import gov.cms.madie.madiefhirservice.services.MeasureBundleService; -import gov.cms.madie.madiefhirservice.utils.BundleUtil; -import gov.cms.madie.madiefhirservice.utils.ExportFileNamesUtil; -import gov.cms.madie.models.measure.Measure; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; - -import lombok.extern.slf4j.Slf4j; import org.hl7.fhir.r4.model.Bundle; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; -@Slf4j +import ca.uhn.fhir.context.FhirContext; +import gov.cms.madie.madiefhirservice.services.ExportService; +import gov.cms.madie.madiefhirservice.services.MeasureBundleService; +import gov.cms.madie.madiefhirservice.utils.ExportFileNamesUtil; +import gov.cms.madie.models.measure.Measure; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; + @Controller @RequestMapping(path = "/fhir/measures") @Tag(name = "Measure-Controller", description = "Measure resources HAPI FHIR API") @@ -47,7 +40,7 @@ public ResponseEntity getMeasureBundle( @RequestBody @Validated(Measure.ValidationSequence.class) Measure measure, @RequestHeader(value = HttpHeaders.ACCEPT, required = false) String accept, @RequestHeader("Authorization") String accessToken, - @RequestParam(required = false, defaultValue = "calculation", name = "bundleType") + @RequestParam(required = false, defaultValue = "CALCULATION", name = "bundleType") String bundleType) { Bundle bundle = diff --git a/src/main/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleController.java b/src/main/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleController.java index cca75885..1ce1bb06 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleController.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleController.java @@ -50,9 +50,6 @@ public ResponseEntity getTestCaseExportBundle( if (testCaseId == null || testCaseId.isEmpty()) { throw new ResourceNotFoundException("test cases", "measure", measure.getId()); } - //MAT-6204 Here we're modifying the bundle based on export choice, - // but we don't want to modify it permanently - testCaseBundleService.setExportBundleType(exportDTO, measure); List testCases = Optional.ofNullable(measure.getTestCases()) @@ -62,7 +59,8 @@ public ResponseEntity getTestCaseExportBundle( .filter(tc -> testCaseId.stream().anyMatch(id -> id.equals(tc.getId()))) .collect(Collectors.toList()); Map exportableTestCaseBundle = - testCaseBundleService.getTestCaseExportBundle(measure, testCases); + testCaseBundleService.getTestCaseExportBundle( + measure, testCases, exportDTO.getBundleType()); if (testCases.size() != exportableTestCaseBundle.size()) { // remove the test cases that couldn't be parsed testCases = diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/MeasureBundleService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/MeasureBundleService.java index c64f9e4a..5c55f691 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/MeasureBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/MeasureBundleService.java @@ -4,6 +4,7 @@ import gov.cms.madie.madiefhirservice.utils.BundleUtil; import gov.cms.madie.madiefhirservice.utils.FhirResourceHelpers; import gov.cms.madie.madiefhirservice.utils.ResourceUtils; + import gov.cms.madie.models.library.CqlLibrary; import gov.cms.madie.models.measure.Measure; import gov.cms.mat.cql.CqlFormatter; @@ -50,7 +51,7 @@ public Bundle createMeasureBundle( // Bundle entry for Measure resource Bundle.BundleEntryComponent measureEntryComponent = - FhirResourceHelpers.getBundleEntryComponent(measure, "Transaction"); + FhirResourceHelpers.getBundleEntryComponent(measure, Bundle.BundleType.TRANSACTION); Bundle bundle = new Bundle().setType(Bundle.BundleType.TRANSACTION).addEntry(measureEntryComponent); // Bundle entries for all the library resources of a MADiE Measure @@ -91,13 +92,15 @@ public List createBundleComponentsForLibrariesOfMad Measure madieMeasure, final String bundleType, final String accessToken) { Library library = getMeasureLibraryResourceForMadieMeasure(madieMeasure); Bundle.BundleEntryComponent mainLibraryBundleComponent = - FhirResourceHelpers.getBundleEntryComponent(library, "Transaction"); + FhirResourceHelpers.getBundleEntryComponent(library, Bundle.BundleType.TRANSACTION); Map includedLibraryMap = new HashMap<>(); libraryService.getIncludedLibraries( madieMeasure.getCql(), includedLibraryMap, bundleType, accessToken); List libraryBundleComponents = includedLibraryMap.values().stream() - .map((lib) -> FhirResourceHelpers.getBundleEntryComponent(lib, "Transaction")) + .map( + (lib) -> + FhirResourceHelpers.getBundleEntryComponent(lib, Bundle.BundleType.TRANSACTION)) .collect(Collectors.toList()); // add main library first in the list libraryBundleComponents.add(0, mainLibraryBundleComponent); 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 acc0159a..a2daba23 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleService.java @@ -24,8 +24,6 @@ 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.Bundle.HTTPVerb; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.MarkdownType; import org.hl7.fhir.r4.model.MeasureReport; @@ -49,7 +47,6 @@ import gov.cms.madie.madiefhirservice.utils.ExportFileNamesUtil; 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; @@ -64,7 +61,8 @@ public class TestCaseBundleService { private final FhirContext fhirContext; - public Map getTestCaseExportBundle(Measure measure, List testCases) { + public Map getTestCaseExportBundle( + Measure measure, List testCases, BundleType bundleType) { if (measure == null || testCases == null || testCases.isEmpty()) { throw new InternalServerException("Unable to find Measure and/or test case"); } @@ -85,6 +83,11 @@ public Map getTestCaseExportBundle(Measure measure, List getTestCaseExportBundle(Measure measure, List getTestCaseExportBundle(Measure measure, List { - if (bundleType == BundleType.TRANSACTION) { - - - FhirResourceHelpers.setResourceEntry(entry.getResource(), entry); - return entry; - } else if (bundleType == BundleType.COLLECTION) { - entry.setRequest(null); - } - return entry; - }) - .collect(Collectors.toList())); - // bundle to json - String json = parser.encodeResourceToString(bundle); - - testCase.setJson(json); - } - private MeasureReport buildMeasureReport( TestCase testCase, Measure measure, Bundle testCaseBundle) { MeasureReport measureReport = new MeasureReport(); @@ -319,26 +287,6 @@ private String generateReadMe(List testCases) { return readMe; } - public void setExportBundleType(ExportDTO exportDTO, Measure measure) { - if (exportDTO.getBundleType() != null) { - BundleType bundleType = BundleType.valueOf(exportDTO.getBundleType().name()); - switch (bundleType) { - case COLLECTION: - log.debug("You're exporting a Collection"); - // update bundle type for each entry MAT 6405 - break; - case TRANSACTION: - log.debug("You're exporting a Transaction"); - // update bundle type and add entry.request for each entry - if (measure.getTestCases() != null) { - measure.getTestCases().stream().forEach(testCase -> updateEntry(testCase, bundleType)); - } - break; - default: - } - } - } - /** * Combines the zip from Packaging Utility and a generated ReadMe file for the testcases * 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 244dfb11..03dadf53 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/utils/FhirResourceHelpers.java @@ -2,6 +2,7 @@ import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Bundle.BundleType; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Period; @@ -11,6 +12,7 @@ import java.util.ArrayList; import java.util.Date; +import java.util.stream.Collectors; @Component public class FhirResourceHelpers { @@ -21,26 +23,55 @@ public void setMadieUrl(String url) { FhirResourceHelpers.madieUrl = url; } + public static Bundle setTestCaseBundleEntryComponent(Bundle bundle) { + + // modify the bundle + org.hl7.fhir.r4.model.Bundle.BundleType fhirBundleType = + org.hl7.fhir.r4.model.Bundle.BundleType.valueOf(bundle.getType().toString().toUpperCase()); + bundle.setType(fhirBundleType); + bundle.setEntry( + bundle.getEntry().stream() + .map( + entry -> { + if (org.hl7.fhir.r4.model.Bundle.BundleType.valueOf( + bundle.getType().toString().toUpperCase()) + == BundleType.TRANSACTION) { + FhirResourceHelpers.setResourceEntry(entry.getResource(), entry); + return entry; + } else if (org.hl7.fhir.r4.model.Bundle.BundleType.valueOf( + bundle.getType().toString().toUpperCase()) + == BundleType.COLLECTION) { + entry.setRequest(null); + } + return entry; + }) + .collect(Collectors.toList())); + // bundle to json + + return bundle; + } + public static Bundle.BundleEntryComponent getBundleEntryComponent( - Resource resource, String bundleType) { + Resource resource, Bundle.BundleType bundleType) { Bundle.BundleEntryComponent entryComponent = new Bundle.BundleEntryComponent() .setFullUrl(buildResourceFullUrl(resource.fhirType(), resource.getIdPart())) .setResource(resource); // for the transaction bundles, add request object to the entry - if ("Transaction".equalsIgnoreCase(bundleType)) { + if (bundleType == Bundle.BundleType.TRANSACTION) { setResourceEntry(resource, entryComponent); } return entryComponent; } -public static void setResourceEntry(Resource resource, Bundle.BundleEntryComponent entryComponent) { - Bundle.BundleEntryRequestComponent requestComponent = - new Bundle.BundleEntryRequestComponent() - .setMethod(Bundle.HTTPVerb.POST) - .setUrl(resource.getResourceType() + "/" + resource.getIdPart()); - entryComponent.setRequest(requestComponent); -} + public static void setResourceEntry( + Resource resource, Bundle.BundleEntryComponent entryComponent) { + Bundle.BundleEntryRequestComponent requestComponent = + new Bundle.BundleEntryRequestComponent() + .setMethod(Bundle.HTTPVerb.POST) + .setUrl(resource.getResourceType() + "/" + resource.getIdPart()); + entryComponent.setRequest(requestComponent); + } public static Period getPeriodFromDates(Date startDate, Date endDate) { return new Period() diff --git a/src/test/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleControllerMvcTest.java b/src/test/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleControllerMvcTest.java index 36257afa..4bd85cd9 100644 --- a/src/test/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleControllerMvcTest.java +++ b/src/test/java/gov/cms/madie/madiefhirservice/resources/TestCaseBundleControllerMvcTest.java @@ -1,14 +1,20 @@ package gov.cms.madie.madiefhirservice.resources; -import ca.uhn.fhir.context.FhirContext; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import gov.cms.madie.madiefhirservice.services.TestCaseBundleService; -import gov.cms.madie.madiefhirservice.utils.ResourceFileUtil; -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 static java.util.Arrays.asList; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.security.Principal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.hl7.fhir.r4.model.Bundle; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -19,15 +25,16 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import java.security.Principal; -import java.util.*; -import static java.util.Arrays.asList; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import ca.uhn.fhir.context.FhirContext; +import gov.cms.madie.madiefhirservice.services.TestCaseBundleService; +import gov.cms.madie.madiefhirservice.utils.ResourceFileUtil; +import gov.cms.madie.models.common.BundleType; +import gov.cms.madie.models.dto.ExportDTO; +import gov.cms.madie.models.measure.Measure; @WebMvcTest({TestCaseBundleController.class}) class TestCaseBundleControllerMvcTest implements ResourceFileUtil { @@ -73,7 +80,8 @@ void getTestCaseExportBundleMulti() throws Exception { dto.getMeasure().getTestCases().get(0).getPatientId().toString(), testCaseBundle); testCaseBundleMap.put( dto.getMeasure().getTestCases().get(1).getPatientId().toString(), testCaseBundle); - when(testCaseBundleService.getTestCaseExportBundle(any(Measure.class), any(List.class))) + when(testCaseBundleService.getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class))) .thenReturn(testCaseBundleMap); mockMvc .perform( @@ -85,7 +93,8 @@ void getTestCaseExportBundleMulti() throws Exception { .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); verify(testCaseBundleService, times(1)) - .getTestCaseExportBundle(any(Measure.class), any(List.class)); + .getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class)); } @Test @@ -99,7 +108,8 @@ void getTestCaseExportBundleMultiWithBundleTypeCollection() throws Exception { dto.getMeasure().getTestCases().get(0).getPatientId().toString(), testCaseBundle); testCaseBundleMap.put( dto.getMeasure().getTestCases().get(1).getPatientId().toString(), testCaseBundle); - when(testCaseBundleService.getTestCaseExportBundle(any(Measure.class), any(List.class))) + when(testCaseBundleService.getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class))) .thenReturn(testCaseBundleMap); mockMvc .perform( @@ -111,7 +121,8 @@ void getTestCaseExportBundleMultiWithBundleTypeCollection() throws Exception { .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); verify(testCaseBundleService, times(1)) - .getTestCaseExportBundle(any(Measure.class), any(List.class)); + .getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class)); } @Test @@ -126,7 +137,8 @@ void getTestCaseExportBundleMultiWithBundleTypeTransaction() throws Exception { dto.getMeasure().getTestCases().get(0).getPatientId().toString(), testCaseBundle); testCaseBundleMap.put( dto.getMeasure().getTestCases().get(1).getPatientId().toString(), testCaseBundle); - when(testCaseBundleService.getTestCaseExportBundle(any(Measure.class), any(List.class))) + when(testCaseBundleService.getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class))) .thenReturn(testCaseBundleMap); mockMvc .perform( @@ -138,7 +150,8 @@ void getTestCaseExportBundleMultiWithBundleTypeTransaction() throws Exception { .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); verify(testCaseBundleService, times(1)) - .getTestCaseExportBundle(any(Measure.class), any(List.class)); + .getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class)); } @Test @@ -184,7 +197,8 @@ void getTestCaseExportAllReturnParialContent() throws Exception { Map testCaseBundleMap = new HashMap<>(); testCaseBundleMap.put( dto.getMeasure().getTestCases().get(0).getPatientId().toString(), testCaseBundle); - when(testCaseBundleService.getTestCaseExportBundle(any(Measure.class), any(List.class))) + when(testCaseBundleService.getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class))) .thenReturn(testCaseBundleMap); mockMvc .perform( @@ -196,6 +210,7 @@ void getTestCaseExportAllReturnParialContent() throws Exception { .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().is(206)); verify(testCaseBundleService, times(1)) - .getTestCaseExportBundle(any(Measure.class), any(List.class)); + .getTestCaseExportBundle( + any(Measure.class), any(List.class), any(gov.cms.madie.models.common.BundleType.class)); } } diff --git a/src/test/java/gov/cms/madie/madiefhirservice/services/ResourceValidationServiceTest.java b/src/test/java/gov/cms/madie/madiefhirservice/services/ResourceValidationServiceTest.java index fe934005..ab4d41c6 100644 --- a/src/test/java/gov/cms/madie/madiefhirservice/services/ResourceValidationServiceTest.java +++ b/src/test/java/gov/cms/madie/madiefhirservice/services/ResourceValidationServiceTest.java @@ -1,8 +1,14 @@ package gov.cms.madie.madiefhirservice.services; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.util.BundleUtil; -import gov.cms.madie.madiefhirservice.constants.UriConstants; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; + +import java.util.List; + import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Encounter; @@ -12,22 +18,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.BundleUtil; +import gov.cms.madie.madiefhirservice.constants.UriConstants; @ExtendWith(MockitoExtension.class) class ResourceValidationServiceTest { diff --git a/src/test/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleServiceTest.java b/src/test/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleServiceTest.java index e734fef9..ff42fbfa 100644 --- a/src/test/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleServiceTest.java +++ b/src/test/java/gov/cms/madie/madiefhirservice/services/TestCaseBundleServiceTest.java @@ -27,7 +27,6 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.time.DateFormatUtils; -import org.hl7.fhir.dstu2.model.Bundle.HTTPVerb; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.MeasureReport; import org.hl7.fhir.r4.model.Parameters; @@ -95,22 +94,6 @@ public void setUp() throws JsonProcessingException { ReflectionTestUtils.setField(fhirResourceHelpers, "madieUrl", "madie.cms.gov"); } - @Test - void updateEntryTest() { - IParser parser = - fhirContext - .newJsonParser() - .setParserErrorHandler(new StrictErrorHandler()) - .setPrettyPrint(true); - Bundle bundle = parser.parseResource(Bundle.class, testCase.getJson()); - assertNull(bundle.getEntry().get(0).getRequest().getMethod()); - testCaseBundleService.updateEntry(testCase, BundleType.TRANSACTION); - - bundle = parser.parseResource(Bundle.class, testCase.getJson()); - assertEquals( - bundle.getEntry().get(0).getRequest().getMethod().toString(), HTTPVerb.POST.toString()); - } - @Test void zipTestCaseContentsTest() { @@ -138,7 +121,8 @@ void zipTestCaseContentsTest() { @Test void getTestCaseExportBundleMulti() { Map exportMap = - testCaseBundleService.getTestCaseExportBundle(madieMeasure, madieMeasure.getTestCases()); + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, madieMeasure.getTestCases(), null); assertEquals(2, exportMap.size()); // first test case bundle(collection) @@ -195,7 +179,7 @@ void getTestCaseExportBundleMulti() { exportMap.get( "0ec1197a-4895-43ed-b2eb-27971f8fb95b/title-v0.0.000-testcaseseries-testcasetitle1"); assertEquals(5, bundle.getEntry().size()); - assertEquals(bundle.getType(), Bundle.BundleType.TRANSACTION); + assertEquals(Bundle.BundleType.TRANSACTION, bundle.getType()); bundleEntry = bundle.getEntry().get(4); assertEquals(bundleEntry.getRequest().getMethod(), Bundle.HTTPVerb.POST); assertEquals( @@ -207,7 +191,8 @@ void getTestCaseExportBundleMulti() { void getTestCaseExportBundleMultiReducedResult() { madieMeasure.getTestCases().get(1).setJson("malformed"); Map exportMap = - testCaseBundleService.getTestCaseExportBundle(madieMeasure, madieMeasure.getTestCases()); + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, madieMeasure.getTestCases(), BundleType.COLLECTION); // The service should remove the malformed testCase and return only the valid one assertEquals(1, exportMap.size()); @@ -258,14 +243,18 @@ void getTestCaseExportAllThrowExceptionWhenTestCaseIsNotFound() { List testCaseList = null; assertThrows( InternalServerException.class, - () -> testCaseBundleService.getTestCaseExportBundle(madieMeasure, testCaseList)); + () -> + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, testCaseList, BundleType.COLLECTION)); } @Test void getTestCaseExportAllThrowExceptionWhenTestCaseListIsEmpty() { assertThrows( InternalServerException.class, - () -> testCaseBundleService.getTestCaseExportBundle(madieMeasure, emptyList())); + () -> + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, emptyList(), BundleType.COLLECTION)); } @Test @@ -273,7 +262,9 @@ void getTestCaseExportAllThrowExceptionWhenMeasureIsNotFound() { madieMeasure = null; assertThrows( InternalServerException.class, - () -> testCaseBundleService.getTestCaseExportBundle(madieMeasure, singletonList(testCase))); + () -> + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, singletonList(testCase), BundleType.COLLECTION)); } @Test @@ -281,7 +272,9 @@ void getTestCaseExportAllThrowExceptionWhenTestCaseJsonIsNull() { testCase.setJson(null); assertThrows( ResourceNotFoundException.class, - () -> testCaseBundleService.getTestCaseExportBundle(madieMeasure, singletonList(testCase))); + () -> + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, singletonList(testCase), BundleType.COLLECTION)); } @Test @@ -289,7 +282,9 @@ void getTestCaseExportAllThrowExceptionWhenTestCaseJsonIsEmpty() { testCase.setJson(""); assertThrows( ResourceNotFoundException.class, - () -> testCaseBundleService.getTestCaseExportBundle(madieMeasure, singletonList(testCase))); + () -> + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, singletonList(testCase), BundleType.COLLECTION)); } @Test @@ -297,7 +292,9 @@ void getTestCaseExportAllThrowExceptionWhenAllTestCaseJsonIsMalformed() { testCase.setJson("test"); assertThrows( ResourceNotFoundException.class, - () -> testCaseBundleService.getTestCaseExportBundle(madieMeasure, singletonList(testCase))); + () -> + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, singletonList(testCase), BundleType.COLLECTION)); } @Test @@ -305,7 +302,24 @@ void getTestCaseExportBundleReturnsMeasureReportWithNoGroupPopulations() { madieMeasure.getTestCases().get(0).setGroupPopulations(null); Map exportMap = - testCaseBundleService.getTestCaseExportBundle(madieMeasure, madieMeasure.getTestCases()); + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, madieMeasure.getTestCases(), BundleType.COLLECTION); + assertEquals(2, exportMap.size()); + + Bundle bundle = + exportMap.get( + "285d114d-9c36-4d66-b0a0-06f395bbf23d/title-v0.0.000-testcaseseries-testcasetitle"); + MeasureReport measureReport = (MeasureReport) bundle.getEntry().get(4).getResource(); + assertEquals(0, measureReport.getGroup().size()); + } + + @Test + void getTestCaseExportBundleReturnsMeasureReportWithNoGroupPopulationsAndNoBundleType() { + + madieMeasure.getTestCases().get(0).setGroupPopulations(null); + Map exportMap = + testCaseBundleService.getTestCaseExportBundle( + madieMeasure, madieMeasure.getTestCases(), null); assertEquals(2, exportMap.size()); Bundle bundle =