From 834bbefab156611556ee66d66db8f1a6b0e8e195 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Tue, 3 Sep 2024 14:23:18 +0100 Subject: [PATCH] fix(OH2-374): Fix exams state --- .../accessories/patientExams/PatientExams.tsx | 2 +- src/state/laboratories/slice.ts | 20 +++++++++++++++---- src/state/laboratories/thunk.ts | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/accessories/patientExams/PatientExams.tsx b/src/components/accessories/patientExams/PatientExams.tsx index 190faef5f..f72c82961 100644 --- a/src/components/accessories/patientExams/PatientExams.tsx +++ b/src/components/accessories/patientExams/PatientExams.tsx @@ -33,8 +33,8 @@ import ConfirmationDialog from "../confirmationDialog/ConfirmationDialog"; import InfoBox from "../infoBox/InfoBox"; import { initialRequestFields } from "../laboratory/consts"; import ExamRequestForm from "../laboratory/examRequestForm/ExamRequestForm"; -import { initialFields } from "./consts"; import ExamForm from "./ExamForm/ExamForm"; +import { initialFields } from "./consts"; import PatientExamRequestsTable from "./patientExamRequestsTable/PatientExamRequestsTable"; import PatientExamsTable from "./patientExamsTable/PatientExamsTable"; import "./styles.scss"; diff --git a/src/state/laboratories/slice.ts b/src/state/laboratories/slice.ts index 7ab25443c..fdb62fc1d 100644 --- a/src/state/laboratories/slice.ts +++ b/src/state/laboratories/slice.ts @@ -1,8 +1,8 @@ import { createSlice } from "@reduxjs/toolkit"; +import { isEmpty } from "lodash"; +import { ApiResponse } from "state/types"; import { initial } from "./initial"; import * as thunks from "./thunk"; -import { ApiResponse } from "state/types"; -import { isEmpty } from "lodash"; export const laboratorySlice = createSlice({ name: "laboratories", @@ -46,8 +46,7 @@ export const laboratorySlice = createSlice({ state.searchLabs = ApiResponse.loading(); }) .addCase(thunks.searchLabs.fulfilled, (state, action) => { - state.searchLabs = - ApiResponse.value(action.payload); + state.searchLabs = ApiResponse.value(action.payload); }) .addCase(thunks.searchLabs.rejected, (state, action) => { state.searchLabs = ApiResponse.error(action.payload); @@ -65,6 +64,19 @@ export const laboratorySlice = createSlice({ .addCase(thunks.getLabsByPatientId.rejected, (state, action) => { state.labsByPatientId = ApiResponse.error(action.payload); }) + // Get Lab Requests By Patient ID + .addCase(thunks.getLabsRequestByPatientId.pending, (state) => { + state.labsRequestByPatientId = ApiResponse.loading(); + }) + .addCase(thunks.getLabsRequestByPatientId.fulfilled, (state, action) => { + state.labsRequestByPatientId.status = isEmpty(action.payload) + ? "SUCCESS_EMPTY" + : "SUCCESS"; + state.labsRequestByPatientId.data = action.payload as any; + }) + .addCase(thunks.getLabsRequestByPatientId.rejected, (state, action) => { + state.labsRequestByPatientId = ApiResponse.error(action.payload); + }) // Get Lab By Code .addCase(thunks.getLabByCode.pending, (state) => { state.getLabByCode = ApiResponse.loading(); diff --git a/src/state/laboratories/thunk.ts b/src/state/laboratories/thunk.ts index 65f4ea7d5..782a34eab 100644 --- a/src/state/laboratories/thunk.ts +++ b/src/state/laboratories/thunk.ts @@ -35,7 +35,7 @@ export const getLabsByPatientId = createAsyncThunk( .getLaboratory1({ patId: patId ?? -1 }) .toPromise() .then((result) => - result.map((item) => + (result ?? []).map((item) => item.laboratoryDTO ? item : { laboratoryDTO: item } ) )