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-7246 QDM - Remove Value Set Versions from CQL and notify user #146

Merged
merged 3 commits into from
Jun 21, 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
23 changes: 15 additions & 8 deletions src/components/editCqlLibrary/EditCqlLibrary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,16 @@ describe("Edit Cql Library Component", () => {
).toBeDisabled();
});

it("should update an existing cql library with the synched cql library name, version and display a warning message", async () => {
it("should revert change in library statement, using statement and value version if encountered", async () => {
(synchingEditorCqlContent as jest.Mock)
.mockClear()
.mockImplementation(() => {
return "library UpdateName version '1.0.000'";
return {
cql: "library UpdateName version '1.0.000'",
isLibraryStatementChanged: true,
isUsingStatementChanged: false,
isValueSetChanged: false,
};
});
mockedAxios.put.mockResolvedValue({
data: {
Expand Down Expand Up @@ -541,12 +546,16 @@ describe("Edit Cql Library Component", () => {
await waitFor(() => {
const successMessage = screen.getByTestId("generic-success-text-header");
expect(successMessage.textContent).toEqual(
"CQL updated successfully! Library Statement or Using Statement were incorrect. MADiE has overwritten them to ensure proper CQL."
"CQL updated successfully but the following issues were found"
);
});
const warningMessage = screen.getByTestId("library-warning");
expect(warningMessage.textContent).toEqual(
"Library statement was incorrect. MADiE has overwritten it."
);
});

it("should update an existing cql library with the synched cql library name, version and warn about blank using", async () => {
it("should update an existing cql library with the updated cql library name, version and warn about blank using", async () => {
(synchingEditorCqlContent as jest.Mock)
.mockClear()
.mockImplementation(() => {
Expand Down Expand Up @@ -601,7 +610,7 @@ describe("Edit Cql Library Component", () => {
await waitFor(() => {
const successMessage = screen.getByTestId("generic-success-text-header");
expect(successMessage.textContent).toEqual(
"CQL updated successfully but was missing a Using statement. Please add in a valid model and version."
"CQL updated successfully but the following issues were found"
);
});
});
Expand Down Expand Up @@ -692,9 +701,7 @@ describe("Edit Cql Library Component", () => {
userEvent.click(updateButton);
await waitFor(() => {
const successMessage = screen.getByTestId("generic-success-text-header");
expect(successMessage.textContent).toEqual(
"CQL Library saved successfully"
);
expect(successMessage.textContent).toEqual("CQL updated successfully");
expect(mockedAxios.put).toHaveBeenCalledTimes(1);
});
expect(mockedAxios.put.mock.lastCall[0]).toEqual(
Expand Down
75 changes: 45 additions & 30 deletions src/components/editCqlLibrary/EditCqlLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
// StatusHandler utilities
const [success, setSuccess] = useState({
status: undefined,
message: undefined,
primaryMessage: undefined,
secondaryMessages: undefined,
});
const [error, setError] = useState(false);
const [errorMessage, setErrorMessage] = useState<string>(null);
Expand Down Expand Up @@ -136,7 +137,11 @@

const onChange = (value) => {
formik.setFieldValue("cql", value);
setSuccess({ status: undefined, message: undefined });
setSuccess({
status: undefined,
primaryMessage: undefined,
secondaryMessages: undefined,
});
setError(false);
setErrorMessage(undefined);
setValuesetMsg(undefined);
Expand All @@ -160,7 +165,7 @@
setErrorMessage("An error occurred while fetching the CQL Library!");
});
}
}, [id, resetForm, loadedCqlLibrary, cqlLibraryServiceApi]);

Check warning on line 168 in src/components/editCqlLibrary/EditCqlLibrary.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has a missing dependency: 'handleAnnotations'. Either include it or remove the dependency array

// fetch organizations DB using measure service and sorts alphabetically
useEffect(() => {
Expand All @@ -176,12 +181,12 @@
const message = `Error fetching organizations`;
handleToast("danger", message, true);
});
}, []);

Check warning on line 184 in src/components/editCqlLibrary/EditCqlLibrary.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has a missing dependency: 'organizationApi'. Either include it or remove the dependency array

async function updateCqlLibrary(cqlLibrary: CqlLibrary) {
setActiveSpinner(true);
const using = loadedCqlLibrary?.model.split(" v");
const inSyncCql = await synchingEditorCqlContent(
const updatedContent = await synchingEditorCqlContent(
formik.values.cql?.trim() ?? "",
loadedCqlLibrary?.cql,
formik.values.cqlLibraryName,
Expand All @@ -191,9 +196,7 @@
using[1],
"updateCqlLibrary"
);

const results = await executeCqlParsingForErrors(inSyncCql);

const results = await executeCqlParsingForErrors(updatedContent.cql);
if (results[0].status === "rejected") {
console.error(
"An error occurred while translating CQL to ELM",
Expand Down Expand Up @@ -223,38 +226,50 @@
_.filter(validationResult?.errors, { errorSeverity: "Error" })
) || !_.isEmpty(validationResult?.externalErrors);

const cqlErrors = inSyncCql?.trim().length
const cqlErrors = updatedContent.cql?.trim().length
? parseErrors || cqlElmErrors
: false;
const synchedCqlLibrary = { ...cqlLibrary, cql: inSyncCql, cqlErrors };
const updatedLibrary = {
...cqlLibrary,
cql: updatedContent.cql,
cqlErrors,
};
cqlLibraryServiceApi
.updateCqlLibrary(synchedCqlLibrary)
.updateCqlLibrary(updatedLibrary)
.then((response) => {
cqlLibraryStore.updateLibrary(response.data);
setLoadedCqlLibrary(response.data);
resetForm();
if (cqlLibrary.cql?.trim() && isUsingEmpty(cqlLibrary.cql.trim())) {
setSuccess({
status: "success",
message:
"CQL updated successfully but was missing a Using statement. Please add in a valid model and version.",
});
} else {
const successMessage =
cqlLibrary.cql !== null &&
inSyncCql &&
inSyncCql?.trim() !== cqlLibrary.cql.trim()
? {
status: "success",
message:
"CQL updated successfully! Library Statement or Using Statement were incorrect. MADiE has overwritten them to ensure proper CQL.",
}
: {
status: "success",
message: "CQL Library saved successfully",
};
setSuccess(successMessage);
let primaryMessage = "CQL updated successfully";
const secondaryMessages = [];
if (isUsingEmpty(updatedContent.cql)) {
secondaryMessages.push(
"Missing a using statement. Please add in a valid model and version."
);
}
if (updatedContent.isLibraryStatementChanged) {
secondaryMessages.push(
"Library statement was incorrect. MADiE has overwritten it."
);
}
if (updatedContent.isUsingStatementChanged) {
secondaryMessages.push(
"Using statement was incorrect. MADiE has overwritten it."
);
}
if (updatedContent.isValueSetChanged) {
secondaryMessages.push(
"MADiE does not currently support use of value set version directly in library at this time. Your value set versions have been removed. Please use the relevant manifest for value set expansion for testing."
);
}
if (secondaryMessages.length > 0) {
primaryMessage += " but the following issues were found";
}
setSuccess({
status: "success",
primaryMessage,
secondaryMessages,
});
})
.catch((error) => {
setError(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
line-height: normal;
}
.secondary {
margin-bottom: 5px;
margin-bottom: 12px;
~ ul,
~ ol {
margin-bottom: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ describe("StatusHandler Component", () => {
it("Should display a success message and a library warning if a library warning exists when no error or messages present, also displays a list of annotations", () => {
const success = {
status: "success",
message:
"CQL updated successfully! Library Statement or Using Statement were incorrect. MADiE has overwritten them to ensure proper CQL.",
primaryMessage:
"CQL updated successfully but the following issues were found",
secondaryMessages: [
"Library statement was incorrect. MADiE has overwritten it",
"Using statement was incorrect. MADiE has overwritten it",
],
};
render(
<StatusHandler
Expand All @@ -35,10 +39,10 @@ describe("StatusHandler Component", () => {
);

expect(getByTestId("generic-success-text-header")).toHaveTextContent(
"Changes saved successfully but the following issues were found"
success.primaryMessage
);
expect(screen.getByTestId("library-warning")).toHaveTextContent(
success.message
success.secondaryMessages.join("")
);
const errorsList = screen.getByTestId("generic-errors-text-list");
expect(errorsList).toBeInTheDocument();
Expand All @@ -55,8 +59,12 @@ describe("StatusHandler Component", () => {
it("Should display a success message and a using warning if a using warning exists when no error or messages present, also displays a list of annotations", () => {
const success = {
status: "success",
message:
"CQL updated successfully but was missing a Using statement. Please add in a valid model and version.",
primaryMessage:
"CQL updated successfully but the following issues were found",
secondaryMessages: [
"Library statement was incorrect. MADiE has overwritten it",
"Using statement was incorrect. MADiE has overwritten it",
],
};
render(
<StatusHandler
Expand All @@ -68,9 +76,8 @@ describe("StatusHandler Component", () => {
);

expect(getByTestId("generic-success-text-header")).toHaveTextContent(
"Changes saved successfully but the following issues were found"
success.primaryMessage
);
expect(screen.queryByTestId("library-warning")).not.toBeInTheDocument();
const errorsList = screen.getByTestId("generic-errors-text-list");
expect(errorsList).toBeInTheDocument();
expect(errorsList).toHaveTextContent(
Expand All @@ -86,7 +93,7 @@ describe("StatusHandler Component", () => {
it("Should display a success message along with annotation", () => {
const success = {
status: "success",
message: "stuff saved successfully",
primaryMessage: "stuff saved successfully",
};
render(
<StatusHandler
Expand All @@ -98,7 +105,7 @@ describe("StatusHandler Component", () => {
);

expect(getByTestId("generic-success-text-header")).toHaveTextContent(
"Changes saved successfully but the following issues were found"
success.primaryMessage
);
expect(screen.queryByTestId("library-warning")).not.toBeInTheDocument();
const errorsList = screen.getByTestId("generic-errors-text-list");
Expand All @@ -116,7 +123,7 @@ describe("StatusHandler Component", () => {
it("Should display a generic success message when no annotations or messages are present", () => {
const success = {
status: "success",
message: "stuff saved successfully",
primaryMessage: "stuff saved successfully",
};
render(
<StatusHandler
Expand All @@ -128,7 +135,7 @@ describe("StatusHandler Component", () => {
);

expect(getByTestId("generic-success-text-header")).toHaveTextContent(
success.message
success.primaryMessage
);
expect(
screen.queryByTestId("generic-errors-text-list")
Expand All @@ -143,7 +150,7 @@ describe("StatusHandler Component", () => {
it("Should display an error message with provided errorMessage and annotations", () => {
const success = {
status: undefined,
message: "",
primaryMessage: "",
};
const errorMessage = "CQL problem please help";
render(
Expand Down Expand Up @@ -173,7 +180,7 @@ describe("StatusHandler Component", () => {
it("Should display an error message with provided error message and no annotations", () => {
const success = {
status: undefined,
message: "",
primaryMessage: "",
};
const errorMessage = "CQL problem please help";
render(
Expand All @@ -200,7 +207,7 @@ describe("StatusHandler Component", () => {
it("Should display a generic error message along with annotations provided", () => {
const success = {
status: undefined,
message: "",
primaryMessage: "",
};
render(
<StatusHandler
Expand Down Expand Up @@ -229,7 +236,7 @@ describe("StatusHandler Component", () => {
it("Should display a generic error message when no error message or annotations are provided, but error flag is true", () => {
const success = {
status: undefined,
message: "",
primaryMessage: "",
};
render(
<StatusHandler
Expand All @@ -255,7 +262,7 @@ describe("StatusHandler Component", () => {
it("Should display outbound annotation even when Error flag is false", () => {
const success = {
status: undefined,
message: "",
primaryMessage: "",
};
render(
<StatusHandler
Expand Down
40 changes: 15 additions & 25 deletions src/components/editCqlLibrary/statusHandler/StatusHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as _ from "lodash";
const generateMadieAlertWithContent = (
type,
header,
secondaryMessage,
secondaryMessages,
outboundAnnotations
) => {
const errorAnnotation = _.filter(outboundAnnotations, { type: "error" });
Expand All @@ -31,9 +31,13 @@ const generateMadieAlertWithContent = (
>
{header}
</h3>
{secondaryMessage && (
{secondaryMessages?.length > 0 && (
<p className="secondary" data-testid="library-warning">
{secondaryMessage}
<ul style={{ listStyle: "inside" }}>
{secondaryMessages.map((message) => (
<li>{message}</li>
))}
</ul>
</p>
)}
{errors?.length > 0 && (
Expand Down Expand Up @@ -73,31 +77,17 @@ const StatusHandler = ({
}) => {
if (success.status === "success") {
if (outboundAnnotations?.length > 0) {
if (
success.message ===
"CQL updated successfully but was missing a Using statement. Please add in a valid model and version." ||
success.message ===
"CQL updated successfully! Library Statement or Using Statement were incorrect. MADiE has overwritten them to ensure proper CQL."
) {
return generateMadieAlertWithContent(
success.status,
"Changes saved successfully but the following issues were found",
success.message,
outboundAnnotations
);
} else {
return generateMadieAlertWithContent(
success.status,
"Changes saved successfully but the following issues were found",
null,
outboundAnnotations
);
}
return generateMadieAlertWithContent(
success.status,
success.primaryMessage,
success.secondaryMessages,
outboundAnnotations
);
} else {
return generateMadieAlertWithContent(
success.status,
success.message,
null,
success.primaryMessage,
success.secondaryMessages,
null
);
}
Expand Down
Loading