From de537f261beded6e37ed05253d4282c37454f3a9 Mon Sep 17 00:00:00 2001 From: Evan Chicoine Date: Tue, 14 Dec 2021 15:33:43 -0500 Subject: [PATCH] 319: Update Measure Refresh to use QM IG 3.0.0 approach --- .../measure/MeasureRefreshProcessor.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/opencds/cqf/tooling/measure/MeasureRefreshProcessor.java b/src/main/java/org/opencds/cqf/tooling/measure/MeasureRefreshProcessor.java index b71d20bcf..0b64b4b8c 100644 --- a/src/main/java/org/opencds/cqf/tooling/measure/MeasureRefreshProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/measure/MeasureRefreshProcessor.java @@ -13,7 +13,9 @@ public class MeasureRefreshProcessor { public Measure refreshMeasure(Measure measureToUse, LibraryManager libraryManager, TranslatedLibrary translatedLibrary, CqlTranslatorOptions options) { - Library moduleDefinitionLibrary = getModuleDefinitionLibrary(measureToUse, libraryManager, translatedLibrary, options); + + Library moduleDefinitionLibrary = getModuleDefinitionLibrary(measureToUse, libraryManager, translatedLibrary, options); + measureToUse.setDate(new Date()); // http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/measure-cqfm setMeta(measureToUse, moduleDefinitionLibrary); @@ -27,11 +29,11 @@ public Measure refreshMeasure(Measure measureToUse, LibraryManager libraryManage clearMeasureExtensions(measureToUse, "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-dataRequirement"); clearMeasureExtensions(measureToUse, "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode"); clearMeasureExtensions(measureToUse, "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-logicDefinition"); + clearMeasureExtensions(measureToUse, "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-effectiveDataRequirements"); clearRelatedArtifacts(measureToUse); - setParameters(measureToUse, moduleDefinitionLibrary); - setDataRequirements(measureToUse, moduleDefinitionLibrary); - setDirectReferenceCode(measureToUse, moduleDefinitionLibrary); - setLogicDefinition(measureToUse, moduleDefinitionLibrary); + + setEffectiveDataRequirements(measureToUse, moduleDefinitionLibrary); + measureToUse.setRelatedArtifact(moduleDefinitionLibrary.getRelatedArtifact()); return measureToUse; @@ -68,29 +70,29 @@ private void clearRelatedArtifacts(Measure measure) { measure.getRelatedArtifact().removeIf(r -> r.getType() == RelatedArtifact.RelatedArtifactType.DEPENDSON); } - private void setLogicDefinition(Measure measureToUse, Library moduleDefinitionLibrary) { - moduleDefinitionLibrary.getExtension().forEach(extension -> { - if (extension.getUrl().equalsIgnoreCase("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-logicDefinition")) { - measureToUse.addExtension(extension); - } - }); - } - - private void setDirectReferenceCode(Measure measureToUse, Library moduleDefinitionLibrary) { - moduleDefinitionLibrary.getExtension().forEach(extension -> { - if(extension.getUrl().equalsIgnoreCase("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode")) { - measureToUse.addExtension(extension); - } - }); - } - - private void setDataRequirements(Measure measureToUse, Library moduleDefinitionLibrary) { - moduleDefinitionLibrary.getDataRequirement().forEach(dataRequirement -> { - Extension dataReqExtension = new Extension(); - dataReqExtension.setUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-dataRequirement"); - dataReqExtension.setValue(dataRequirement); - measureToUse.addExtension(dataReqExtension); - }); + private void setEffectiveDataRequirements(Measure measureToUse, Library moduleDefinitionLibrary) { + + moduleDefinitionLibrary.setId("effective-data-requirements"); + + int delIndex = -1; + for (Resource res : measureToUse.getContained()) { + if (res instanceof Library && ((Library)res).getId().equalsIgnoreCase("effective-data-requirements")) { + delIndex = measureToUse.getContained().indexOf(res); + break; + } + } + + if (delIndex >= 0) { + measureToUse.getContained().remove(delIndex); + } + + measureToUse.getContained().add(moduleDefinitionLibrary); + + Extension effDataReqExtension = new Extension(); + effDataReqExtension.setUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-effectiveDataRequirements"); + effDataReqExtension.setId("effective-data-requirements"); + effDataReqExtension.setValue(new Reference().setReference("#effective-data-requirements")); + measureToUse.addExtension(effDataReqExtension); } private void setParameters(Measure measureToUse, Library moduleDefinitionLibrary) { @@ -120,4 +122,6 @@ private void setMeta(Measure measureToUse, Library moduleDefinitionLibrary){ measureToUse.getMeta().addProfile("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/computable-measure-cqfm"); } } + + }