diff --git a/src/api/useTestCaseServiceApi.ts b/src/api/useTestCaseServiceApi.ts index b830567f8..8e65313cd 100644 --- a/src/api/useTestCaseServiceApi.ts +++ b/src/api/useTestCaseServiceApi.ts @@ -220,6 +220,25 @@ export class TestCaseServiceApi { } } + async importTestCasesQDM( + measureId: string, + testCasesImportRequest: TestCaseImportRequest[] + ): Promise { + try { + return await axios.put( + `${this.baseUrl}/measures/${measureId}/test-cases/imports/qdm`, + testCasesImportRequest, + { + headers: { + Authorization: `Bearer ${this.getAccessToken()}`, + }, + } + ); + } catch (err) { + throw new Error(`Unable to create new test cases`); + } + } + async scanImportFile(file: any): Promise { try { const formData = new FormData(); diff --git a/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx b/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx index e1b810058..a5a098868 100644 --- a/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx +++ b/src/components/testCaseLanding/common/import/TestCaseImportFromBonnieDialogQDM.tsx @@ -9,16 +9,14 @@ import { Paper, } from "@mui/material"; import Button from "@mui/material/Button"; -import { - processPatientBundlesForQDM, - readImportFile, -} from "../../../../util/FhirImportHelper"; +import { 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"; +import { TestCaseImportRequest } from "@madie/madie-models"; const TestCaseImportFromBonnieDialogQDM = ({ open, handleClose, onImport }) => { const [file, setFile] = useState(null); @@ -91,6 +89,19 @@ const TestCaseImportFromBonnieDialogQDM = ({ open, handleClose, onImport }) => { }, }); + function processPatientBundlesForQDM( + bonniePatients + ): TestCaseImportRequest[] { + const testCases: TestCaseImportRequest[] = []; + for (const patient of bonniePatients) { + testCases.push({ + patientId: "", + json: JSON.stringify(patient), + } as TestCaseImportRequest); + } + return testCases; + } + const renderFileDrop = () => { return ( diff --git a/src/components/testCaseLanding/qdm/TestCaseList.test.tsx b/src/components/testCaseLanding/qdm/TestCaseList.test.tsx index 00bd9bb60..5557d35d6 100644 --- a/src/components/testCaseLanding/qdm/TestCaseList.test.tsx +++ b/src/components/testCaseLanding/qdm/TestCaseList.test.tsx @@ -472,6 +472,7 @@ const useTestCaseServiceMockResolved = { .fn() .mockResolvedValue(["Series 1", "Series 2"]), createTestCases: jest.fn().mockResolvedValue([]), + importTestCasesQDM: jest.fn().mockResolvedValue([]), } as unknown as TestCaseServiceApi; // mocking measureService @@ -1111,7 +1112,7 @@ describe("TestCaseList component", () => { expect(nextState).toEqual([]); }); - it("should display import error when createTestCases call fails", async () => { + it("should display import error when importTestCasesQDM call fails", async () => { (checkUserCanEdit as jest.Mock).mockClear().mockImplementation(() => true); (useFeatureFlags as jest.Mock).mockClear().mockImplementation(() => ({ importTestCases: true, @@ -1122,7 +1123,9 @@ describe("TestCaseList component", () => { getTestCaseSeriesForMeasure: jest .fn() .mockResolvedValue(["Series 1", "Series 2"]), - createTestCases: jest.fn().mockRejectedValueOnce(new Error("BAD THINGS")), + importTestCasesQDM: jest + .fn() + .mockRejectedValueOnce(new Error("BAD THINGS")), } as unknown as TestCaseServiceApi; useTestCaseServiceMock.mockImplementation(() => { diff --git a/src/components/testCaseLanding/qdm/TestCaseList.tsx b/src/components/testCaseLanding/qdm/TestCaseList.tsx index 7848935e9..479b33a7b 100644 --- a/src/components/testCaseLanding/qdm/TestCaseList.tsx +++ b/src/components/testCaseLanding/qdm/TestCaseList.tsx @@ -2,8 +2,11 @@ import React, { useEffect, useRef, useState } from "react"; import "twin.macro"; import "styled-components/macro"; import * as _ from "lodash"; -import { Group, TestCase, MeasureErrorType } from "@madie/madie-models"; -import { QDMPatient } from "cqm-models"; +import { + Group, + MeasureErrorType, + TestCaseImportRequest, +} from "@madie/madie-models"; import { useParams } from "react-router-dom"; import calculationService from "../../../api/CalculationService"; import { DetailedPopulationGroupResult } from "fqm-execution/build/types/Calculator"; @@ -26,6 +29,7 @@ import qdmCalculationService, { CqmExecutionResultsByPatient, } from "../../../api/QdmCalculationService"; import TestCaseImportFromBonnieDialogQDM from "../common/import/TestCaseImportFromBonnieDialogQDM"; +import { QDMPatient, DataElement } from "cqm-models"; export const IMPORT_ERROR = "An error occurred while importing your test cases. Please try again, or reach out to the Help Desk."; @@ -286,22 +290,15 @@ const TestCaseList = (props: TestCaseListProps) => { ? Object.keys(calculationOutput).length : 0; - const onTestCaseImport = async (testCases: TestCase[]) => { + const onTestCaseImport = async (testCases: TestCaseImportRequest[]) => { setImportDialogState({ ...importDialogState, open: false }); setLoadingState(() => ({ loading: true, message: "Importing Test Cases...", })); - testCases = testCases.map((testCase) => { - if (testCase.json) { - testCase.json = JSON.stringify( - new QDMPatient(JSON.parse(testCase.json)) - ); - } - return testCase; - }); + try { - await testCaseService.current.createTestCases(measureId, testCases); + await testCaseService.current.importTestCasesQDM(measureId, testCases); retrieveTestCases(); } catch (error) { setErrors((prevState) => [...prevState, IMPORT_ERROR]); diff --git a/src/util/FhirImportHelper.ts b/src/util/FhirImportHelper.ts index 40edacfb6..cc53b26b0 100644 --- a/src/util/FhirImportHelper.ts +++ b/src/util/FhirImportHelper.ts @@ -31,25 +31,6 @@ export function processPatientBundles(patientBundles): TestCase[] { return testCases; } -export function processPatientBundlesForQDM(bonniePatients): TestCase[] { - const testCases: TestCase[] = []; - for (const patient of bonniePatients) { - const familyName = patient?.familyName || ""; - const givenName = patient?.givenNames?.[0] || ""; - - testCases.push({ - id: "", - title: givenName, - series: familyName, - description: patient?.notes, - createdAt: new Date().toISOString(), - json: JSON.stringify(patient.qdmPatient, null, 4), - groupPopulations: [], - } as TestCase); - } - return testCases; -} - // TODO: Refactor to dedup with useTestCaseService::readTestCaseFile export function readImportFile(importFile): Promise { return new Promise((resolve, reject) => {