Skip to content

Commit

Permalink
Merge pull request #120 from MeasureAuthoringTool/MAT-5567
Browse files Browse the repository at this point in the history
MAT-5567 get all the retrieves
  • Loading branch information
adongare authored May 31, 2023
2 parents b2ad5f7 + 41cd822 commit 6be874f
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/CqlAntlr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CqlAntlr {
identifiers: [],
expressionDefinitions: [],
errors: [],
retrieves: [],
};
}

Expand Down
13 changes: 13 additions & 0 deletions src/CqlAntlrListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IncludeDefinitionContext,
LibraryDefinitionContext,
ParameterDefinitionContext,
RetrieveContext,
UsingDefinitionContext,
ValuesetDefinitionContext
} from "../generated";
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
17 changes: 17 additions & 0 deletions src/CqlRetrieveCreator.ts
Original file line number Diff line number Diff line change
@@ -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<CqlRetrieve> {
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;
}
}
2 changes: 2 additions & 0 deletions src/dto/CqlResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@ export default interface CqlResult {
identifiers: CqlIdentifier[];
context?: CqlContext;
expressionDefinitions: CqlExpressionDefinition[];
retrieves: CqlRetrieve[];

errors: CqlError[];
}
Expand Down
6 changes: 6 additions & 0 deletions src/dto/CqlRetrieve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import CqlText from "./CqlText";

export default interface CqlRetrieve extends CqlText {
terminology?: string;
hits: number;
}
3 changes: 2 additions & 1 deletion test/CqlAntlr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ 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);
});

it("reports syntactical errors", () => {
Expand Down
5 changes: 4 additions & 1 deletion test/testCql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6be874f

Please sign in to comment.