Skip to content

Commit

Permalink
Code cleanup with fixed merge of LibraryProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Chicoine committed Nov 29, 2023
1 parent 3470423 commit c4946a6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"editor.formatOnSave": true
}
}
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,15 +208,57 @@ 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));
}
}

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<Library> refreshGeneratedContent(List<Library> sourceLibraries) {
return internalRefreshGeneratedContent(sourceLibraries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, IBaseResource>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,4 @@ private String getFhirVersion(IniFile ini) {
}
return specifiedFhirVersion;
}
}
}

0 comments on commit c4946a6

Please sign in to comment.