From ea3191667848026fddc5edccc74150c9ffb7085e Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Tue, 1 Oct 2024 12:59:17 -0400 Subject: [PATCH 1/6] MAT-7511 editing the included library from saved libraries --- .../editMeasure/editor/MeasureEditor.tsx | 24 ++++++++++++++++++- .../editMeasure/editor/libraryApplier.ts | 6 +++++ src/types/madie-madie-editor.d.ts | 7 +++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/components/editMeasure/editor/MeasureEditor.tsx b/src/components/editMeasure/editor/MeasureEditor.tsx index 291f209b..4154c323 100644 --- a/src/components/editMeasure/editor/MeasureEditor.tsx +++ b/src/components/editMeasure/editor/MeasureEditor.tsx @@ -54,7 +54,11 @@ import { SuccessText } from "../../../styles/editMeasure/editor"; import "./MeasureEditor.scss"; import applyCode from "./codeApplier"; import applyValueset from "./valuesetApplier"; -import { applyLibrary, deleteIncludedLibrary } from "./libraryApplier"; +import { + applyLibrary, + deleteIncludedLibrary, + editLibrary, +} from "./libraryApplier"; import { applyDefinition, editDefinition } from "./DefinitionApplier"; export const mapErrorsToAceAnnotations = ( @@ -481,6 +485,23 @@ const MeasureEditor = () => { setToastOpen(true); }; + const handleEditLibrary = ( + selectedLibrary: IncludeLibrary, + editedLibrary: IncludeLibrary + ) => { + const updatedCql = editLibrary(selectedLibrary, editedLibrary, editorVal); + handleMadieEditorValue(updatedCql); + + const setDefinitionConfirmation = () => { + setToastMessage( + `Library ${editedLibrary.name} has been successfully edited in the CQL` + ); + setToastType("success"); + setToastOpen(true); + }; + updateMeasureCql(updatedCql, setDefinitionConfirmation); + }; + const handleDeleteLibrary = (library: IncludeLibrary) => { if (editorVal) { const updatedCql = deleteIncludedLibrary(editorVal, library); @@ -690,6 +711,7 @@ const MeasureEditor = () => { handleApplyDefinition={handleApplyDefinition} handleDefinitionEdit={handleDefinitionEdit} handleDeleteLibrary={handleDeleteLibrary} + handleEditLibrary={handleEditLibrary} onChange={(val: string) => handleMadieEditorValue(val)} value={editorVal} inboundAnnotations={elmAnnotations} diff --git a/src/components/editMeasure/editor/libraryApplier.ts b/src/components/editMeasure/editor/libraryApplier.ts index 0b16c45f..0879be1b 100644 --- a/src/components/editMeasure/editor/libraryApplier.ts +++ b/src/components/editMeasure/editor/libraryApplier.ts @@ -83,3 +83,9 @@ export const deleteIncludedLibrary = ( } return cql; }; + +export const editLibrary = (selectedLibrary, editedLibrary, cql) => { + const oldLibrary = getIncludeStatementForLibrary(selectedLibrary); + const newLibrary = getIncludeStatementForLibrary(editedLibrary); + return cql.replace(oldLibrary, newLibrary); +}; diff --git a/src/types/madie-madie-editor.d.ts b/src/types/madie-madie-editor.d.ts index bf420d75..2fab2cc0 100644 --- a/src/types/madie-madie-editor.d.ts +++ b/src/types/madie-madie-editor.d.ts @@ -74,10 +74,11 @@ declare module "@madie/madie-editor" { handleApplyDefinition?: (def: Definition) => void; handleDefinitionEdit?: (lib: SelectedLibrary, def: Definition) => void; handleApplyLibrary?: (lib: SelectedLibrary) => void; + handleEditLibrary?: ( + lib: SelectedLibrary, + editedLib: IncludeLibrary + ) => void; handleDeleteLibrary?: (lib: SelectedLibrary) => void; - // handleApplyLibrary?: (lib: IncludeLibrary) => void; - // handleDeleteLibrary?: (lib: IncludeLibrary) => void; - parseDebounceTime?: number; inboundAnnotations?: Ace.Annotation[]; inboundErrorMarkers?: Ace.MarkerLike[]; From aea0a8ca2ad4d2049234fec55d81d795f8862018 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Tue, 1 Oct 2024 13:13:25 -0400 Subject: [PATCH 2/6] MAT-7511 added test case --- .../editMeasure/editor/libraryApplier.test.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/components/editMeasure/editor/libraryApplier.test.ts b/src/components/editMeasure/editor/libraryApplier.test.ts index bd0287ca..984e5359 100644 --- a/src/components/editMeasure/editor/libraryApplier.test.ts +++ b/src/components/editMeasure/editor/libraryApplier.test.ts @@ -1,4 +1,4 @@ -import { applyLibrary, deleteIncludedLibrary } from "./libraryApplier"; +import { applyLibrary, deleteIncludedLibrary, editLibrary } from "./libraryApplier"; import IncludedLibrary from "@madie/madie-models/dist/IncludedLibrary"; import { IncludeLibrary } from "@madie/madie-editor"; @@ -148,4 +148,30 @@ describe("Library Apply Utility tests", () => { // cql unchanged expect(result).toEqual(cql); }); + + it("Should edit the existing Library successfully with new library", () => { + const cql = + "library CaseWhenThen version '0.3.000'\n" + + "using QDM version '5.6'\n" + + "include CancerLinQ version '1.5.000' called CancerLinQQ\n" + + "codesystem \"RXNORM\": 'urn:oid:2.16.840.1.113883.6.88'"; + + const editedLibrary = { + name:'CancerLinQ', + version:'1.5.000', + alias: 'EditedCancerLinQQ' + } + + const selectedLibrary = { + name:'CancerLinQ', + version:'1.5.000', + alias: 'CancerLinQQ' + } + + const result= editLibrary(selectedLibrary, editedLibrary,cql) + expect(result).toEqual("library CaseWhenThen version '0.3.000'\n" + + "using QDM version '5.6'\n" + + "include CancerLinQ version '1.5.000' called EditedCancerLinQQ\n" + + "codesystem \"RXNORM\": 'urn:oid:2.16.840.1.113883.6.88'"); + }) }); From efca63d0973ecbb467bb122b00580e07d4f9bc06 Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Tue, 1 Oct 2024 13:28:14 -0400 Subject: [PATCH 3/6] MAT-7511 fixed lint issue --- .../editMeasure/editor/libraryApplier.test.ts | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/components/editMeasure/editor/libraryApplier.test.ts b/src/components/editMeasure/editor/libraryApplier.test.ts index 984e5359..ce4f262e 100644 --- a/src/components/editMeasure/editor/libraryApplier.test.ts +++ b/src/components/editMeasure/editor/libraryApplier.test.ts @@ -1,4 +1,8 @@ -import { applyLibrary, deleteIncludedLibrary, editLibrary } from "./libraryApplier"; +import { + applyLibrary, + deleteIncludedLibrary, + editLibrary, +} from "./libraryApplier"; import IncludedLibrary from "@madie/madie-models/dist/IncludedLibrary"; import { IncludeLibrary } from "@madie/madie-editor"; @@ -155,23 +159,25 @@ describe("Library Apply Utility tests", () => { "using QDM version '5.6'\n" + "include CancerLinQ version '1.5.000' called CancerLinQQ\n" + "codesystem \"RXNORM\": 'urn:oid:2.16.840.1.113883.6.88'"; - + const editedLibrary = { - name:'CancerLinQ', - version:'1.5.000', - alias: 'EditedCancerLinQQ' - } + name: "CancerLinQ", + version: "1.5.000", + alias: "EditedCancerLinQQ", + }; const selectedLibrary = { - name:'CancerLinQ', - version:'1.5.000', - alias: 'CancerLinQQ' - } + name: "CancerLinQ", + version: "1.5.000", + alias: "CancerLinQQ", + }; - const result= editLibrary(selectedLibrary, editedLibrary,cql) - expect(result).toEqual("library CaseWhenThen version '0.3.000'\n" + - "using QDM version '5.6'\n" + - "include CancerLinQ version '1.5.000' called EditedCancerLinQQ\n" + - "codesystem \"RXNORM\": 'urn:oid:2.16.840.1.113883.6.88'"); - }) + const result = editLibrary(selectedLibrary, editedLibrary, cql); + expect(result).toEqual( + "library CaseWhenThen version '0.3.000'\n" + + "using QDM version '5.6'\n" + + "include CancerLinQ version '1.5.000' called EditedCancerLinQQ\n" + + "codesystem \"RXNORM\": 'urn:oid:2.16.840.1.113883.6.88'" + ); + }); }); From 251fffc611b175c010093f5005420d5a817a9e2c Mon Sep 17 00:00:00 2001 From: Prateek Keerthi Date: Wed, 2 Oct 2024 09:03:59 -0400 Subject: [PATCH 4/6] MAT-7511 added test case --- src/__mocks__/@madie/madie-editor.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/__mocks__/@madie/madie-editor.tsx b/src/__mocks__/@madie/madie-editor.tsx index cb5535ab..ca9532f6 100644 --- a/src/__mocks__/@madie/madie-editor.tsx +++ b/src/__mocks__/@madie/madie-editor.tsx @@ -30,6 +30,7 @@ export function MadieTerminologyEditor({ inboundAnnotations, handleCodeDelete, handleApplyLibrary, + handleEditLibrary, handleDeleteLibrary, }) { const code = { @@ -74,6 +75,13 @@ export function MadieTerminologyEditor({ Apply Library + +