Cql2ElmVisitor extends cqlBaseVisitor { @Override public Object visitLibrary(@NotNull cqlParser.LibraryContext ctx) { Object lastResult = null; VersionedIdentifier identifier = new VersionedIdentifier().withId(libraryInfo.getLibraryName()).withVersion(libraryInfo.getVersion()); if (libraryInfo.getNamespaceName() != null) { identifier.setSystem(libraryBuilder.resolveNamespaceUri(libraryInfo.getNamespaceName(), true)); } else if (libraryBuilder.getNamespaceInfo() != null) { identifier.setSystem(libraryBuilder.getNamespaceInfo().getUri()); } libraryBuilder.setLibraryIdentifier(identifier); libraryBuilder.beginTranslation(); try { for (int i = 0; i < ctx.getChildCount(); i++) { ParseTree tree = ctx.getChild(i); TerminalNode terminalNode = tree instanceof TerminalNode ? (TerminalNode)tree : null; if (terminalNode != null && terminalNode.getSymbol().getType() == cqlLexer.EOF) { continue; } Object childResult = visit(tree); if (childResult != null) { lastResult = childResult; } } return lastResult; } finally { libraryBuilder.endTranslation(); } } Cql2ElmVisitor(LibraryBuilder libraryBuilder); void setLibraryInfo(LibraryInfo libraryInfo); void enableAnnotations(); void disableAnnotations(); void enableLocators(); void disableLocators(); void enableResultTypes(); void disableResultTypes(); void enableDateRangeOptimization(); void disableDateRangeOptimization(); boolean getDateRangeOptimization(); void enableDetailedErrors(); void disableDetailedErrors(); boolean isDetailedErrorsEnabled(); void enableMethodInvocation(); void disableMethodInvocation(); boolean isFromKeywordRequired(); void enableFromKeywordRequired(); void disableFromKeywordRequired(); boolean isCompatibilityLevel3(); boolean isCompatibilityLevel4(); String getCompatibilityLevel(); void setCompatibilityLevel(String compatibilityLevel); void setTranslatorOptions(CqlTranslatorOptions options); TokenStream getTokenStream(); void setTokenStream(TokenStream value); List<Retrieve> getRetrieves(); List<Expression> getExpressions(); @Override Object visit(@NotNull ParseTree tree); @Override Object visitLibrary(@NotNull cqlParser.LibraryContext ctx); @Override @SuppressWarnings("unchecked") VersionedIdentifier visitLibraryDefinition(@NotNull cqlParser.LibraryDefinitionContext ctx); @Override UsingDef visitUsingDefinition(@NotNull cqlParser.UsingDefinitionContext ctx); Model getModel(); Model getModel(String modelName); Model getModel(String modelName, String version); @Override @SuppressWarnings("unchecked") Object visitIncludeDefinition(@NotNull cqlParser.IncludeDefinitionContext ctx); @Override ParameterDef visitParameterDefinition(@NotNull cqlParser.ParameterDefinitionContext ctx); @Override NamedTypeSpecifier visitNamedTypeSpecifier(@NotNull cqlParser.NamedTypeSpecifierContext ctx); @Override TupleElementDefinition visitTupleElementDefinition(@NotNull cqlParser.TupleElementDefinitionContext ctx); @Override Object visitTupleTypeSpecifier(@NotNull cqlParser.TupleTypeSpecifierContext ctx); @Override ChoiceTypeSpecifier visitChoiceTypeSpecifier(@NotNull cqlParser.ChoiceTypeSpecifierContext ctx); @Override IntervalTypeSpecifier visitIntervalTypeSpecifier(@NotNull cqlParser.IntervalTypeSpecifierContext ctx); @Override ListTypeSpecifier visitListTypeSpecifier(@NotNull cqlParser.ListTypeSpecifierContext ctx); @Override AccessModifier visitAccessModifier(@NotNull cqlParser.AccessModifierContext ctx); @Override CodeSystemDef visitCodesystemDefinition(@NotNull cqlParser.CodesystemDefinitionContext ctx); @Override CodeSystemRef visitCodesystemIdentifier(@NotNull cqlParser.CodesystemIdentifierContext ctx); @Override CodeRef visitCodeIdentifier(@NotNull cqlParser.CodeIdentifierContext ctx); @Override ValueSetDef visitValuesetDefinition(@NotNull cqlParser.ValuesetDefinitionContext ctx); @Override CodeDef visitCodeDefinition(@NotNull cqlParser.CodeDefinitionContext ctx); @Override ConceptDef visitConceptDefinition(@NotNull cqlParser.ConceptDefinitionContext ctx); @Override Object visitContextDefinition(@NotNull cqlParser.ContextDefinitionContext ctx); ExpressionDef internalVisitExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionContext ctx); @Override ExpressionDef visitExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionContext ctx); @Override Literal visitStringLiteral(@NotNull cqlParser.StringLiteralContext ctx); @Override Literal visitSimpleStringLiteral(@NotNull cqlParser.SimpleStringLiteralContext ctx); @Override Literal visitBooleanLiteral(@NotNull cqlParser.BooleanLiteralContext ctx); @Override Object visitIntervalSelector(@NotNull cqlParser.IntervalSelectorContext ctx); @Override Object visitTupleElementSelector(@NotNull cqlParser.TupleElementSelectorContext ctx); @Override Object visitTupleSelector(@NotNull cqlParser.TupleSelectorContext ctx); @Override Object visitInstanceElementSelector(@NotNull cqlParser.InstanceElementSelectorContext ctx); @Override Object visitInstanceSelector(@NotNull cqlParser.InstanceSelectorContext ctx); @Override Object visitCodeSelector(@NotNull cqlParser.CodeSelectorContext ctx); @Override Object visitConceptSelector(@NotNull cqlParser.ConceptSelectorContext ctx); @Override Object visitListSelector(@NotNull cqlParser.ListSelectorContext ctx); @Override Object visitTimeLiteral(@NotNull cqlParser.TimeLiteralContext ctx); @Override Object visitDateLiteral(@NotNull cqlParser.DateLiteralContext ctx); @Override Object visitDateTimeLiteral(@NotNull cqlParser.DateTimeLiteralContext ctx); @Override Null visitNullLiteral(@NotNull cqlParser.NullLiteralContext ctx); @Override Expression visitNumberLiteral(@NotNull cqlParser.NumberLiteralContext ctx); @Override Expression visitSimpleNumberLiteral(@NotNull cqlParser.SimpleNumberLiteralContext ctx); @Override Literal visitLongNumberLiteral(@NotNull cqlParser.LongNumberLiteralContext ctx); @Override Expression visitQuantity(@NotNull cqlParser.QuantityContext ctx); @Override Expression visitRatio(@NotNull cqlParser.RatioContext ctx); @Override Not visitNotExpression(@NotNull cqlParser.NotExpressionContext ctx); @Override Exists visitExistenceExpression(@NotNull cqlParser.ExistenceExpressionContext ctx); @Override BinaryExpression visitMultiplicationExpressionTerm(@NotNull cqlParser.MultiplicationExpressionTermContext ctx); @Override Power visitPowerExpressionTerm(@NotNull cqlParser.PowerExpressionTermContext ctx); @Override Object visitPolarityExpressionTerm(@NotNull cqlParser.PolarityExpressionTermContext ctx); @Override Expression visitAdditionExpressionTerm(@NotNull cqlParser.AdditionExpressionTermContext ctx); @Override Object visitPredecessorExpressionTerm(@NotNull cqlParser.PredecessorExpressionTermContext ctx); @Override Object visitSuccessorExpressionTerm(@NotNull cqlParser.SuccessorExpressionTermContext ctx); @Override Object visitElementExtractorExpressionTerm(@NotNull cqlParser.ElementExtractorExpressionTermContext ctx); @Override Object visitPointExtractorExpressionTerm(@NotNull cqlParser.PointExtractorExpressionTermContext ctx); @Override Object visitTypeExtentExpressionTerm(@NotNull cqlParser.TypeExtentExpressionTermContext ctx); @Override Object visitTimeBoundaryExpressionTerm(@NotNull cqlParser.TimeBoundaryExpressionTermContext ctx); @Override Object visitTimeUnitExpressionTerm(@NotNull cqlParser.TimeUnitExpressionTermContext ctx); @Override Object visitDurationExpressionTerm(@NotNull cqlParser.DurationExpressionTermContext ctx); @Override Object visitDifferenceExpressionTerm(@NotNull cqlParser.DifferenceExpressionTermContext ctx); @Override Object visitBetweenExpression(@NotNull cqlParser.BetweenExpressionContext ctx); @Override Object visitDurationBetweenExpression(@NotNull cqlParser.DurationBetweenExpressionContext ctx); @Override Object visitDifferenceBetweenExpression(@NotNull cqlParser.DifferenceBetweenExpressionContext ctx); @Override Object visitWidthExpressionTerm(@NotNull cqlParser.WidthExpressionTermContext ctx); @Override Expression visitParenthesizedTerm(@NotNull cqlParser.ParenthesizedTermContext ctx); @Override Object visitMembershipExpression(@NotNull cqlParser.MembershipExpressionContext ctx); @Override And visitAndExpression(@NotNull cqlParser.AndExpressionContext ctx); @Override Expression visitOrExpression(@NotNull cqlParser.OrExpressionContext ctx); @Override Expression visitImpliesExpression(@NotNull cqlParser.ImpliesExpressionContext ctx); @Override Object visitInFixSetExpression(@NotNull cqlParser.InFixSetExpressionContext ctx); @Override Expression visitEqualityExpression(@NotNull cqlParser.EqualityExpressionContext ctx); @Override BinaryExpression visitInequalityExpression(@NotNull cqlParser.InequalityExpressionContext ctx); @Override List<String> visitQualifiedIdentifier(@NotNull cqlParser.QualifiedIdentifierContext ctx); @Override List<String> visitQualifiedIdentifierExpression(@NotNull cqlParser.QualifiedIdentifierExpressionContext ctx); @Override String visitSimplePathReferentialIdentifier(@NotNull cqlParser.SimplePathReferentialIdentifierContext ctx); @Override String visitSimplePathQualifiedIdentifier(@NotNull cqlParser.SimplePathQualifiedIdentifierContext ctx); @Override String visitSimplePathIndexer(@NotNull cqlParser.SimplePathIndexerContext ctx); @Override Object visitTermExpression(@NotNull cqlParser.TermExpressionContext ctx); @Override Object visitTerminal(@NotNull TerminalNode node); @Override Object visitConversionExpressionTerm(@NotNull cqlParser.ConversionExpressionTermContext ctx); @Override Object visitTypeExpression(@NotNull cqlParser.TypeExpressionContext ctx); @Override Object visitCastExpression(@NotNull cqlParser.CastExpressionContext ctx); @Override Expression visitBooleanExpression(@NotNull cqlParser.BooleanExpressionContext ctx); @Override Object visitTimingExpression(@NotNull cqlParser.TimingExpressionContext ctx); @Override Object visitConcurrentWithIntervalOperatorPhrase(@NotNull cqlParser.ConcurrentWithIntervalOperatorPhraseContext ctx); @Override Object visitIncludesIntervalOperatorPhrase(@NotNull cqlParser.IncludesIntervalOperatorPhraseContext ctx); @Override Object visitIncludedInIntervalOperatorPhrase(@NotNull cqlParser.IncludedInIntervalOperatorPhraseContext ctx); @Override Object visitBeforeOrAfterIntervalOperatorPhrase(@NotNull cqlParser.BeforeOrAfterIntervalOperatorPhraseContext ctx); @Override Object visitWithinIntervalOperatorPhrase(@NotNull cqlParser.WithinIntervalOperatorPhraseContext ctx); @Override Object visitMeetsIntervalOperatorPhrase(@NotNull cqlParser.MeetsIntervalOperatorPhraseContext ctx); @Override Object visitOverlapsIntervalOperatorPhrase(@NotNull cqlParser.OverlapsIntervalOperatorPhraseContext ctx); @Override Object visitStartsIntervalOperatorPhrase(@NotNull cqlParser.StartsIntervalOperatorPhraseContext ctx); @Override Object visitEndsIntervalOperatorPhrase(@NotNull cqlParser.EndsIntervalOperatorPhraseContext ctx); Expression resolveIfThenElse(If ifObject); @Override Object visitIfThenElseExpressionTerm(@NotNull cqlParser.IfThenElseExpressionTermContext ctx); @Override Object visitCaseExpressionTerm(@NotNull cqlParser.CaseExpressionTermContext ctx); @Override Object visitCaseExpressionItem(@NotNull cqlParser.CaseExpressionItemContext ctx); @Override Object visitAggregateExpressionTerm(@NotNull cqlParser.AggregateExpressionTermContext ctx); @Override Object visitSetAggregateExpressionTerm(@NotNull cqlParser.SetAggregateExpressionTermContext ctx); @Override @SuppressWarnings("unchecked") Retrieve visitRetrieve(@NotNull cqlParser.RetrieveContext ctx); @Override Object visitSourceClause(@NotNull cqlParser.SourceClauseContext ctx); @Override @SuppressWarnings("unchecked") Object visitQuery(@NotNull cqlParser.QueryContext ctx); Expression optimizeDateRangeInQuery(Expression where, AliasedQuerySource aqs); @Override Object visitLetClause(@NotNull cqlParser.LetClauseContext ctx); @Override Object visitLetClauseItem(@NotNull cqlParser.LetClauseItemContext ctx); @Override Object visitAliasedQuerySource(@NotNull cqlParser.AliasedQuerySourceContext ctx); @Override Object visitWithClause(@NotNull cqlParser.WithClauseContext ctx); @Override Object visitWithoutClause(@NotNull cqlParser.WithoutClauseContext ctx); @Override Object visitWhereClause(@NotNull cqlParser.WhereClauseContext ctx); @Override Object visitReturnClause(@NotNull cqlParser.ReturnClauseContext ctx); @Override Object visitStartingClause(@NotNull cqlParser.StartingClauseContext ctx); @Override Object visitAggregateClause(@NotNull cqlParser.AggregateClauseContext ctx); @Override SortDirection visitSortDirection(@NotNull cqlParser.SortDirectionContext ctx); @Override SortByItem visitSortByItem(@NotNull cqlParser.SortByItemContext ctx); @Override Object visitSortClause(@NotNull cqlParser.SortClauseContext ctx); @Override @SuppressWarnings("unchecked") Object visitQuerySource(@NotNull cqlParser.QuerySourceContext ctx); @Override Object visitIndexedExpressionTerm(@NotNull cqlParser.IndexedExpressionTermContext ctx); @Override Expression visitInvocationExpressionTerm(@NotNull cqlParser.InvocationExpressionTermContext ctx); @Override Expression visitExternalConstant(@NotNull cqlParser.ExternalConstantContext ctx); @Override Expression visitThisInvocation(@NotNull cqlParser.ThisInvocationContext ctx); @Override Expression visitMemberInvocation(@NotNull cqlParser.MemberInvocationContext ctx); @Override Expression visitQualifiedMemberInvocation(@NotNull cqlParser.QualifiedMemberInvocationContext ctx); Expression resolveQualifiedIdentifier(List<String> identifiers); Expression resolveMemberIdentifier(String identifier); Expression resolveFunctionOrQualifiedFunction(@NotNull String identifier, cqlParser.ParamListContext paramListCtx); @Override Expression visitFunction(@NotNull cqlParser.FunctionContext ctx); @Override Expression visitQualifiedFunction(@NotNull cqlParser.QualifiedFunctionContext ctx); @Override Object visitFunctionBody(@NotNull cqlParser.FunctionBodyContext ctx); Object internalVisitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx); @Override Object visitFunctionDefinition(@NotNull cqlParser.FunctionDefinitionContext ctx); String parseString(ParseTree pt);  }
@Test public void testBasicValueSet() { String cql = "valueset \"Female Administrative Sex\" : '2.16.840.1.113883.3.560.100.2'\n" + "define X : 1"; Library l = visitLibrary(cql); ValueSetDef def = l.getValueSets().getDef().get(0); assertThat(def.getName(), is("Female Administrative Sex")); assertThat(def.getId(), is("2.16.840.1.113883.3.560.100.2")); assertThat(def.getVersion(), is(nullValue())); assertThat(def.getCodeSystem().size(), is(0)); }
@Test public void testVersionedValueSet() { String cql = "valueset \"Female Administrative Sex\" : '2.16.840.1.113883.3.560.100.2' version '1'\n" + "define X : 1"; Library l = visitLibrary(cql); ValueSetDef def = l.getValueSets().getDef().get(0); assertThat(def.getName(), is("Female Administrative Sex")); assertThat(def.getId(), is("2.16.840.1.113883.3.560.100.2")); assertThat(def.getVersion(), is("1")); assertThat(def.getCodeSystem().size(), is(0)); }
@Test public void testStaticallyBoundValueSet() { String cql = "codesystem \"SNOMED-CT:2014\" : 'SNOMED-CT' version '2014'\n" + "codesystem \"ICD-9:2014\" : 'ICD-9' version '2014'\n" + "valueset \"Female Administrative Sex\" : '2.16.840.1.113883.3.560.100.2' version '1'\n" + " codesystems { \"SNOMED-CT:2014\", \"ICD-9:2014\" }\n" + "define X : 1"; Library l = visitLibrary(cql); ValueSetDef def = l.getValueSets().getDef().get(0); assertThat(def.getName(), is("Female Administrative Sex")); assertThat(def.getId(), is("2.16.840.1.113883.3.560.100.2")); assertThat(def.getVersion(), is("1")); assertThat(def.getCodeSystem(), is(not(nullValue()))); assertThat(def.getCodeSystem().size(), is(2)); CodeSystemRef r = def.getCodeSystem().get(0); assertThat(r.getName(), is("SNOMED-CT:2014")); assertThat(r.getLibraryName(), is(nullValue())); r = def.getCodeSystem().get(1); assertThat(r.getName(), is("ICD-9:2014")); assertThat(r.getLibraryName(), is(nullValue())); CodeSystemDef snomedCT = l.getCodeSystems().getDef().get(0); assertThat(snomedCT.getName(), is("SNOMED-CT:2014")); assertThat(snomedCT.getId(), is("SNOMED-CT")); assertThat(snomedCT.getVersion(), is("2014")); CodeSystemDef icd9 = l.getCodeSystems().getDef().get(1); assertThat(icd9.getName(), is("ICD-9:2014")); assertThat(icd9.getId(), is("ICD-9")); assertThat(icd9.getVersion(), is("2014")); }