diff --git a/pom.xml b/pom.xml index 34b744ba2..a0e021a28 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ gov.cms.madie madie-java-models - 0.6.73-SNAPSHOT + 0.6.74-SNAPSHOT gov.cms.madie @@ -162,7 +162,7 @@ gov.cms.madie.packaging packaging-utility - 0.2.5 + 0.2.6 org.springdoc diff --git a/src/main/java/cms/gov/madie/measure/services/VersionService.java b/src/main/java/cms/gov/madie/measure/services/VersionService.java index a7ea0539d..2cc5595f9 100644 --- a/src/main/java/cms/gov/madie/measure/services/VersionService.java +++ b/src/main/java/cms/gov/madie/measure/services/VersionService.java @@ -1,9 +1,6 @@ package cms.gov.madie.measure.services; -import cms.gov.madie.measure.exceptions.BadVersionRequestException; -import cms.gov.madie.measure.exceptions.CqlElmTranslationErrorException; -import cms.gov.madie.measure.exceptions.MeasureNotDraftableException; -import cms.gov.madie.measure.exceptions.ResourceNotFoundException; +import cms.gov.madie.measure.exceptions.*; import cms.gov.madie.measure.repositories.CqmMeasureRepository; import cms.gov.madie.measure.repositories.ExportRepository; import cms.gov.madie.measure.repositories.MeasureRepository; @@ -12,6 +9,8 @@ import gov.cms.madie.models.common.Version; import gov.cms.madie.models.cqm.CqmMeasure; import gov.cms.madie.models.measure.*; +import gov.cms.madie.packaging.utils.PackagingUtility; +import gov.cms.madie.packaging.utils.PackagingUtilityFactory; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -19,6 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.lang.reflect.InvocationTargetException; import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -366,8 +366,23 @@ public String generateLibraryContentLine(String cqlLibraryName, Version version) } private void saveMeasureBundle(Measure savedMeasure, String measureBundle, String username) { + String humanReadableWithCss; + try { + PackagingUtility utility = PackagingUtilityFactory.getInstance(savedMeasure.getModel()); + humanReadableWithCss = utility.getHumanReadableWithCSS(measureBundle); + } catch (InstantiationException + | IllegalAccessException + | InvocationTargetException + | NoSuchMethodException + | ClassNotFoundException e) { + throw new BundleOperationException("Measure", savedMeasure.getId(), e); + } Export export = - Export.builder().measureId(savedMeasure.getId()).measureBundleJson(measureBundle).build(); + Export.builder() + .measureId(savedMeasure.getId()) + .measureBundleJson(measureBundle) + .humanReadable(humanReadableWithCss) + .build(); Export savedExport = exportRepository.save(export); log.info( "User [{}] successfully saved versioned measure's export data with ID [{}]", diff --git a/src/main/resources/templates/HumanReadable.liquid b/src/main/resources/templates/HumanReadable.liquid index d2f034c9e..6909a1eef 100644 --- a/src/main/resources/templates/HumanReadable.liquid +++ b/src/main/resources/templates/HumanReadable.liquid @@ -2,337 +2,420 @@ - human_readable_content_holder +human_readable_content_holder \ No newline at end of file diff --git a/src/test/java/cms/gov/madie/measure/services/VersionServiceTest.java b/src/test/java/cms/gov/madie/measure/services/VersionServiceTest.java index 4323a65fc..34c2bf0d4 100644 --- a/src/test/java/cms/gov/madie/measure/services/VersionServiceTest.java +++ b/src/test/java/cms/gov/madie/measure/services/VersionServiceTest.java @@ -50,33 +50,25 @@ public class VersionServiceTest { @Mock private MeasureRepository measureRepository; @Mock private CqmMeasureRepository cqmMeasureRepository; + @Mock private ExportRepository exportRepository; @Mock ActionLogService actionLogService; - - @Mock ElmTranslatorClient elmTranslatorClient; - - @Mock FhirServicesClient fhirServicesClient; - - @Mock ExportRepository exportRepository; - @Mock MeasureService measureService; - - @Mock QdmPackageService qdmPackageService; - @Mock ExportService exportService; - @Mock TestCaseSequenceService sequenceService; + @Mock QdmPackageService qdmPackageService; @Mock AppConfigService appConfigService; - @Mock ElmToJsonService elmToJsonService; - @InjectMocks VersionService versionService; + @Mock ElmTranslatorClient elmTranslatorClient; + @Mock FhirServicesClient fhirServicesClient; @Captor private ArgumentCaptor measureCaptor; @Captor private ArgumentCaptor cqmMeasureCaptor; - @Captor private ArgumentCaptor exportArgumentCaptor; + @InjectMocks VersionService versionService; + private final String ELMJON_ERROR = "{\n" + "\"errorExceptions\" : \n" + "[ {\"error\":\"error translating cql\" } ]\n" + "}"; private final String ELMJON_NO_ERROR = "{\n" + "\"errorExceptions\" : \n" + "[]\n" + "}"; @@ -443,7 +435,7 @@ public void testCreateVersionMajorSuccess() throws Exception { .measureSetId("testMeasureSetId") .createdBy("testUser") .cql("library Test1CQLLib version '2.3.001'") - .model(ModelType.QDM_5_6.getValue()) + .model(ModelType.QI_CORE.getValue()) .measureSet(measureSet) .build(); MeasureMetaData metaData = new MeasureMetaData(); @@ -470,16 +462,20 @@ public void testCreateVersionMajorSuccess() throws Exception { updatedMeasure.setMeasureMetaData(updatedMetaData); when(measureRepository.save(any(Measure.class))).thenReturn(updatedMeasure); + String measureBundleJson = + """ + {"resourceType": "Bundle","entry": [ { + "resource": { + "resourceType": "Measure","text":{"div":"humanReadable"}}}]}"""; Export measureExport = Export.builder() .id("testId") .measureId("testMeasureId") - .measureBundleJson("test measure json") + .measureBundleJson(measureBundleJson) .build(); when(exportRepository.save(any(Export.class))).thenReturn(measureExport); when(fhirServicesClient.getMeasureBundle(any(), anyString(), anyString())) - .thenReturn("test measure json"); - + .thenReturn(measureBundleJson); versionService.createVersion("testMeasureId", "MAJOR", "testUser", "accesstoken"); verify(measureRepository, times(1)).save(measureCaptor.capture()); @@ -564,7 +560,7 @@ public void testCreateFhirVersionPatchSuccess() throws Exception { FhirMeasure.builder() .id("testMeasureId") .measureSetId("testMeasureSetId") - .model(ModelType.QDM_5_6.getValue()) + .model(ModelType.QI_CORE_6_0_0.getValue()) .createdBy("testUser") .cql("library Test1CQLLib version '2.3.001'") .measureSet(measureSet) @@ -595,15 +591,20 @@ public void testCreateFhirVersionPatchSuccess() throws Exception { updatedMeasure.setMeasureMetaData(updatedMetaData); when(measureRepository.save(any(Measure.class))).thenReturn(updatedMeasure); + String measureBundleJson = + """ + {"resourceType": "Bundle","entry": [ { + "resource": { + "resourceType": "Measure","text":{"div":"humanReadable"}}}]}"""; Export measureExport = Export.builder() .id("testId") .measureId("testMeasureId") - .measureBundleJson("test measure json") + .measureBundleJson(measureBundleJson) .build(); when(exportRepository.save(any(Export.class))).thenReturn(measureExport); when(fhirServicesClient.getMeasureBundle(any(), anyString(), anyString())) - .thenReturn("test measure json"); + .thenReturn(measureBundleJson); versionService.createVersion("testMeasureId", "PATCH", "testUser", "accesstoken");