Skip to content

Commit

Permalink
Merge pull request #232 from MeasureAuthoringTool/MAT-7999_CodeSystem…
Browse files Browse the repository at this point in the history
…ErrorMsg

Release 1.11
  • Loading branch information
gregory-akins authored Dec 31, 2024
2 parents 6e394b1 + 40d847d commit b24220f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@madie/cql-antlr-parser",
"version": "1.0.10",
"version": "1.0.11",
"description": "Antlr Parsing of CQL in typescript",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -28,7 +28,7 @@
"Fhir"
],
"author": "SemanticBits [email protected]",
"license": "CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE",
"license": "ISC",
"bugs": {
"url": "https://github.com/MeasureAuthoringTool/cql-antlr-parser/issues"
},
Expand Down
6 changes: 6 additions & 0 deletions src/util/CustomeErrorConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ const keyWords: string[] = [
];
const convertCustomError = (errorMessage: string): string => {
let convertedMsg: string = errorMessage;

if (errorMessage.match(/mismatched input \'display\' expecting \'from\'/g)) {
convertedMsg =
"code statement requires a codesystem reference. Please add a 'from' clause to your statement.";
}

switch (errorMessage) {
case "no viable alternative at input 'define :'": {
convertedMsg = "Definition is missing a name.";
Expand Down
14 changes: 12 additions & 2 deletions test/CqlAntlr.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
simpleDefinitionCql,
missingCodeSystemCql,
fhirTestCql,
qdmTestCql,
cqlWithSyntaxErrors,
Expand Down Expand Up @@ -100,11 +101,11 @@ describe("test antlr", () => {
expect(cqlResult.usings[0]?.name).toBe("QDM");
expect(cqlResult.valueSets.length).toBe(2);
expect(cqlResult.valueSets[0].name).toBe(
'"Adolescent depression screening assessment"'
"\"Adolescent depression screening assessment\""
);
expect(cqlResult.valueSets[0].version).toBeUndefined();
expect(cqlResult.valueSets[1].name).toBe(
'"Adolescent depression screening assessment with version"'
"\"Adolescent depression screening assessment with version\""
);
expect(cqlResult.valueSets[1].version).toBe("'urn:hl7:version:20240307'");
});
Expand Down Expand Up @@ -197,4 +198,13 @@ describe("test antlr", () => {
"Definition names must not be a reserved word."
);
});

it("test code with no system", (): void => {
const cqlAntlr = new CqlAntlr(missingCodeSystemCql);
const cqlResult: CqlResult = cqlAntlr.parse();
expect(cqlResult.errors.length).toEqual(1);
expect(cqlResult.errors[0].message).toEqual(
"code statement requires a codesystem reference. Please add a 'from' clause to your statement."
);
});
});
12 changes: 6 additions & 6 deletions test/CqlExpressionVisitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe("test visitor", () => {
cqlResult.includes.push(createInclude("FHIRHelpers"));
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(cqlResult);
cqlExpressionVisitor.visit(createAntlrContext(testDefineWithAlias));
Expand Down Expand Up @@ -101,9 +101,9 @@ describe("test visitor", () => {
cqlResult.includes.push(createInclude("FHIRHelpers"));
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(cqlResult);
v.visit(createAntlrContext(sdeValueset));
Expand Down
15 changes: 15 additions & 0 deletions test/testCql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ define function "Denominator Observation"(Encounter "Encounter, Performed" ):
define function "Numerator Observation"(Encounter "Encounter, Performed" ):
duration in hours of Encounter.relevantPeriod
`;
const missingCodeSystemCql = `library TJCOverall_FHIR4 version '4.0.000'
using FHIR version '4.0.0'
include FHIRHelpers version '4.0.0' called FHIRHelpers
codesystem "LOINC": 'urn:oid:2.16.840.1.113883.6.1'
code "Birth date": '21112-8' display 'Birth date'
define "Initial Population":
true
`;

const fhirTestCql = `library TJCOverall_FHIR4 version '4.0.000'
Expand Down Expand Up @@ -140,6 +152,8 @@ define "SDE Sex":
SDE."SDE Sex"
`;



const cqlWithUsedParam = `
valueset "Statin Allergen": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.42'
parameter "Measurement Period" Interval<DateTime>
Expand Down Expand Up @@ -230,6 +244,7 @@ define on or:
`;
export {
simpleDefinitionCql,
missingCodeSystemCql,
fhirTestCql,
qdmTestCql,
cqlWithSyntaxErrors,
Expand Down

0 comments on commit b24220f

Please sign in to comment.