diff --git a/Src/cql-lm/schema/elm/expression.xsd b/Src/cql-lm/schema/elm/expression.xsd index e730908ed..512b612be 100644 --- a/Src/cql-lm/schema/elm/expression.xsd +++ b/Src/cql-lm/schema/elm/expression.xsd @@ -88,11 +88,6 @@ - - - This element is deprecated. New implementations should use the new elementType element. - - @@ -118,11 +113,6 @@ - - - This element is deprecated. New implementations should use the new choice element. - - diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java index bd268f547..ed3fe9bb7 100755 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java @@ -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; } diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompiler.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompiler.java index a99fbbac6..32624d4a9 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompiler.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompiler.java @@ -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); diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java index 11bae46ce..27f179744 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java @@ -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; diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/elm/ElmEdit.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/elm/ElmEdit.java index 81212314d..34ce11dd0 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/elm/ElmEdit.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/elm/ElmEdit.java @@ -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 { @@ -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 tags inside . - // 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); - } - } - } }; } diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.java index 4c3f7d1a7..1267eb049 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.java @@ -50,7 +50,6 @@ public class CqlPreprocessorElmCommonVisitor extends cqlBaseVisitor { private boolean fromKeywordRequired = false; private final List expressions = new ArrayList<>(); - private boolean includeDeprecatedElements = false; public CqlPreprocessorElmCommonVisitor(LibraryBuilder libraryBuilder, TokenStream tokenStream) { this.libraryBuilder = Objects.requireNonNull(libraryBuilder, "libraryBuilder required"); @@ -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; } @@ -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; @@ -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(); diff --git a/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/elm/ElmEditTest.java b/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/elm/ElmEditTest.java deleted file mode 100644 index b86a8b878..000000000 --- a/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/elm/ElmEditTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.cqframework.cql.cql2elm.elm; - -import static org.junit.jupiter.api.Assertions.*; - -import java.util.List; -import org.hl7.elm.r1.ChoiceTypeSpecifier; -import org.hl7.elm.r1.NamedTypeSpecifier; -import org.hl7.elm.r1.TypeSpecifier; -import org.junit.jupiter.api.Test; - -class ElmEditTest { - - @Test - void removeChoiceTypeSpecifierTypeIfEmpty() { - var extChoiceTypeSpecifier = new ExtChoiceTypeSpecifier(); - - extChoiceTypeSpecifier.setType(List.of()); - ElmEdit.REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY.edit(extChoiceTypeSpecifier); - assertNull(extChoiceTypeSpecifier.getType()); - - var typeSpecifiers = List.of((TypeSpecifier) new NamedTypeSpecifier()); - extChoiceTypeSpecifier.setType(typeSpecifiers); - ElmEdit.REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY.edit(extChoiceTypeSpecifier); - assertSame(typeSpecifiers, extChoiceTypeSpecifier.getType()); - } - - private static class ExtChoiceTypeSpecifier extends ChoiceTypeSpecifier { - public List getType() { - return type; - } - } -} diff --git a/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json b/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json index 1834225ea..83c1d815a 100644 --- a/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json +++ b/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json @@ -1 +1 @@ -{"options":["EnableAnnotations","EnableLocators","DisableListDemotion","DisableListPromotion"],"formats":[ "XML"],"validateUnits":true,"verifyOnly":false,"errorLevel":"Info","signatureLevel":"None"} \ No newline at end of file +{"options":["EnableAnnotations","EnableLocators","DisableListDemotion","DisableListPromotion"],"formats":[ "XML"],"validateUnits":true,"verifyOnly":false,"errorLevel":"Info","signatureLevel":"Overloads"} \ No newline at end of file diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java index f096303cd..1c8074d37 100644 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java @@ -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; } @@ -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; } diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java index e4cec60ad..835275ae9 100644 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java @@ -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; } @@ -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; } diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java index ed88db13f..0dc4fe0c0 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java @@ -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 diff --git a/Src/java/gradle.properties b/Src/java/gradle.properties index 1659570e3..c31cde98d 100644 --- a/Src/java/gradle.properties +++ b/Src/java/gradle.properties @@ -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