diff --git a/package-lock.json b/package-lock.json index a6c1383..43c21d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1885,12 +1885,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -3056,9 +3056,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" @@ -7672,12 +7672,12 @@ } }, "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "requires": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" } }, "browser-process-hrtime": { @@ -8571,9 +8571,9 @@ } }, "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "requires": { "to-regex-range": "^5.0.1" diff --git a/src/CqlAntlrListener.ts b/src/CqlAntlrListener.ts index 6f5e8ad..18d9431 100644 --- a/src/CqlAntlrListener.ts +++ b/src/CqlAntlrListener.ts @@ -65,10 +65,10 @@ export default class CqlAntlrListener implements cqlListener { } enterValuesetDefinition(ctx: ValuesetDefinitionContext): void { - const cqlCode: CqlValueSet | undefined = new CqlValueSetSystemCreator(ctx).buildDao(); + const cqlValueSet: CqlValueSet | undefined = new CqlValueSetSystemCreator(ctx, this.cqlResult.using?.name).buildDao(); - if (cqlCode) { - this.cqlResult.valueSets.push(cqlCode); + if (cqlValueSet) { + this.cqlResult.valueSets.push(cqlValueSet); } } diff --git a/src/CqlCodeValueSystemCreator.ts b/src/CqlCodeValueSystemCreator.ts index 0a820ea..5c85e96 100644 --- a/src/CqlCodeValueSystemCreator.ts +++ b/src/CqlCodeValueSystemCreator.ts @@ -3,14 +3,25 @@ import CreatorBase from "./CreatorBase"; import CqlValueSet from "./dto/CqlValueSet"; import {cqlLexer} from "../generated"; +type StringOrUndefined = undefined | string; + export default class CqlValueSetSystemCreator extends CreatorBase { - constructor(ctx: ParserRuleContext) { + model: StringOrUndefined + + constructor(ctx: ParserRuleContext, model: StringOrUndefined) { super(ctx, {} as CqlValueSet); + this.model = model; } protected build(): CqlValueSet { this.cqlDao.name = this.findChildText(cqlLexer.QUOTEDIDENTIFIER); this.cqlDao.url = this.findChildText(cqlLexer.STRING); + if (this.model === "QDM") { + this.cqlDao.version = this.findChildText(cqlLexer.STRING, 2); + } else { + const tokens = this.cqlDao.url?.split("|"); + this.cqlDao.version = tokens?.length === 2 ? tokens[1] : undefined + } this.cqlDao.hits = 0; return this.cqlDao; } diff --git a/src/dto/CqlValueSet.ts b/src/dto/CqlValueSet.ts index 502698c..93ea69a 100644 --- a/src/dto/CqlValueSet.ts +++ b/src/dto/CqlValueSet.ts @@ -1,6 +1,6 @@ -import CqlText from "./CqlText"; +import CqlVersion from "./CqlVersion"; -export default interface CqlValueSet extends CqlText { +export default interface CqlValueSet extends CqlVersion { url?: string; hits: number; } diff --git a/test/CqlAntlr.test.ts b/test/CqlAntlr.test.ts index 033fdf2..975d2ae 100644 --- a/test/CqlAntlr.test.ts +++ b/test/CqlAntlr.test.ts @@ -1,5 +1,6 @@ import { - testCql, + fhirTestCql, + qdmTestCql, cqlWithSyntaxErrors, cqlWithUsedParam, cqlWithUsedDefines, @@ -13,8 +14,8 @@ import { CqlAntlr } from "../src"; import CqlResult from "../src/dto/CqlResult"; describe("test antlr", () => { - it("parse", () => { - const cqlAntlr = new CqlAntlr(testCql); + it("parse fhir cql", () => { + const cqlAntlr = new CqlAntlr(fhirTestCql); const cqlResult: CqlResult = cqlAntlr.parse(); @@ -29,6 +30,18 @@ describe("test antlr", () => { expect(cqlResult.expressionDefinitions.length).toEqual(7); expect(cqlResult.retrieves.length).toEqual(1); }); + + it("parse qdm cql", () => { + const cqlAntlr = new CqlAntlr(qdmTestCql); + const cqlResult: CqlResult = cqlAntlr.parse(); + + expect(cqlResult.using?.name).toBe("QDM"); + expect(cqlResult.valueSets.length).toBe(2); + expect(cqlResult.valueSets[0].name).toBe("\"Adolescent depression screening assessment\""); + expect(cqlResult.valueSets[0].version).toBeUndefined(); + expect(cqlResult.valueSets[1].name).toBe("\"Adolescent depression screening assessment with version\""); + expect(cqlResult.valueSets[1].version).toBe("'urn:hl7:version:20240307'"); + }); it("reports syntactical errors", () => { const cqlAntlr = new CqlAntlr(cqlWithSyntaxErrors); diff --git a/test/testCql.ts b/test/testCql.ts index fa54ec2..761f1b6 100644 --- a/test/testCql.ts +++ b/test/testCql.ts @@ -1,4 +1,4 @@ -const testCql = `library TJCOverall_FHIR4 version '4.0.000' +const fhirTestCql = `library TJCOverall_FHIR4 version '4.0.000' using FHIR version '4.0.0' // NOTE: BTR 2019-07-30: Updated version dependencies @@ -52,6 +52,12 @@ define "Antithrombotic Not Given at Discharge": and NoAntithromboticDischarge.status = 'completed' and NoAntithromboticDischarge.intent = 'order' `; +const qdmTestCql = ` +library PreventiveCareScreeningFollowUpPlan version '0.0.000' +using QDM version '5.6' +valueset "Adolescent depression screening assessment": 'urn:oid:2.16.840.1.113762.1.4.1260.162' +valueset "Adolescent depression screening assessment with version": 'urn:oid:2.16.840.1.113762.1.4.1260.162' version 'urn:hl7:version:20240307' +` const cqlWithSyntaxErrors = `library TJCOverall_FHIR4 version '4.0.000' @@ -170,7 +176,8 @@ define FactorialOfFive: ` export { - testCql, + fhirTestCql, + qdmTestCql, cqlWithSyntaxErrors, cqlWithUsedParam, cqlWithUsedDefines,