@madie/cql-antlr-parser
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -16,13 +16,5 @@ "use strict"; | ||
static findChildName(children) { | ||
if ((children === null || children === void 0 ? void 0 : children.length) != 4) { | ||
console.error("########### Entering.. children length is ", children === null || children === void 0 ? void 0 : children.length); | ||
throw new Error("Definition might be malformed."); | ||
} | ||
return children ? children[1].text : undefined; | ||
} | ||
static findChildExpression(children) { | ||
if ((children === null || children === void 0 ? void 0 : children.length) != 4) { | ||
console.error("########### Entering.. children length is ", children === null || children === void 0 ? void 0 : children.length); | ||
throw new Error("Definition might be malformed."); | ||
} | ||
return children ? children[3].text : undefined; | ||
@@ -59,7 +51,8 @@ } | ||
static formatComment(comment) { | ||
return comment.replace(AntlrUtils.SINGLE_LINE_COMMENT_REGEX, "") | ||
return comment | ||
.replace(AntlrUtils.SINGLE_LINE_COMMENT_REGEX, "") | ||
.replace(AntlrUtils.MULTI_LINE_COMMENT_REGEX, "") | ||
.split("\n") | ||
.map((line) => line.trim()) | ||
.filter(line => line !== "") | ||
.filter((line) => line !== "") | ||
.join("\n"); | ||
@@ -66,0 +59,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { AggregateClauseContext, CodeDefinitionContext, CodesystemDefinitionContext, ContextDefinitionContext, cqlListener, ExpressionDefinitionContext, IncludeDefinitionContext, LibraryDefinitionContext, ParameterDefinitionContext, RetrieveContext, UsingDefinitionContext, ValuesetDefinitionContext } from "../generated"; | ||
import { AggregateClauseContext, CodeDefinitionContext, CodesystemDefinitionContext, ContextDefinitionContext, cqlListener, ExpressionDefinitionContext, FunctionDefinitionContext, IncludeDefinitionContext, LibraryDefinitionContext, ParameterDefinitionContext, RetrieveContext, UsingDefinitionContext, ValuesetDefinitionContext } from "../generated"; | ||
import CqlResult from "./dto/CqlResult"; | ||
@@ -16,3 +16,5 @@ import { BufferedTokenStream } from "antlr4ts"; | ||
enterContextDefinition(ctx: ContextDefinitionContext): void; | ||
private processDefinitionWithComments; | ||
enterExpressionDefinition(ctx: ExpressionDefinitionContext): void; | ||
enterFunctionDefinition(ctx: FunctionDefinitionContext): void; | ||
enterAggregateClause(ctx: AggregateClauseContext): void; | ||
@@ -19,0 +21,0 @@ enterRetrieve(ctx: RetrieveContext): void; |
@@ -67,18 +67,13 @@ "use strict"; | ||
} | ||
enterExpressionDefinition(ctx) { | ||
const cqlExpressionCreator = new CqlExpressionDefinitionCreator_1.default(ctx); | ||
const expressionDefinition = cqlExpressionCreator.buildDao(); | ||
if (expressionDefinition) { | ||
if (ctx.start.inputStream) { | ||
const hiddenTokens = this.bufferedTokenStream.getHiddenTokensToLeft(ctx.start.tokenIndex, generated_1.cqlLexer.HIDDEN); | ||
let comment = ""; | ||
hiddenTokens.forEach((token) => { | ||
if (token.text) { | ||
comment += token.text; | ||
} | ||
}); | ||
comment = comment.trim(); | ||
processDefinitionWithComments(ctx, buildDao) { | ||
const expressionDefinition = buildDao(); | ||
if (expressionDefinition && ctx.start.inputStream) { | ||
const hiddenTokens = this.bufferedTokenStream.getHiddenTokensToLeft(ctx.start.tokenIndex, generated_1.cqlLexer.HIDDEN); | ||
if (hiddenTokens && hiddenTokens.length > 0) { | ||
const comment = hiddenTokens | ||
.map((token) => { var _a; return (_a = token.text) === null || _a === void 0 ? void 0 : _a.trim(); }) | ||
.filter(Boolean) | ||
.join(" "); | ||
if (comment) { | ||
// if expression has comment, start needs to be adjusted to consider comments as comment is part of definition | ||
expressionDefinition.start = cqlExpressionCreator.buildLineInfo(hiddenTokens[1]); | ||
expressionDefinition.start = new CqlExpressionDefinitionCreator_1.default(ctx).buildLineInfo(hiddenTokens[1]); | ||
expressionDefinition.comment = AntlrUtils_1.default.formatComment(comment); | ||
@@ -90,2 +85,12 @@ } | ||
} | ||
enterExpressionDefinition(ctx) { | ||
this.processDefinitionWithComments(ctx, () => { | ||
return new CqlExpressionDefinitionCreator_1.default(ctx).buildDao(); | ||
}); | ||
} | ||
enterFunctionDefinition(ctx) { | ||
this.processDefinitionWithComments(ctx, () => { | ||
return new CqlExpressionDefinitionCreator_1.default(ctx).buildDao(); | ||
}); | ||
} | ||
enterAggregateClause(ctx) { | ||
@@ -92,0 +97,0 @@ const identifier = new CqlIdentifierCreator_1.default(ctx).buildDao(); |
@@ -33,3 +33,3 @@ "use strict"; | ||
expect(cqlResult.parameters.length).toBe(0); | ||
expect(cqlResult.expressionDefinitions.length).toEqual(4); | ||
expect(cqlResult.expressionDefinitions.length).toEqual(6); | ||
cqlResult.expressionDefinitions.forEach((def) => { | ||
@@ -43,3 +43,3 @@ expect(def.name).toBeDefined(); | ||
const expressions = cqlResult.expressionDefinitions; | ||
expect(expressions.length).toEqual(4); | ||
expect(expressions.length).toEqual(6); | ||
expect(cqlResult.expressionDefinitions[0].comment).toEqual("ehnicity comment"); | ||
@@ -49,2 +49,4 @@ expect(cqlResult.expressionDefinitions[1].comment).toEqual("multi line"); | ||
expect(cqlResult.expressionDefinitions[3].comment).toEqual(undefined); | ||
expect(cqlResult.expressionDefinitions[4].comment).toEqual("multiline comment outside of a function with multiple\nrows"); | ||
expect(cqlResult.expressionDefinitions[5].comment).toEqual("comment outside of function"); | ||
}); | ||
@@ -73,5 +75,5 @@ it("parse fhir cql", () => { | ||
expect(cqlResult.valueSets.length).toBe(2); | ||
expect(cqlResult.valueSets[0].name).toBe("\"Adolescent depression screening assessment\""); | ||
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].name).toBe('"Adolescent depression screening assessment with version"'); | ||
expect(cqlResult.valueSets[1].version).toBe("'urn:hl7:version:20240307'"); | ||
@@ -78,0 +80,0 @@ }); |
@@ -53,5 +53,5 @@ "use strict"; | ||
cqlResult.includes.push(createInclude("Global")); | ||
cqlResult.valueSets.push(createValueSet("\"Patient Refusal\"")); | ||
cqlResult.valueSets.push(createValueSet("\"Medical Reason\"")); | ||
cqlResult.valueSets.push(createValueSet("\"Antithrombotic Therapy\"")); | ||
cqlResult.valueSets.push(createValueSet('"Patient Refusal"')); | ||
cqlResult.valueSets.push(createValueSet('"Medical Reason"')); | ||
cqlResult.valueSets.push(createValueSet('"Antithrombotic Therapy"')); | ||
const cqlExpressionVisitor = new CqlExpressionVisitor_1.default(cqlResult); | ||
@@ -86,5 +86,5 @@ cqlExpressionVisitor.visit(createAntlrContext(testDefineWithAlias)); | ||
cqlResult.includes.push(createInclude("Global")); | ||
cqlResult.valueSets.push(createValueSet("\"Patient Refusal\"")); | ||
cqlResult.valueSets.push(createValueSet("\"Medical Reason\"")); | ||
cqlResult.valueSets.push(createValueSet("\"Antithrombotic Therapy\"")); | ||
cqlResult.valueSets.push(createValueSet('"Patient Refusal"')); | ||
cqlResult.valueSets.push(createValueSet('"Medical Reason"')); | ||
cqlResult.valueSets.push(createValueSet('"Antithrombotic Therapy"')); | ||
const v = new CqlExpressionVisitor_1.default(cqlResult); | ||
@@ -91,0 +91,0 @@ v.visit(createAntlrContext(sdeValueset)); |
@@ -1,2 +0,2 @@ | ||
declare const simpleDefinitionCql = "\n //MAT-4844: Test Define with no quotes\n library ScreeningPrediabetesFHIR version '0.0.000'\n using QICore version '4.1.1'\n using FHIR version '4.0.1'\n\n context Patient\n // ehnicity comment\n define \"SDE Ethnicity\":\n SDE.\"SDE Ethnicity\"\n\n /* multi line \n */\n define InitialPopulation:\n \"VTE Prophylaxis by Medication Administered or Device Applied\"\n\n /* \n @author: john doe \n @description: this is Numerator \n */\n define \"Numerator\":\n \"VTE Prophylaxis by Medication Administered or Device Applied\"\n\n define \"VTE Prophylaxis by Medication Administered or Device Applied\":\n ( [\"MedicationAdministration\": medication in \"Low Dose Unfractionated Heparin for VTE Prophylaxis\"] VTEMedication\n where VTEMedication.status = 'completed'\n )\n"; | ||
declare const simpleDefinitionCql = "\n //MAT-4844: Test Define with no quotes\n library ScreeningPrediabetesFHIR version '0.0.000'\n using QICore version '4.1.1'\n using FHIR version '4.0.1'\n\n context Patient\n // ehnicity comment\n define \"SDE Ethnicity\":\n SDE.\"SDE Ethnicity\"\n\n /* multi line \n */\n define InitialPopulation:\n \"VTE Prophylaxis by Medication Administered or Device Applied\"\n\n /* \n @author: john doe \n @description: this is Numerator \n */\n define \"Numerator\":\n \"VTE Prophylaxis by Medication Administered or Device Applied\"\n\n define \"VTE Prophylaxis by Medication Administered or Device Applied\":\n ( [\"MedicationAdministration\": medication in \"Low Dose Unfractionated Heparin for VTE Prophylaxis\"] VTEMedication\n where VTEMedication.status = 'completed'\n )\n \n /*\nmultiline comment outside of a function with multiple\nrows\n*/\n\ndefine function \"Denominator Observation\"(Encounter \"Encounter, Performed\" ):\n // inside of definition to ignore\n duration in hours of Encounter.relevantPeriod\n\n// comment outside of function\ndefine function \"Numerator Observation\"(Encounter \"Encounter, Performed\" ):\n duration in hours of Encounter.relevantPeriod\n"; | ||
declare const fhirTestCql = "library TJCOverall_FHIR4 version '4.0.000'\n\nusing FHIR version '4.0.0'\n// NOTE: BTR 2019-07-30: Updated version dependencies\ninclude FHIRHelpers version '4.0.0' called FHIRHelpers\ninclude MATGlobalCommonFunctions_FHIR4 version '4.0.000' called Global\ninclude SupplementalDataElements_FHIR4 version '1.0.0' called SDE\n\ncodesystem \"LOINC\": 'urn:oid:2.16.840.1.113883.6.1'\ncodesystem \"CPT:2018\": 'urn:oid:2.16.840.1.113883.6.12'\ncodesystem \"SNOMEDCT:2017-09\": 'http://snomed.info/sct/731000124108' version 'http://snomed.info/sct/731000124108/version/201709'\n\nvalueset \"Acute Pharyngitis (1)\": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.102.12.1011.1'\nvalueset \"Acute Pharyngitis (2)\": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.102.12.1011.2'\nvalueset \"Encounter Inpatient SNOMEDCT Value Set\": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.7.307|20160929'\nvalueset \"Face-to-Face Interaction\": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1004.101.12.1048|MU2%20Update@202016-04-01'\n\ncode \"Venous foot pump, device (physical object)\": '442023007' from \"SNOMED-CT\"\nparameter \"Measurement Period\" Interval<DateTime>\n default Interval[@2019-01-01T00:00:00.0, @2020-01-01T00:00:00.0)\n \ncontext Patient\n\ndefine \"SDE Ethnicity\":\n SDE.\"SDE Ethnicity\"\n\ndefine \"SDE Payer\":\n SDE.\"SDE Payer\"\n\ndefine \"SDE Race\":\n SDE.\"SDE Race\"\n\ndefine \"SDE Sex\":\n SDE.\"SDE Sex\"\n\n//MAT-4844: Test Define with no quotes\ndefine InitialPopulation:\n true \n\ndefine \"Denominator Exclusion\":\n TJC.\"Ischemic Stroke Encounters with Discharge Disposition\"\n union TJC.\"Comfort Measures during Hospitalization\"\n \ndefine \"Encounter Performed\":\n [\"Encounter, Performed\"] EP\n where EP.relevantPeriod not null\n \ndefine \"Antithrombotic Not Given at Discharge\":\n [\"MedicationRequest\": medication in \"Antithrombotic Therapy\"] NoAntithromboticDischarge\n where NoAntithromboticDischarge.doNotPerform is true\n and (NoAntithromboticDischarge.reasonCode in \"Medical Reason\"\n or NoAntithromboticDischarge.reasonCode in \"Patient Refusal\")\n //Note: expressed as an or with equivalence semantics pending resolution of potential CQL issue.\n and exists (NoAntithromboticDischarge.category C where FHIRHelpers.ToConcept(C) ~ Global.\"Community\" or FHIRHelpers.ToConcept(C) ~ Global.\"Discharge\")\n and NoAntithromboticDischarge.status = 'completed'\n and NoAntithromboticDischarge.intent = 'order' \n"; | ||
@@ -3,0 +3,0 @@ declare const qdmTestCql = "\nlibrary PreventiveCareScreeningFollowUpPlan version '0.0.000'\nusing QDM version '5.6'\nvalueset \"Adolescent depression screening assessment\": 'urn:oid:2.16.840.1.113762.1.4.1260.162'\nvalueset \"Adolescent depression screening assessment with version\": 'urn:oid:2.16.840.1.113762.1.4.1260.162' version 'urn:hl7:version:20240307'\n"; |
@@ -31,2 +31,15 @@ "use strict"; | ||
) | ||
/* | ||
multiline comment outside of a function with multiple | ||
rows | ||
*/ | ||
define function "Denominator Observation"(Encounter "Encounter, Performed" ): | ||
// inside of definition to ignore | ||
duration in hours of Encounter.relevantPeriod | ||
// comment outside of function | ||
define function "Numerator Observation"(Encounter "Encounter, Performed" ): | ||
duration in hours of Encounter.relevantPeriod | ||
`; | ||
@@ -33,0 +46,0 @@ exports.simpleDefinitionCql = simpleDefinitionCql; |
{ | ||
"name": "@madie/cql-antlr-parser", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Antlr Parsing of CQL in typescript", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1565961
22438