diff --git a/src/AceEditor/madie-ace-editor.test.tsx b/src/AceEditor/madie-ace-editor.test.tsx index 78c419ee..666b3bbe 100644 --- a/src/AceEditor/madie-ace-editor.test.tsx +++ b/src/AceEditor/madie-ace-editor.test.tsx @@ -307,6 +307,23 @@ describe("synching the cql", () => { expect(updatedContent.isValueSetChanged).toEqual(false); }); + it("should replace incorrect alias for FHIRHelpers", 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( + "library MAT7909TestDefaultAlias version '0.0.000' using QICore version '4.1.1' include FHIRHelpers version '4.3.000' called Dummy 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); + }); + 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 4b225a04..6741f3b2 100644 --- a/src/AceEditor/madie-ace-editor.tsx +++ b/src/AceEditor/madie-ace-editor.tsx @@ -72,6 +72,7 @@ export interface UpdatedCqlObject { isLibraryStatementChanged?: boolean; isUsingStatementChanged?: boolean; isValueSetChanged?: boolean; + isFhirHelpersAliasChanged?: boolean; } export const updateUsingStatements = ( @@ -258,6 +259,20 @@ const updateCql = ( ] = `library ${libraryName} version '${libraryVersion}'`; 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]; + parsedEditorCql.cqlArrayToBeFiltered[include.start.line - 1] = + fhirHelpersIncludeLine.replace(include.called, "FHIRHelpers"); + cqlUpdates.isFhirHelpersAliasChanged = true; + } + }); // update using statements if they are incorrect const { isCqlUpdated, updatedCqlArray } = updateUsingStatements( parsedEditorCql,