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

Commit

Permalink
Merge pull request #497 from MeasureAuthoringTool/feature/MAT-5706-im…
Browse files Browse the repository at this point in the history
…port-expected-values

MAT-5706: change api call for qdm imports
  • Loading branch information
mcmcphillips authored Nov 27, 2023
2 parents de2f05d + 5c678f2 commit e29ab67
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
19 changes: 19 additions & 0 deletions src/api/useTestCaseServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ export class TestCaseServiceApi {
}
}

async importTestCasesQDM(
measureId: string,
testCasesImportRequest: TestCaseImportRequest[]
): Promise<TestCase[]> {
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<ScanValidationDto> {
try {
const formData = new FormData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<Paper style={{ padding: 20 }}>
Expand Down
7 changes: 5 additions & 2 deletions src/components/testCaseLanding/qdm/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(() => {
Expand Down
21 changes: 9 additions & 12 deletions src/components/testCaseLanding/qdm/TestCaseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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.";
Expand Down Expand Up @@ -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]);
Expand Down
19 changes: 0 additions & 19 deletions src/util/FhirImportHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit e29ab67

Please sign in to comment.