Skip to content

Commit

Permalink
MAT-7909: Fixed when alias is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-akins committed Dec 9, 2024
1 parent 376db8f commit 8e7cc7c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
36 changes: 35 additions & 1 deletion src/AceEditor/madie-ace-editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,24 @@ describe("synching the cql", () => {
expect(updatedContent.isValueSetChanged).toEqual(false);
});

it("should replace incorrect alias for FHIRHelpers", async () => {
it("should replace incorrect alias for FHIRHelpers ; alias has spaces", async () => {
const expectValue =
"library MAT7909TestDefaultAlias version '0.0.000' using QICore version '4.1.1' include FHIRHelpers version '4.3.000' called FHIRHelpers Helpers valueset \"Bicarbonate lab test\": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1045.139' context Patient define \"Initial Population\": exists ( [Observation] O where O.value < 5 'mg') ";
const updatedContent = await updateEditorContent(
"library MAT7909TestDefaultAlias version '0.0.000' using QICore version '4.1.1' include FHIRHelpers version '4.3.000' called F Helpers valueset \"Bicarbonate lab test\": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1045.139' context Patient define \"Initial Population\": exists ( [Observation] O where O.value < 5 'mg') ",
"library MAT7909TestDefaultAlias version '0.0.000'",
"MAT7909TestDefaultAlias",
"",
"0.0.000",
"QI-Core",
"4.1.1",
"measureEditor"
);
expect(updatedContent.cql).toEqual(expectValue);
expect(updatedContent.isFhirHelpersAliasChanged).toEqual(true);
});

it("should replace incorrect alias for FHIRHelpers single line CQL", async () => {
const expectValue =
"library MAT7909TestDefaultAlias version '0.0.000' using QICore version '4.1.1' include FHIRHelpers version '4.3.000' called FHIRHelpers valueset \"Bicarbonate lab test\": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1045.139' context Patient define \"Initial Population\": exists ( [Observation] O where O.value < 5 'mg') ";
const updatedContent = await updateEditorContent(
Expand All @@ -324,6 +341,23 @@ describe("synching the cql", () => {
expect(updatedContent.isFhirHelpersAliasChanged).toEqual(true);
});

it("should replace incorrect alias for FHIRHelpers; multiple line cql ", async () => {
const expectValue =
"library MAT7909TestDefaultAlias version '0.0.000'\n using QICore version '4.1.1'\n include FHIRHelpers version '4.3.000' called FHIRHelpers\n valueset \"Bicarbonate lab test\": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1045.139'\n context Patient\n define \"Initial Population\":\n exists ( [Observation] O where O.value < 5 'mg')\n ";
const updatedContent = await updateEditorContent(
"library MAT7909TestDefaultAlias version '0.0.000'\n using QICore version '4.1.1'\n include FHIRHelpers version '4.3.000' called Dummy\n valueset \"Bicarbonate lab test\": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1045.139'\n context Patient\n define \"Initial Population\":\n exists ( [Observation] O where O.value < 5 'mg')\n ",
"library MAT7909TestDefaultAlias version '0.0.000'",
"MAT7909TestDefaultAlias",
"",
"0.0.000",
"QI-Core",
"4.1.1",
"measureEditor"
);
expect(updatedContent.cql).toEqual(expectValue);
expect(updatedContent.isFhirHelpersAliasChanged).toEqual(true);
});

test("replacing the error containing using content line to actual using content", async () => {
const expectValue = "using QICore version '4.1.1'";
const updatedContent = await updateEditorContent(
Expand Down
23 changes: 10 additions & 13 deletions src/AceEditor/madie-ace-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,21 @@ const updateCql = (
cqlUpdates.isLibraryStatementChanged = true;
}

//FHIRHelpers can not be aliased

//in includes find FHIRHelpers.. if it exists, check for Alias. If Alias isn't FHIRHelpers exactly,
parsedEditorCql.parsedCql.includes.forEach((include) => {
if (include.name === "FHIRHelpers" && include.called != "FHIRHelpers") {
//then modify and return .. also set cqlUpdates.isFhirHelpersAliasModified = true
const fhirHelpersIncludeLine: string[] =
parsedEditorCql.cqlArrayToBeFiltered[include.start.line - 1].split(
" "
);
if (fhirHelpersIncludeLine[4].toLowerCase() === "called") {
fhirHelpersIncludeLine[5] = "FHIRHelpers";
} else {
console.error("FHIRHelpers include statement was malformed");
throw new Error("FHIRHelpers include statement was malformed");
}
const correctFhirHelpersIncludeLine: string = ` FHIRHelpers version ${include.version} called FHIRHelpers`;
const incorrectFhirHelpersIncludeLine: string =
parsedEditorCql.cqlArrayToBeFiltered[
include.start.line - 1
].substring(include.start.position + 1, include.stop.position + 1);

parsedEditorCql.cqlArrayToBeFiltered[include.start.line - 1] =
fhirHelpersIncludeLine.join(" ");
parsedEditorCql.cqlArrayToBeFiltered[include.start.line - 1].replace(
incorrectFhirHelpersIncludeLine,
correctFhirHelpersIncludeLine
);
cqlUpdates.isFhirHelpersAliasChanged = true;
}
});
Expand Down

0 comments on commit 8e7cc7c

Please sign in to comment.