Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
merged develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-prateekkeerthi committed Dec 6, 2023
2 parents 407cc78 + 164e199 commit 57a9879
Show file tree
Hide file tree
Showing 14 changed files with 580 additions and 226 deletions.
2 changes: 1 addition & 1 deletion src/components/routes/qiCore/TestCaseRoutes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jest.mock("@madie/madie-util", () => ({
},
useFeatureFlags: jest.fn().mockImplementation(() => ({
applyDefaults: false,
importTestCases: false,
qiCoreBonnieTestCases: false,
})),
useOktaTokens: () => ({
getAccessToken: () => "test.jwt",
Expand Down
2 changes: 1 addition & 1 deletion src/components/testCaseLanding/common/TestCase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const setError = jest.fn();
let mockApplyDefaults = false;
jest.mock("@madie/madie-util", () => ({
useFeatureFlags: () => {
return { applyDefaults: mockApplyDefaults, exportQiCoreBundleType: true };
return { applyDefaults: mockApplyDefaults };
},
}));

Expand Down
3 changes: 1 addition & 2 deletions src/components/testCaseLanding/common/TestCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ const TestCase = ({
>
{viewOrEdit}
</button>
{featureFlags?.exportQiCoreBundleType &&
measure.model.startsWith("QI-Core") ? (
{measure.model.startsWith("QI-Core") ? (
<>
<button
id={`export-transaction-bundle-${testCase.id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand All @@ -75,7 +75,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand All @@ -94,7 +94,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -137,7 +137,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -185,7 +185,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -293,7 +293,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -352,7 +352,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -404,7 +404,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down Expand Up @@ -447,7 +447,7 @@ describe("TestCaseImportFromBonnieDialog", () => {

render(
<TestCaseImportFromBonnieDialog
open={open}
openDialog={open}
handleClose={handleClose}
onImport={onImport}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import Dialog from "@mui/material/Dialog";
import React, { useCallback, useRef, useState } from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import "twin.macro";
import "styled-components/macro";
import { CircularProgress, Divider } from "@mui/material";
import {
Alert,
DialogActions,
DialogContent,
DialogTitle,
Divider,
Paper,
} from "@mui/material";
import Button from "@mui/material/Button";
Button,
Toast,
MadieDialog,
} from "@madie/madie-design-system/dist/react";
import {
processPatientBundles,
readImportFile,
} from "../../../../util/FhirImportHelper";
import { useDropzone } from "react-dropzone";
import { Toast } from "@madie/madie-design-system/dist/react";
import "./TestCaseImportDialog.css";
import * as _ from "lodash";
import useTestCaseServiceApi from "../../../../api/useTestCaseServiceApi";
import { ScanValidationDto } from "../../../../api/models/ScanValidationDto";

const TestCaseImportFromBonnieDialog = ({ open, handleClose, onImport }) => {
const TestCaseImportFromBonnieDialog = ({
openDialog,
handleClose,
onImport,
}) => {
const [file, setFile] = useState(null);
const [fileInputKey, setFileInputKey] = useState(Math.random().toString(36));
const [errorMessage, setErrorMessage] = useState(null);
const [testCases, setTestCases] = useState([]);
const [uploadingFileSpinner, setUploadingFileSpinner] = useState(false);
const testCaseService = useRef(useTestCaseServiceApi());

// Toast utilities
Expand All @@ -36,17 +38,25 @@ const TestCaseImportFromBonnieDialog = ({ open, handleClose, onImport }) => {
setToastOpen(false);
};

useEffect(() => {
if (!openDialog) {
setFile(null);
setTestCases([]);
}
}, [openDialog]);

const showErrorToast = (message: string) => {
setToastOpen(true);
setToastType("danger");
setToastMessage(message);
setErrorMessage(message);
};

const onDrop = useCallback(async (acceptedFiles) => {
setErrorMessage(() => null);
setFileInputKey(Math.random().toString(36));
const importFile = acceptedFiles[0];
let response: ScanValidationDto;
setUploadingFileSpinner(true);
try {
response = await testCaseService.current.scanImportFile(importFile);
} catch (error) {
Expand All @@ -56,11 +66,13 @@ const TestCaseImportFromBonnieDialog = ({ open, handleClose, onImport }) => {
return;
}
if (response.valid) {
setUploadingFileSpinner(false);
setFile(importFile);
let patientBundles;
try {
patientBundles = await readImportFile(importFile);
} catch (error) {
setUploadingFileSpinner(false);
showErrorToast(
"An error occurred while processing the import file. Please try to regenerate the file and re-import, or contact the Help Desk."
);
Expand All @@ -71,46 +83,37 @@ const TestCaseImportFromBonnieDialog = ({ open, handleClose, onImport }) => {
const testCases = processPatientBundles(patientBundles);
setTestCases(testCases);
} catch (error) {
setUploadingFileSpinner(false);
showErrorToast(
"An error occurred while processing the patient bundles. Please try to regenerate the file and re-import, or contact the Help Desk."
);
}
} else {
setUploadingFileSpinner(false);
showErrorToast("No patients were found in the selected import file!");
}
} else {
setUploadingFileSpinner(false);
showErrorToast(response.error.defaultMessage);
}
}, []);
const { getRootProps, getInputProps, isDragActive } = useDropzone({
const { getRootProps, getInputProps, open } = useDropzone({
onDrop,
noClick: true,
noDrag: false,
maxFiles: 1,
multiple: false,
accept: {
"application/json": [".json"],
},
});

const renderFileDrop = () => {
return (
<Paper style={{ padding: 20 }}>
<div
data-testid="file-drop-div"
{...getRootProps({ className: "dropzone" })}
>
<input
data-testid="file-drop-input"
key={fileInputKey}
{...getInputProps()}
/>
{isDragActive ? (
<p>Drop the files here ...</p>
) : (
<p>Drag 'n' drop some files here, or click to select files</p>
)}
</div>
</Paper>
);
const onClose = () => {
setUploadingFileSpinner(false);
setFile(null);
setErrorMessage(null);
setTestCases([]);
handleClose();
};

const renderFileContent = () => {
Expand Down Expand Up @@ -138,53 +141,69 @@ const TestCaseImportFromBonnieDialog = ({ open, handleClose, onImport }) => {
};

return (
<Dialog
open={open}
onClose={handleClose}
data-testid="test-case-import-dialog"
aria-labelledby="responsive-dialog-title"
fullWidth={true}
maxWidth="md"
<MadieDialog
title="Test Case Import"
dialogProps={{
onClose,
open: openDialog,
maxWidth: "md",
fullWidth: true,
}}
cancelButtonProps={{
variant: "secondary",
cancelText: "Cancel",
"data-testid": "test-case-import-cancel-btn",
}}
continueButtonProps={{
variant: "cyan",
type: "submit",
"data-testid": "test-case-import-import-btn",
disabled:
_.isNil(testCases) ||
testCases.length === 0 ||
!_.isEmpty(errorMessage),
continueText: "Import",
onClick: () => onImport(testCases),
}}
>
<DialogTitle id="responsive-dialog-title">Test Case Import</DialogTitle>
<DialogContent>
<DialogContent>
<Alert severity="warning" style={{ marginBottom: 10 }}>
Please Note: Expected Values for group populations are not imported
and must be manually updated!
</Alert>
<div data-testid="test-case-import-error-div">
{errorMessage && <span>{errorMessage}</span>}
</div>
<div data-testid="test-case-import-content-div">
{file ? renderFileContent() : renderFileDrop()}
</div>
</DialogContent>
</DialogContent>
<DialogActions>
<Button
autoFocus
data-testid="test-case-import-cancel-btn"
onClick={() => {
setFile(null);
setErrorMessage(null);
setTestCases([]);
setFileInputKey(Math.random().toString(36));
handleClose();
}}
>
Cancel
</Button>
<Button
onClick={() => onImport(testCases)}
autoFocus
data-testid="test-case-import-import-btn"
disabled={_.isNil(testCases) || testCases.length === 0}
<div data-testid="test-case-import-content-div">
<div
data-testid="file-drop-div"
{...getRootProps({ className: "dropzone" })}
>
Import
</Button>
</DialogActions>

<input data-testid="file-drop-input" {...getInputProps()} />
<span tw="text-black">Drag 'n' drop file to upload </span>
<span tw="pb-3" style={{ color: "#666666" }}>
{" "}
or{" "}
</span>
<Button
variant="outline-filled"
data-testid="select-file-button"
onClick={open}
>
Select File
</Button>
<span tw="pt-3" style={{ color: "#666666" }}>
(.json)
</span>
</div>
{file && renderFileContent()}
{uploadingFileSpinner && (
<div
tw="flex border border-l-4 mt-5 mx-16 mb-1"
data-testid="test-case-preview-header"
>
<div tw="flex items-center ml-80 my-4">
<CircularProgress size={32} />
</div>
</div>
)}
</div>
<div
tw="flex items-center ml-20"
data-testid="test-case-import-error-div"
></div>
<Toast
toastKey="import-tests-toast"
aria-live="polite"
Expand All @@ -198,7 +217,7 @@ const TestCaseImportFromBonnieDialog = ({ open, handleClose, onImport }) => {
onClose={onToastClose}
autoHideDuration={10000}
/>
</Dialog>
</MadieDialog>
);
};

Expand Down
Loading

0 comments on commit 57a9879

Please sign in to comment.