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-7511 editing the included library from saved libraries #652

Merged
merged 6 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 14 additions & 0 deletions src/__mocks__/@madie/madie-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function MadieTerminologyEditor({
inboundAnnotations,
handleCodeDelete,
handleApplyLibrary,
handleEditLibrary,
handleDeleteLibrary,
}) {
const code = {
Expand All @@ -49,6 +50,12 @@ export function MadieTerminologyEditor({
version: "1.0.000",
};

const editedLibrary = {
name: "TestHelpers",
version: "1.0.000",
alias: "EditedHelpers",
};

return (
<>
<textarea
Expand All @@ -74,6 +81,13 @@ export function MadieTerminologyEditor({
Apply Library
</button>

<button
data-testid="edit-included-library"
onClick={() => handleEditLibrary(library, editedLibrary)}
>
Edit Library
</button>

<button
data-testid="delete-included-library"
onClick={() => handleDeleteLibrary(library)}
Expand Down
26 changes: 26 additions & 0 deletions src/components/editMeasure/editor/MeasureEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1009,4 +1009,30 @@ describe("EditorWithTerminology", () => {
"Library TestHelpers has been successfully removed from the CQL."
);
});

it("should edit included library successfully", async () => {
const cqlWithIncludes =
"library ApplyLibraryTest version '0.0.000'\nusing QDM version '5.6'\ninclude TestHelpers version '1.0.000' called Helpers";

const cqlWithEdittedIncludes =
"library ApplyLibraryTest version '0.0.000'\nusing QDM version '5.6'\ninclude TestHelpers version '1.0.000' called EditedHelpers";

const measureWithIncludes = {
...measure,
model: Model.QDM_5_6,
cql: cqlWithIncludes,
} as Measure;
renderEditor(measureWithIncludes);

const editIncludeBtn = screen.getByTestId("edit-included-library");
userEvent.click(editIncludeBtn);

await waitFor(() => {
const editor = screen.getByTestId("measure-editor");
expect(editor).toHaveValue(cqlWithEdittedIncludes);
});
expect(screen.getByTestId("measure-editor-toast")).toHaveTextContent(
"Library TestHelpers has been successfully edited in the CQL"
);
});
});
24 changes: 23 additions & 1 deletion src/components/editMeasure/editor/MeasureEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -481,6 +485,23 @@ const MeasureEditor = () => {
setToastOpen(true);
};

const handleEditLibrary = (
sb-prateekkeerthi marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down Expand Up @@ -690,6 +711,7 @@ const MeasureEditor = () => {
handleApplyDefinition={handleApplyDefinition}
handleDefinitionEdit={handleDefinitionEdit}
handleDeleteLibrary={handleDeleteLibrary}
handleEditLibrary={handleEditLibrary}
onChange={(val: string) => handleMadieEditorValue(val)}
value={editorVal}
inboundAnnotations={elmAnnotations}
Expand Down
34 changes: 33 additions & 1 deletion src/components/editMeasure/editor/libraryApplier.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
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";

Expand Down Expand Up @@ -148,4 +152,32 @@ 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'"
);
});
});
6 changes: 6 additions & 0 deletions src/components/editMeasure/editor/libraryApplier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
7 changes: 4 additions & 3 deletions src/types/madie-madie-editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
Loading