Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into rel-3.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Dec 20, 2024
2 parents 028ab88 + b9f7ad3 commit d49f1ac
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 121 deletions.
10 changes: 0 additions & 10 deletions Src/cql-lm/schema/elm/expression.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@
<xs:complexContent>
<xs:extension base="Element">
<xs:sequence>
<xs:element name="type" type="TypeSpecifier" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation>This element is deprecated. New implementations should use the new elementType element.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="elementType" type="TypeSpecifier" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
Expand All @@ -118,11 +113,6 @@
<xs:complexContent>
<xs:extension base="TypeSpecifier">
<xs:sequence>
<xs:element name="type" type="TypeSpecifier" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>This element is deprecated. New implementations should use the new choice element.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="choice" type="TypeSpecifier" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ public TupleElementDefinition visitTupleElementDefinition(cqlParser.TupleElement
.withName(parseString(ctx.referentialIdentifier()))
.withElementType(parseTypeSpecifier(ctx.typeSpecifier()));

if (getIncludeDeprecatedElements()) {
result.setType(result.getElementType());
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ public Library run(CharStream is) {
var edits = allNonNull(
!options.contains(EnableAnnotations) ? ElmEdit.REMOVE_ANNOTATION : null,
!options.contains(EnableResultTypes) ? ElmEdit.REMOVE_RESULT_TYPE : null,
!options.contains(EnableLocators) ? ElmEdit.REMOVE_LOCATOR : null,
ElmEdit.REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY);
!options.contains(EnableLocators) ? ElmEdit.REMOVE_LOCATOR : null);

new ElmEditor(edits).edit(library);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum Options {
private boolean enableCqlOnly = false;
private String compatibilityLevel = "1.5";
private CqlCompilerException.ErrorSeverity errorLevel = CqlCompilerException.ErrorSeverity.Info;
private LibraryBuilder.SignatureLevel signatureLevel = LibraryBuilder.SignatureLevel.None;
private LibraryBuilder.SignatureLevel signatureLevel = LibraryBuilder.SignatureLevel.Overloads;
private boolean analyzeDataRequirements = false;
private boolean collapseDataRequirements = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cqframework.cql.cql2elm.elm;

import org.hl7.cql_annotations.r1.Annotation;
import org.hl7.elm.r1.ChoiceTypeSpecifier;
import org.hl7.elm.r1.Element;

public enum ElmEdit implements IElmEdit {
Expand Down Expand Up @@ -39,24 +38,5 @@ public void edit(Element element) {
element.setResultTypeName(null);
element.setResultTypeSpecifier(null);
}
},
REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY {
// The ChoiceTypeSpecifier ELM node has a deprecated `type` element which, if not null, clashes with the
// `"type" : "ChoiceTypeSpecifier"` field in the JSON serialization of the node. This does not happen in the XML
// serialization which nests <type> tags inside <ChoiceTypeSpecifier>.
// Because the `type` element is deprecated, it is not normally populated by the compiler anymore and
// stays null in the ChoiceTypeSpecifier instance. It is however set to an empty list if you just call
// ChoiceTypeSpecifier.getType() (which we do during the ELM optimization stage in the compiler), so
// this edit is needed to "protect" the downstream JSON serialization if it can be done without data loss.

@Override
public void edit(Element element) {
if (element instanceof ChoiceTypeSpecifier) {
var choice = (ChoiceTypeSpecifier) element;
if (choice.getType().isEmpty()) {
choice.setType(null);
}
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class CqlPreprocessorElmCommonVisitor extends cqlBaseVisitor<Object> {
private boolean fromKeywordRequired = false;

private final List<Expression> expressions = new ArrayList<>();
private boolean includeDeprecatedElements = false;

public CqlPreprocessorElmCommonVisitor(LibraryBuilder libraryBuilder, TokenStream tokenStream) {
this.libraryBuilder = Objects.requireNonNull(libraryBuilder, "libraryBuilder required");
Expand Down Expand Up @@ -152,10 +151,6 @@ public TupleElementDefinition visitTupleElementDefinition(cqlParser.TupleElement
.withName(parseString(ctx.referentialIdentifier()))
.withElementType(parseTypeSpecifier(ctx.typeSpecifier()));

if (includeDeprecatedElements) {
result.setType(result.getElementType());
}

return result;
}

Expand Down Expand Up @@ -185,9 +180,6 @@ public ChoiceTypeSpecifier visitChoiceTypeSpecifier(cqlParser.ChoiceTypeSpecifie
types.add(typeSpecifier.getResultType());
}
ChoiceTypeSpecifier result = of.createChoiceTypeSpecifier().withChoice(typeSpecifiers);
if (includeDeprecatedElements) {
result.getType().addAll(typeSpecifiers);
}
ChoiceType choiceType = new ChoiceType(types);
result.setResultType(choiceType);
return result;
Expand Down Expand Up @@ -884,14 +876,6 @@ public void disableFromKeywordRequired() {
fromKeywordRequired = false;
}

public boolean getIncludeDeprecatedElements() {
return includeDeprecatedElements;
}

public void setIncludeDeprecatedElements(boolean includeDeprecatedElements) {
this.includeDeprecatedElements = includeDeprecatedElements;
}

private void setCompilerOptions(CqlCompilerOptions options) {
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableDateRangeOptimization)) {
this.enableDateRangeOptimization();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"options":["EnableAnnotations","EnableLocators","DisableListDemotion","DisableListPromotion"],"formats":[ "XML"],"validateUnits":true,"verifyOnly":false,"errorLevel":"Info","signatureLevel":"None"}
{"options":["EnableAnnotations","EnableLocators","DisableListDemotion","DisableListPromotion"],"formats":[ "XML"],"validateUnits":true,"verifyOnly":false,"errorLevel":"Info","signatureLevel":"Overloads"}
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public boolean typeSpecifiersEqual(TypeSpecifier left, TypeSpecifier right) {
leftArg.getElement().get(i);
TupleElementDefinition rightElement =
rightArg.getElement().get(i);
if (!typeSpecifiersEqual(leftElement.getType(), rightElement.getType())
|| !typeSpecifiersEqual(leftElement.getElementType(), rightElement.getElementType())
if (!typeSpecifiersEqual(leftElement.getElementType(), rightElement.getElementType())
|| !stringsEqual(leftElement.getName(), rightElement.getName())) {
return false;
}
Expand All @@ -181,12 +180,12 @@ public boolean typeSpecifiersEqual(TypeSpecifier left, TypeSpecifier right) {
if (right instanceof ChoiceTypeSpecifier) {
ChoiceTypeSpecifier leftArg = (ChoiceTypeSpecifier) left;
ChoiceTypeSpecifier rightArg = (ChoiceTypeSpecifier) right;
if (leftArg.getType() != null
&& rightArg.getType() != null
&& leftArg.getType().size() == rightArg.getType().size()) {
for (int i = 0; i < leftArg.getType().size(); i++) {
TypeSpecifier leftType = leftArg.getType().get(i);
TypeSpecifier rightType = rightArg.getType().get(i);
if (leftArg.getChoice() != null
&& rightArg.getChoice() != null
&& leftArg.getChoice().size() == rightArg.getChoice().size()) {
for (int i = 0; i < leftArg.getChoice().size(); i++) {
TypeSpecifier leftType = leftArg.getChoice().get(i);
TypeSpecifier rightType = rightArg.getChoice().get(i);
if (!typeSpecifiersEqual(leftType, rightType)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ public T visitTupleElementDefinition(TupleElementDefinition elm, C context) {
result = aggregateResult(result, childResult);
}

if (elm.getType() != null) {
T childResult = visitTypeSpecifier(elm.getType(), context);
result = aggregateResult(result, childResult);
}

return result;
}

Expand Down Expand Up @@ -220,11 +215,6 @@ public T visitChoiceTypeSpecifier(ChoiceTypeSpecifier elm, C context) {
result = aggregateResult(result, childResult);
}

for (var type : elm.getType()) {
T childResult = visitTypeSpecifier(type, context);
result = aggregateResult(result, childResult);
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,32 @@
class TestFHIRHelpers extends FhirExecutionTestBase {

@Test
void testWithUnambiguousCompilerOptions() {
// Test with non-ambiguous compiler options. Should pass.
void testWithAmbiguousCompilerOptions() {
// This tests the behavior of the engine when the compiler
// options are set to allow ambiguous overloads
// It's expected that the engine will throw an exception
//
// If we update the FHIRHelpers content to not have ambiguous overloads
// the results of this test will change
var compilerOptions = CqlCompilerOptions.defaultOptions();
compilerOptions.setSignatureLevel(LibraryBuilder.SignatureLevel.Overloads);
compilerOptions.setSignatureLevel(LibraryBuilder.SignatureLevel.None);
var modelManager = new ModelManager();
var libraryManager = new LibraryManager(modelManager, compilerOptions);
libraryManager.getLibrarySourceLoader().clearProviders();
libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider());
libraryManager.getLibrarySourceLoader().registerProvider(new TestLibrarySourceProvider());

var engine = new CqlEngine(new Environment(libraryManager));
engine.getEnvironment().registerDataProvider("http://hl7.org/fhir", r4Provider);
var badOptionsEngine = new CqlEngine(new Environment(libraryManager));
badOptionsEngine.getEnvironment().registerDataProvider("http://hl7.org/fhir", r4Provider);

runTest(engine);
var identifier = library.getIdentifier();
assertThrows(CqlException.class, () -> badOptionsEngine.evaluate(identifier));
}

@Test
void standardCompilerOptions() {
// Test with standard compiler options. Should throw an Exception as of the
// time this test is written because the default compiler options produce
// ambiguous ELM output. This test is intended to fail, and if we change the
// compiler options to be non-ambiguous, this test should be updated to expect
// a different (presumably passing) result.
void testFhirHelpers() {
var engine = getEngine();
engine.getEnvironment().registerDataProvider("http://hl7.org/fhir", r4Provider);
assertThrows(CqlException.class, () -> runTest(engine));
}

void runTest(CqlEngine engine) {
var results = engine.evaluate(library.getIdentifier());

// Primitives
Expand Down
2 changes: 1 addition & 1 deletion Src/java/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx4096m
systemProp.sonar.gradle.skipCompile=true

group=info.cqframework
version=3.20.1
version=3.21.0-SNAPSHOT
specification.version=1.5.2
hapi.version=7.4.5
jackson.version=2.17.1
Expand Down

0 comments on commit d49f1ac

Please sign in to comment.