From 88df867e7ca9bb2e0ae98b10506ba1efdce8eb78 Mon Sep 17 00:00:00 2001 From: adongare Date: Tue, 23 May 2023 17:49:25 -0400 Subject: [PATCH 1/3] MAT-5567 get all the retrieves --- src/CqlAntlr.ts | 1 + src/CqlAntlrListener.ts | 13 +++++++++++++ src/CqlRetrieveCreator.ts | 17 +++++++++++++++++ src/dto/CqlResult.ts | 2 ++ src/dto/CqlRetrieve.ts | 6 ++++++ test/CqlAntlr.test.ts | 1 + 6 files changed, 40 insertions(+) create mode 100644 src/CqlRetrieveCreator.ts create mode 100644 src/dto/CqlRetrieve.ts diff --git a/src/CqlAntlr.ts b/src/CqlAntlr.ts index 77cbe30..a4fb3e7 100644 --- a/src/CqlAntlr.ts +++ b/src/CqlAntlr.ts @@ -35,6 +35,7 @@ class CqlAntlr { identifiers: [], expressionDefinitions: [], errors: [], + retrieves: [], }; } diff --git a/src/CqlAntlrListener.ts b/src/CqlAntlrListener.ts index c58cee6..4b20978 100644 --- a/src/CqlAntlrListener.ts +++ b/src/CqlAntlrListener.ts @@ -8,6 +8,7 @@ import { IncludeDefinitionContext, LibraryDefinitionContext, ParameterDefinitionContext, + RetrieveContext, UsingDefinitionContext, ValuesetDefinitionContext } from "../generated"; @@ -28,6 +29,8 @@ import CqlExpressionDefinitionCreator from "./CqlExpressionDefinitionCreator"; import {CqlCode} from "./dto"; import CqlIdentifier from "./dto/CqlIdentifier"; import CqlIdentifierCreator from "./CqlIdentifierCreator"; +import CqlRetrieve from "./dto/CqlRetrieve"; +import CqlRetrieveCreator from "./CqlRetrieveCreator"; export default class CqlAntlrListener implements cqlListener { constructor(private cqlResult: CqlResult) { @@ -103,4 +106,14 @@ export default class CqlAntlrListener implements cqlListener { this.cqlResult.identifiers.push(identifier); } } + + enterRetrieve(ctx: RetrieveContext): void { + if (ctx.terminology() == undefined) { + return; + } + const cqlRetrieve: CqlRetrieve | undefined = new CqlRetrieveCreator(ctx).buildDao(); + if (cqlRetrieve) { + this.cqlResult.retrieves.push(cqlRetrieve); + } + } } diff --git a/src/CqlRetrieveCreator.ts b/src/CqlRetrieveCreator.ts new file mode 100644 index 0000000..55abef3 --- /dev/null +++ b/src/CqlRetrieveCreator.ts @@ -0,0 +1,17 @@ +import {ParserRuleContext} from "antlr4ts/ParserRuleContext"; +import CreatorBase from "./CreatorBase"; +import {cqlLexer} from "../generated"; +import CqlRetrieve from "./dto/CqlRetrieve"; + +export default class CqlRetrieveCreator extends CreatorBase { + constructor(ctx: ParserRuleContext) { + super(ctx, {} as CqlRetrieve); + } + + protected build(): CqlRetrieve { + this.cqlDao.name = this.findChildText(cqlLexer.QUOTEDIDENTIFIER); + this.cqlDao.terminology = this.findChildText(cqlLexer.QUOTEDIDENTIFIER, 2); + this.cqlDao.hits = 0; + return this.cqlDao; + } +} diff --git a/src/dto/CqlResult.ts b/src/dto/CqlResult.ts index 998ab9d..dd0771b 100644 --- a/src/dto/CqlResult.ts +++ b/src/dto/CqlResult.ts @@ -8,6 +8,7 @@ import CqlContext from "./CqlContext"; import CqlExpressionDefinition from "./CqlExpressionDefinition"; import CqlError from "./CqlError"; import CqlIdentifier from "./CqlIdentifier"; +import CqlRetrieve from "./CqlRetrieve"; export default interface CqlResult { library?: CqlVersion; @@ -20,6 +21,7 @@ export default interface CqlResult { identifiers: CqlIdentifier[]; context?: CqlContext; expressionDefinitions: CqlExpressionDefinition[]; + retrieves: CqlRetrieve[]; errors: CqlError[]; } diff --git a/src/dto/CqlRetrieve.ts b/src/dto/CqlRetrieve.ts new file mode 100644 index 0000000..a2c1aed --- /dev/null +++ b/src/dto/CqlRetrieve.ts @@ -0,0 +1,6 @@ +import CqlText from "./CqlText"; + +export default interface CqlRetrieve extends CqlText { + terminology?: string; + hits: number; +} diff --git a/test/CqlAntlr.test.ts b/test/CqlAntlr.test.ts index 66843a3..5e7975f 100644 --- a/test/CqlAntlr.test.ts +++ b/test/CqlAntlr.test.ts @@ -27,6 +27,7 @@ describe("test antlr", () => { expect(cqlResult.context?.name).toEqual("Patient"); expect(cqlResult.expressionDefinitions.length).toEqual(6); + expect(cqlResult.retrieves.length).toEqual(1); }); it("reports syntactical errors", () => { From f30e8b37351baa44461f4db472f264aa781db6ad Mon Sep 17 00:00:00 2001 From: adongare Date: Tue, 23 May 2023 18:04:03 -0400 Subject: [PATCH 2/3] MAT-5567 test case --- package-lock.json | 4 ++-- package.json | 2 +- test/CqlAntlr.test.ts | 2 +- test/testCql.ts | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a809f4..2ff8a57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@madie/cql-antlr-parser", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@madie/cql-antlr-parser", - "version": "1.0.1", + "version": "1.0.2", "license": "CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE", "dependencies": { "antlr4ts": "^0.5.0-alpha.4", diff --git a/package.json b/package.json index be3aed2..d39d70e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@madie/cql-antlr-parser", - "version": "1.0.1", + "version": "1.0.2", "description": "Antlr Parsing of CQL in typescript", "publishConfig": { "access": "public" diff --git a/test/CqlAntlr.test.ts b/test/CqlAntlr.test.ts index 5e7975f..033fdf2 100644 --- a/test/CqlAntlr.test.ts +++ b/test/CqlAntlr.test.ts @@ -26,7 +26,7 @@ describe("test antlr", () => { expect(cqlResult.context?.name).toEqual("Patient"); - expect(cqlResult.expressionDefinitions.length).toEqual(6); + expect(cqlResult.expressionDefinitions.length).toEqual(7); expect(cqlResult.retrieves.length).toEqual(1); }); diff --git a/test/testCql.ts b/test/testCql.ts index fbf1ba7..fa54ec2 100644 --- a/test/testCql.ts +++ b/test/testCql.ts @@ -38,7 +38,10 @@ define "Denominator Exclusion": TJC."Ischemic Stroke Encounters with Discharge Disposition" union TJC."Comfort Measures during Hospitalization" - +define "Encounter Performed": + ["Encounter, Performed"] EP + where EP.relevantPeriod not null + define "Antithrombotic Not Given at Discharge": ["MedicationRequest": medication in "Antithrombotic Therapy"] NoAntithromboticDischarge where NoAntithromboticDischarge.doNotPerform is true From 41cd822243f9b8f8f6fcdacb99bab969d28a6d2e Mon Sep 17 00:00:00 2001 From: adongare Date: Wed, 24 May 2023 07:56:57 -0400 Subject: [PATCH 3/3] MAT-5567 address review feedback --- src/CqlAntlrListener.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CqlAntlrListener.ts b/src/CqlAntlrListener.ts index 4b20978..6f5e8ad 100644 --- a/src/CqlAntlrListener.ts +++ b/src/CqlAntlrListener.ts @@ -108,7 +108,7 @@ export default class CqlAntlrListener implements cqlListener { } enterRetrieve(ctx: RetrieveContext): void { - if (ctx.terminology() == undefined) { + if (ctx.terminology() === undefined) { return; } const cqlRetrieve: CqlRetrieve | undefined = new CqlRetrieveCreator(ctx).buildDao();