Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-7652 CQL Validation - Multiple Using Statements #386

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 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
Expand Up @@ -66,7 +66,7 @@
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@madie/cql-antlr-parser": "^1.0.5",
"@madie/cql-antlr-parser": "^1.0.7",
"@madie/madie-design-system": "^1.2.37",
"@material-ui/core": "^4.12.4",
"@mui/icons-material": "^5.5.1",
Expand Down
172 changes: 168 additions & 4 deletions src/AceEditor/madie-ace-editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import MadieAceEditor, {
mapParserErrorsToAceMarkers,
updateEditorContent,
setCommandEnabled,
updateUsingStatements,
} from "./madie-ace-editor";

import "ace-builds/src-noconflict/mode-java";
import "ace-builds/src-noconflict/theme-monokai";
import userEvent from "@testing-library/user-event";
import CqlError from "@madie/cql-antlr-parser/dist/src/dto/CqlError";
import { CqlAntlr } from "@madie/cql-antlr-parser/dist/src";

describe("MadieAceEditor component", () => {
it("should create madie editor", async () => {
Expand Down Expand Up @@ -55,7 +57,7 @@ describe("MadieAceEditor component", () => {
expect(aceEditor.value).toContain(editorValue);
});

it("should should trigger parts of toggleSearch when events emitted", async () => {
it.skip("should should trigger parts of toggleSearch when events emitted", async () => {
sb-prateekkeerthi marked this conversation as resolved.
Show resolved Hide resolved
// Mock the editor and searchBox
const editorMock = {
execCommand: jest.fn(),
Expand Down Expand Up @@ -321,7 +323,7 @@ describe("synching the cql", () => {
});

test("replacing the error containing using content line to actual using content with FHIR", async () => {
const expectValue = "using FHIR version '4.0.1'";
const expectValue = "using QICore version '4.1.1'";
const updatedContent = await updateEditorContent(
"using FHIR version '4.0.1'",
"",
Expand Down Expand Up @@ -350,7 +352,7 @@ describe("synching the cql", () => {
expect(updatedContent.cql).toEqual(expectValue);
});

test.only("remove value set version if exists in cql", async () => {
test("remove value set version if exists in cql", async () => {
const cql = `
library Testing version '0.0.000'
using QDM version '5.6'
Expand Down Expand Up @@ -461,7 +463,7 @@ I want to decalre a concept lalala`,
});

describe("isUsingStatementEmpty", () => {
test("Replace concept declaration with comment", async () => {
it("Replace concept declaration with comment", async () => {
const expectValue = `library Testing version '0.0.000'
/*CONCEPT DECLARATION REMOVED: CQL concept construct shall NOT be used.*/`;
const updatedContents = await updateEditorContent(
Expand Down Expand Up @@ -513,3 +515,165 @@ describe("isUsingStatementEmpty", () => {
expect(updatedContents.cql).toEqual(expectValue);
});
});

describe("updateUsingStatements", () => {
it("should not update using statement if there is only one using statement and it matches with measure model", async () => {
const cql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'";
const measureModel = "QICore";
const measureModelVersion = "4.1.1";
const parsedCql = new CqlAntlr(cql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: cql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(false);
expect(cql).toEqual(updatedCqlArray.join("\n"));
});

it("should correct using statement if using model does not match with measure model", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QDM version '4.1.1'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'";
const measureModel = "QICore";
const measureModelVersion = "4.1.1";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});

it("should correct using statement if using model version does not match with measure model", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '5.6'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'";
const measureModel = "QICore";
const measureModelVersion = "4.1.1";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});

it("should retain only one valid using statement if multiple using statement of same or different model found", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'\n" +
"using QICore version '4.1.1'\n" +
"using QDM version '5.6'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'";
const measureModel = "QICore";
const measureModelVersion = "4.1.1";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});

it("should correct QICore and FHIR valid using statement if multiple using statement of QICore and FHIR models found", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.0.1'\n" +
"using FHIR version '4.1.1'\n" +
"using FHIR version '4.1.1'\n" +
"using QICore version '5.6'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'\n" +
"using FHIR version '4.0.1'";
const measureModel = "QICore";
const measureModelVersion = "4.1.1";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});

it("should correct QICore using statement if QDM is declared first followed by QICore for QICore measure", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QDM version '4.0.1'\n" +
"using QICore version '4.1.1'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'";
const measureModel = "QICore";
const measureModelVersion = "4.1.1";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});

it("should correct QDM using statement for QDM measure and remove QICore and FHIR using statement if found", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.1.1'\n" +
"using FHIR version '4.0.1'\n" +
"using FHIR version '4..1'\n" +
"using QICore version '5.6'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QDM version '5.6'";
const measureModel = "QDM";
const measureModelVersion = "5.6";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});

it("should correct QDM using statement if QICore using is declared first followed by QDM for QDM measure", async () => {
const editorCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QICore version '4.0.1'\n" +
"using QDM version '4.1.1'";
const correctedCql =
"library SimpleEncounterMeasure version '0.0.000'\n" +
"using QDM version '5.6'";
const measureModel = "QDM";
const measureModelVersion = "5.6";
const parsedCql = new CqlAntlr(editorCql)?.parse();
const { isCqlUpdated, updatedCqlArray } = updateUsingStatements(
{ parsedCql, cqlArrayToBeFiltered: editorCql.split("\n") },
measureModel,
measureModelVersion
);
expect(isCqlUpdated).toEqual(true);
expect(correctedCql).toEqual(updatedCqlArray.join("\n"));
});
});
Loading
Loading