From 12f59f3813fa9f9930ed43592551915a29364b3f Mon Sep 17 00:00:00 2001 From: JP Date: Fri, 20 Dec 2024 13:53:00 -0700 Subject: [PATCH] Remove type from TupleTypeElement and ChoiceType, which were deprecated (#1482) --- Src/cql-lm/schema/elm/expression.xsd | 10 ------ .../cql/cql2elm/Cql2ElmVisitor.java | 4 --- .../cqframework/cql/cql2elm/CqlCompiler.java | 3 +- .../cqframework/cql/cql2elm/elm/ElmEdit.java | 20 ------------ .../CqlPreprocessorElmCommonVisitor.java | 16 ---------- .../cql/cql2elm/elm/ElmEditTest.java | 32 ------------------- .../cql/elm/evaluating/SimpleElmEngine.java | 15 ++++----- .../cql/elm/visiting/BaseElmVisitor.java | 10 ------ 8 files changed, 8 insertions(+), 102 deletions(-) delete mode 100644 Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/elm/ElmEditTest.java 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/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/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; }