diff --git a/src/AceEditor/madie-ace-editor.test.tsx b/src/AceEditor/madie-ace-editor.test.tsx index 21b40c1..a7b3782 100644 --- a/src/AceEditor/madie-ace-editor.test.tsx +++ b/src/AceEditor/madie-ace-editor.test.tsx @@ -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( @@ -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( diff --git a/src/AceEditor/madie-ace-editor.tsx b/src/AceEditor/madie-ace-editor.tsx index f91e8ec..563719b 100644 --- a/src/AceEditor/madie-ace-editor.tsx +++ b/src/AceEditor/madie-ace-editor.tsx @@ -268,16 +268,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 = - parsedEditorCql.cqlArrayToBeFiltered[include.start.line - 1]; + 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.replace(include.called, "FHIRHelpers"); + parsedEditorCql.cqlArrayToBeFiltered[include.start.line - 1].replace( + incorrectFhirHelpersIncludeLine, + correctFhirHelpersIncludeLine + ); cqlUpdates.isFhirHelpersAliasChanged = true; } });