From 9b36a3392b942f4ca736525b7f19a3c6299d2198 Mon Sep 17 00:00:00 2001 From: Greg Akins Date: Tue, 10 Sep 2024 12:07:57 -0400 Subject: [PATCH] MAT-7403: Segregating definitions by whether they're only in the local CQL, or included libraries --- pom.xml | 2 +- .../dto/CqlBuilderLookup.java | 3 +- .../utils/cql/parsing/Cql2ElmListener.java | 29 ++++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index ea7bcb3..0d348ac 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 gov.cms.madie madie-translator-commons - 0.0.3-cqframework3.14.0-SNAPSHOT + 0.0.5-SNAPSHOT UTF-8 17 diff --git a/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java b/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java index 55e3386..1c2633b 100644 --- a/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java +++ b/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java @@ -9,7 +9,8 @@ @Builder public class CqlBuilderLookup { private Set parameters; - private Set definitions; + private Set allDefinitions; + private Set localDefinitions; private Set functions; private Set fluentFunctions; diff --git a/src/main/java/gov/cms/madie/cql_elm_translator/utils/cql/parsing/Cql2ElmListener.java b/src/main/java/gov/cms/madie/cql_elm_translator/utils/cql/parsing/Cql2ElmListener.java index 55e45b8..079a1d3 100644 --- a/src/main/java/gov/cms/madie/cql_elm_translator/utils/cql/parsing/Cql2ElmListener.java +++ b/src/main/java/gov/cms/madie/cql_elm_translator/utils/cql/parsing/Cql2ElmListener.java @@ -18,7 +18,6 @@ import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.misc.Interval; -import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.apache.commons.collections4.CollectionUtils; @@ -59,6 +58,7 @@ import gov.cms.madie.cql_elm_translator.utils.cql.parsing.model.CQLValueSet; import gov.cms.madie.cql_elm_translator.utils.cql.parsing.model.DefinitionContent; import lombok.Getter; +import lombok.NonNull; @Slf4j public class Cql2ElmListener extends cqlBaseListener { @@ -228,7 +228,7 @@ public void enterReferentialIdentifier(ReferentialIdentifierContext ctx) { } @Override - public void enterQualifiedIdentifier(@NotNull cqlParser.QualifiedIdentifierContext ctx) { + public void enterQualifiedIdentifier(@NonNull cqlParser.QualifiedIdentifierContext ctx) { String identifier = parseString(ctx.identifier().getText()); String qualifier = ""; @@ -257,14 +257,14 @@ private boolean shouldResolve(String identifier) { } @Override - public void enterFunction(@NotNull cqlParser.FunctionContext ctx) { + public void enterFunction(@NonNull cqlParser.FunctionContext ctx) { String identifier = parseString(ctx.referentialIdentifier().getText()); resolve(identifier, getCurrentLibraryContext()); libraryAccessor = null; } @Override - public void enterExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionContext ctx) { + public void enterExpressionDefinition(@NonNull cqlParser.ExpressionDefinitionContext ctx) { String identifier = parseString(ctx.identifier().getText()); this.currentContext = libraryIdentifier + identifier; String content = @@ -277,8 +277,9 @@ public void enterExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionCon } @Override - public void enterFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx) { - String identifier = parseString(ctx.identifierOrFunctionIdentifier().getText()); + public void enterFunctionDefinition(@NonNull cqlParser.FunctionDefinitionContext ctx) { + String functionDef = ctx.identifierOrFunctionIdentifier().getText(); + String identifier = parseString(functionDef); this.currentContext = libraryIdentifier + identifier; for (cqlParser.OperandDefinitionContext operand : ctx.operandDefinition()) { namespace.push(operand.referentialIdentifier().getText()); @@ -299,7 +300,7 @@ public void enterFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext } @Override - public void exitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx) { + public void exitFunctionDefinition(@NonNull cqlParser.FunctionDefinitionContext ctx) { for (cqlParser.OperandDefinitionContext operand : ctx.operandDefinition()) { namespace.pop(); } @@ -345,14 +346,16 @@ private static String getFullText(ParserRuleContext context) { || context.stop.getStopIndex() < 0) { return context.getText(); } - return context - .start - .getInputStream() - .getText(Interval.of(context.start.getStartIndex(), context.stop.getStopIndex())); + String result = + context + .start + .getInputStream() + .getText(Interval.of(context.start.getStartIndex(), context.stop.getStopIndex())); + return result; } @Override - public void enterParameterDefinition(@NotNull cqlParser.ParameterDefinitionContext ctx) { + public void enterParameterDefinition(@NonNull cqlParser.ParameterDefinitionContext ctx) { String identifier = parseString(ctx.identifier().getText()); this.currentContext = libraryIdentifier + identifier; graph.addNode(currentContext); @@ -363,7 +366,7 @@ public void enterParameterDefinition(@NotNull cqlParser.ParameterDefinitionConte } @Override - public void enterRetrieve(@NotNull cqlParser.RetrieveContext ctx) { + public void enterRetrieve(@NonNull cqlParser.RetrieveContext ctx) { // we only care about entering a retrieve if it has a terminology if (ctx.terminology() == null || ctx.codePath() != null) {