From c4946a6f270d4da69f92b49266f2c07db1fb8c55 Mon Sep 17 00:00:00 2001 From: Evan Chicoine Date: Wed, 29 Nov 2023 07:51:24 -0500 Subject: [PATCH] Code cleanup with fixed merge of LibraryProcessor --- .vscode/settings.json | 4 +- .../cqf/tooling/library/LibraryProcessor.java | 47 ++++++++++++++++++- .../cqf/tooling/utilities/IOUtils.java | 4 ++ .../tooling/processor/IGProcessorTest.java | 2 +- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 746e145f1..c21670fb7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,5 @@ "editor.codeActionsOnSave": { "source.organizeImports": true, "editor.formatOnSave": true - } -} + }, +} \ No newline at end of file diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java b/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java index 28c0c0190..e9aa938ea 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java @@ -3,6 +3,9 @@ import ca.uhn.fhir.context.FhirContext; import com.google.common.base.Strings; import org.apache.commons.io.FilenameUtils; +import org.cqframework.cql.cql2elm.CqlCompilerOptions; +import org.cqframework.cql.cql2elm.CqlTranslator; +import org.cqframework.cql.cql2elm.CqlTranslatorOptions; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r5.model.*; import org.hl7.fhir.utilities.TextFile; @@ -205,8 +208,10 @@ protected Library refreshGeneratedContent(Library sourceLibrary) { sourceLibrary.getRelatedArtifact().addAll(info.getRelatedArtifacts()); sourceLibrary.getParameter().clear(); sourceLibrary.getParameter().addAll(info.getParameters()); + getCqlProcessor().getCqlTranslatorOptions(); + setTranslatorOptions(sourceLibrary, getCqlProcessor().getCqlTranslatorOptions()); } else { - logMessage(String.format("No cql info found for ", fileName)); + logMessage(String.format("No cql info found for %s", fileName)); //f.getErrors().add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTFOUND, "Library", "No cql info found for "+f.getName(), ValidationMessage.IssueSeverity.ERROR)); } } @@ -214,6 +219,46 @@ protected Library refreshGeneratedContent(Library sourceLibrary) { return sourceLibrary; } + protected void setTranslatorOptions(Library sourceLibrary, CqlTranslatorOptions options) { + Extension optionsExtension = sourceLibrary.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/cqf-cqlOptions"); + if (optionsExtension == null) { + optionsExtension = sourceLibrary.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/cqf-cqlOptions"); + } + Reference optionsReference = optionsExtension.getValueReference(); + String optionsReferenceValue = optionsReference.getReference(); + if (optionsReferenceValue == null) { + optionsReferenceValue = "#options"; + optionsReference.setReference(optionsReferenceValue); + } + Parameters optionsParameters = (Parameters)sourceLibrary.getContained(optionsReferenceValue); + if (optionsParameters == null) { + optionsParameters = new Parameters(); + optionsParameters.setId(optionsReferenceValue.substring(1)); + sourceLibrary.addContained(optionsParameters); + } + optionsParameters.getParameter().clear(); + + optionsParameters.addParameter("translatorVersion", CqlTranslator.class.getPackage().getImplementationVersion()); + + var compilerOptions = options.getCqlCompilerOptions(); + for (CqlCompilerOptions.Options o : compilerOptions.getOptions()) { + optionsParameters.addParameter("option", o.name()); + } + for (CqlTranslatorOptions.Format f : options.getFormats()) { + optionsParameters.addParameter("format", f.name()); + } + optionsParameters.addParameter("analyzeDataRequirements", compilerOptions.getAnalyzeDataRequirements()); + optionsParameters.addParameter("collapseDataRequirements", compilerOptions.getCollapseDataRequirements()); + if (compilerOptions.getCompatibilityLevel() != null) { + optionsParameters.addParameter("compatibilityLevel", compilerOptions.getCompatibilityLevel()); + } + optionsParameters.addParameter("enableCqlOnly", compilerOptions.getEnableCqlOnly()); + optionsParameters.addParameter("errorLevel", compilerOptions.getErrorLevel().name()); + optionsParameters.addParameter("signatureLevel", compilerOptions.getSignatureLevel().name()); + optionsParameters.addParameter("validateUnits", compilerOptions.getValidateUnits()); + optionsParameters.addParameter("verifyOnly", compilerOptions.getVerifyOnly()); + } + protected List refreshGeneratedContent(List sourceLibraries) { return internalRefreshGeneratedContent(sourceLibraries); } diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/utilities/IOUtils.java b/tooling/src/main/java/org/opencds/cqf/tooling/utilities/IOUtils.java index 27582d967..779caa4bd 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/utilities/IOUtils.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/utilities/IOUtils.java @@ -1091,6 +1091,10 @@ public static String concatFilePath(String basePath, String... pathsToAppend) { return filePath; } + + /** + * Cleans up cached data to ensure a clean state for subsequent ci tests. + */ public static void cleanUp(){ alreadyCopied = new HashMap<>(); cachedResources = new LinkedHashMap(); diff --git a/tooling/src/test/java/org/opencds/cqf/tooling/processor/IGProcessorTest.java b/tooling/src/test/java/org/opencds/cqf/tooling/processor/IGProcessorTest.java index ff8aa4592..7f9857202 100644 --- a/tooling/src/test/java/org/opencds/cqf/tooling/processor/IGProcessorTest.java +++ b/tooling/src/test/java/org/opencds/cqf/tooling/processor/IGProcessorTest.java @@ -217,4 +217,4 @@ private String getFhirVersion(IniFile ini) { } return specifiedFhirVersion; } -} \ No newline at end of file +}