Skip to content

Commit

Permalink
#445: Added cqlOptions extension support to the LibraryProcessor refr… (
Browse files Browse the repository at this point in the history
#446)

* #445: Added cqlOptions extension support to the LibraryProcessor refresh logic

* Fix up options

---------

Co-authored-by: JP <[email protected]>
  • Loading branch information
brynrhodes and JPercival authored Nov 28, 2023
1 parent 8b356fd commit fa035c9
Showing 1 changed file with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,41 @@
import java.util.Map;
import java.util.regex.Pattern;

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.Attachment;
import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.Attachment;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.Library;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.RelatedArtifact;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.opencds.cqf.tooling.library.r4.R4LibraryProcessor;
import org.opencds.cqf.tooling.library.stu3.STU3LibraryProcessor;
import org.opencds.cqf.tooling.parameter.RefreshLibraryParameters;
import org.opencds.cqf.tooling.processor.*;
import org.opencds.cqf.tooling.processor.BaseProcessor;
import org.opencds.cqf.tooling.processor.CqlProcessor;
import org.opencds.cqf.tooling.processor.IGProcessor;
import org.opencds.cqf.tooling.utilities.IOUtils;
import org.opencds.cqf.tooling.utilities.IOUtils.Encoding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opencds.cqf.tooling.utilities.LogUtils;
import org.opencds.cqf.tooling.utilities.ResourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;

import ca.uhn.fhir.context.FhirContext;

public class LibraryProcessor extends BaseProcessor {
private static final Logger logger = LoggerFactory.getLogger(LibraryProcessor.class);
public static final String ResourcePrefix = "library-";
public static final String ResourcePrefix = "library-";
public static String getId(String baseId) {
return ResourcePrefix + baseId;
}
Expand All @@ -52,7 +60,7 @@ public static void validateIdAlphaNumeric(String id) {
throw new RuntimeException("The library id format is invalid.");
}
}

public List<String> refreshIgLibraryContent(BaseProcessor parentContext, Encoding outputEncoding, Boolean versioned, FhirContext fhirContext, Boolean shouldApplySoftwareSystemStamp) {
return refreshIgLibraryContent(parentContext, outputEncoding, null, versioned, fhirContext, shouldApplySoftwareSystemStamp);
}
Expand Down Expand Up @@ -162,6 +170,8 @@ 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 %s", fileName));
//f.getErrors().add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTFOUND, "Library", "No cql info found for "+f.getName(), ValidationMessage.IssueSeverity.ERROR));
Expand All @@ -171,6 +181,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<Library> refreshGeneratedContent(List<Library> sourceLibraries) {
return internalRefreshGeneratedContent(sourceLibraries);
}
Expand Down

0 comments on commit fa035c9

Please sign in to comment.