Skip to content

Commit

Permalink
Merge pull request #228 from cqframework/refreshExceptionFix
Browse files Browse the repository at this point in the history
Refresh exception fix
  • Loading branch information
brynrhodes authored May 14, 2021
2 parents f15a297 + 06e3641 commit 88f4653
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ public <T extends DomainResource> void ensureSoftwareSystemExtensionAndDevice(T
final List<Extension> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -544,6 +551,14 @@ private String stripReference(String path) {
private org.hl7.fhir.r5.model.DataRequirement toDataRequirement(ElmRequirementsContext context,
VersionedIdentifier libraryIdentifier, Retrieve retrieve, Map<String, Retrieve> 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) {
Expand All @@ -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())));
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/org/opencds/cqf/tooling/utilities/BundleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 88f4653

Please sign in to comment.