diff --git a/src/main/java/org/opencds/cqf/tooling/common/r4/CqfmSoftwareSystemHelper.java b/src/main/java/org/opencds/cqf/tooling/common/r4/CqfmSoftwareSystemHelper.java index b34316d6f..0bd5fe6ee 100644 --- a/src/main/java/org/opencds/cqf/tooling/common/r4/CqfmSoftwareSystemHelper.java +++ b/src/main/java/org/opencds/cqf/tooling/common/r4/CqfmSoftwareSystemHelper.java @@ -111,9 +111,13 @@ public void ensureSoftwareSystemExtensionAndDevice(T final List extensions = resource.getExtension(); Extension softwareSystemExtension = null; for (Extension ext : extensions) { - if (ext.getValue().fhirType().equals("Reference") && ((Reference) ext.getValue()).getReference().equals(systemReferenceID)) { - softwareSystemExtension = ext; - ((Reference)softwareSystemExtension.getValue()).setResource(null); + if(ext.getValue() != null + && ext.getValue().fhirType() != null + && ext.getValue().fhirType().equals("Reference") + && ((Reference)ext.getValue()).getReference() != null + && ((Reference) ext.getValue()).getReference().equals(systemReferenceID)){ + softwareSystemExtension = ext; + ((Reference) softwareSystemExtension.getValue()).setResource(null); } } diff --git a/src/main/java/org/opencds/cqf/tooling/operation/ExtractMatBundleOperation.java b/src/main/java/org/opencds/cqf/tooling/operation/ExtractMatBundleOperation.java index a34dbda65..443996f29 100644 --- a/src/main/java/org/opencds/cqf/tooling/operation/ExtractMatBundleOperation.java +++ b/src/main/java/org/opencds/cqf/tooling/operation/ExtractMatBundleOperation.java @@ -24,26 +24,49 @@ public class ExtractMatBundleOperation extends Operation { private String version = "r4"; private FhirContext context; private String encoding; + private boolean suppressNarrative = true; @Override - public void execute(String[] args) { - // Set file to extract - inputFile = args[1]; - if (inputFile == null) { - throw new IllegalArgumentException("The path to a bundle file is required"); - } - - // Set version - if (args.length > 2) { - if (args[2] != null) { - String[] flagAndValue = args[2].split("="); - String flag = flagAndValue[0]; - String value = flagAndValue[1]; - if (flag != "-v") { - throw new IllegalArgumentException("Invalid argument: " + flag); - } else { - version = value; - } + public void execute(String[] args) { + + for (int i = 0; i < args.length;i++) { + if(i == 0 && args[i].equalsIgnoreCase("-ExtractMatBundle")){ + continue; // + } + if(i == 1){ + inputFile = args[i]; + if (inputFile == null) { + throw new IllegalArgumentException("The path to a bundle file is required"); + } + continue; + } + + String[] flagAndValue = args[i].split("="); + if (flagAndValue.length < 2) { + throw new IllegalArgumentException("Invalid argument: " + args[i]); + } + String flag = flagAndValue[0]; + String value = flagAndValue[1]; + + switch (flag.replace("-", "").toLowerCase()) { + case "encoding": + case "e": + encoding = value.toLowerCase(); + break; + case "supressNarrative": + case "sn": + if(value.equalsIgnoreCase("false")) { + suppressNarrative = false; + } + break; + case "outputpath": + case "op": + setOutputPath(value); + break; // -outputpath (-op) + case "version": case "v": + version = value; + break; + default: throw new IllegalArgumentException("Unknown flag: " + flag); } } @@ -99,14 +122,15 @@ else if (bundleFile.getPath().endsWith(".json")) { // Now call the Bundle utilities to extract the bundle String outputDir = bundleFile.getAbsoluteFile().getParent(); if (version == "stu3") { - BundleUtils.extractStu3Resources((org.hl7.fhir.dstu3.model.Bundle)bundle, encoding, outputDir); + BundleUtils.extractStu3Resources((org.hl7.fhir.dstu3.model.Bundle)bundle, encoding, outputDir, suppressNarrative); } else if (version == "r4") { - BundleUtils.extractR4Resources((org.hl7.fhir.r4.model.Bundle)bundle, encoding, outputDir); + BundleUtils.extractR4Resources((org.hl7.fhir.r4.model.Bundle)bundle, encoding, outputDir, suppressNarrative); } // Now move and properly rename the files moveAndRenameFiles(outputDir); + LogUtils.info("Extraction completed successfully"); } diff --git a/src/main/java/org/opencds/cqf/tooling/processor/DataRequirementsProcessor.java b/src/main/java/org/opencds/cqf/tooling/processor/DataRequirementsProcessor.java index a7471ae70..91975406f 100644 --- a/src/main/java/org/opencds/cqf/tooling/processor/DataRequirementsProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/processor/DataRequirementsProcessor.java @@ -368,8 +368,15 @@ private ParameterDefinition toParameterDefinition(VersionedIdentifier libraryIde private ParameterDefinition toOutputParameterDefinition(VersionedIdentifier libraryIdentifier, ExpressionDef def) { AtomicBoolean isList = new AtomicBoolean(false); - Enumerations.FHIRAllTypes typeCode = Enumerations.FHIRAllTypes.fromCode( - toFHIRResultTypeCode(def.getResultType(), def.getName(), isList)); + Enumerations.FHIRAllTypes typeCode = null; + try{ + typeCode = Enumerations.FHIRAllTypes.fromCode( + toFHIRResultTypeCode(def.getResultType(), def.getName(), isList)); + }catch(org.hl7.fhir.exceptions.FHIRException fhirException){ + validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", + String.format("Result type %s of library %s is not supported; implementations may not be able to use the result of this expression", + def.getResultType().toLabel(), libraryIdentifier.getId()), ValidationMessage.IssueSeverity.WARNING)); + } return new ParameterDefinition() .setName(def.getName()) @@ -544,6 +551,14 @@ private String stripReference(String path) { private org.hl7.fhir.r5.model.DataRequirement toDataRequirement(ElmRequirementsContext context, VersionedIdentifier libraryIdentifier, Retrieve retrieve, Map retrieveMap) { org.hl7.fhir.r5.model.DataRequirement dr = new org.hl7.fhir.r5.model.DataRequirement(); + try { + dr.setType(org.hl7.fhir.r5.model.Enumerations.FHIRAllTypes.fromCode(retrieve.getDataType().getLocalPart())); + } + catch(org.hl7.fhir.exceptions.FHIRException fhirException) { + validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", + String.format("Result type %s of library %s is not supported; implementations may not be able to use the result of this expression", + retrieve.getDataType().getLocalPart(), libraryIdentifier.getId()), ValidationMessage.IssueSeverity.WARNING)); + } // Set the id attribute of the data requirement if it will be referenced from an included retrieve if (retrieve.getLocalId() != null && retrieve.getInclude() != null && retrieve.getInclude().size() > 0) { @@ -554,8 +569,6 @@ private org.hl7.fhir.r5.model.DataRequirement toDataRequirement(ElmRequirementsC } } - dr.setType(org.hl7.fhir.r5.model.Enumerations.FHIRAllTypes.fromCode(retrieve.getDataType().getLocalPart())); - // Set profile if specified if (retrieve.getTemplateId() != null) { dr.setProfile(Collections.singletonList(new org.hl7.fhir.r5.model.CanonicalType(retrieve.getTemplateId()))); diff --git a/src/main/java/org/opencds/cqf/tooling/utilities/BundleUtils.java b/src/main/java/org/opencds/cqf/tooling/utilities/BundleUtils.java index 29a2db9c7..4ebd9ba17 100644 --- a/src/main/java/org/opencds/cqf/tooling/utilities/BundleUtils.java +++ b/src/main/java/org/opencds/cqf/tooling/utilities/BundleUtils.java @@ -141,20 +141,28 @@ public static void stampR4BundleEntriesWithSoftwareSystems(org.hl7.fhir.r4.model } } - public static void extractStu3Resources(org.hl7.fhir.dstu3.model.Bundle bundle, String encoding, String outputPath) { + public static void extractStu3Resources(org.hl7.fhir.dstu3.model.Bundle bundle, String encoding, String outputPath, boolean suppressNarrative) { FhirContext context = FhirContext.forDstu3(); for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) { - if (entry.getResource() != null) { - ResourceUtils.outputResource(entry.getResource(), encoding, context, outputPath); + org.hl7.fhir.dstu3.model.Resource entryResource = entry.getResource(); + if (entryResource != null) { + if(entryResource.fhirType().equals("Measure") && suppressNarrative){ + ((org.hl7.fhir.dstu3.model.Measure)entryResource).setText(null); + } + ResourceUtils.outputResource(entryResource, encoding, context, outputPath); } } } - public static void extractR4Resources(org.hl7.fhir.r4.model.Bundle bundle, String encoding, String outputPath) { + public static void extractR4Resources(org.hl7.fhir.r4.model.Bundle bundle, String encoding, String outputPath, boolean suppressNarrative) { FhirContext context = FhirContext.forR4(); for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) { - if (entry.getResource() != null) { - ResourceUtils.outputResource(entry.getResource(), encoding, context, outputPath); + org.hl7.fhir.r4.model.Resource entryResource = entry.getResource(); + if (entryResource != null) { + if(entryResource.fhirType().equals("Measure") && suppressNarrative){ + ((org.hl7.fhir.r4.model.Measure)entryResource).setText(null); + } + ResourceUtils.outputResource(entryResource, encoding, context, outputPath); } } }