Przeglądaj źródła

feat(exam->exit exam): send notification to service with study id when user selects 'Continue Check'

sw 1 miesiąc temu
rodzic
commit
36fe31c0f2

+ 15 - 0
src/API/patient/workActions.ts

@@ -337,3 +337,18 @@ const deleteStudies = async (
 };
 
 export { deleteStudies };
+// eslint-disable-next-line
+const suspendOrCompleteStudy = async (studyId: string, studyStatus: 'InProgress' | 'Completed'): Promise<{ code: string; description: string; solution: string; data: {} }> => {
+  try {
+    const response = await axiosInstance.post('/auth/task/inspection/leave', {
+      study_id: studyId,
+      study_status: studyStatus,
+    });
+    return response.data;
+  } catch (error) {
+    console.error('Error suspending or completing study:', error);
+    throw error;
+  }
+};
+
+export { suspendOrCompleteStudy };

+ 13 - 2
src/states/businessFlowMiddlewareLogic.ts

@@ -2,11 +2,13 @@ import { Middleware, PayloadAction } from '@reduxjs/toolkit';
 import prepare, { unprepare } from '../domain/exam/prepare';
 import { BusinessFlowState, setBusinessFlow } from './BusinessFlowSlice';
 import { setFeedbackOpen } from './exam/largeScreenSlice';
+import { suspendOrCompleteStudy } from '@/API/patient/workActions';
+import { RootState } from './store';
 
 let continueBusinessFlow = '';
 
 const businessFlowMiddlewareLogic: Middleware =
-  (store) => (next) => (action: PayloadAction<string>) => {
+  (store) => (next) => async (action: PayloadAction<string>) => {
     //const result = next(action);
     // console.log(
     //   `[businessFlowMiddleware] Action dispatched: ${action.type} ${action.payload}`
@@ -81,7 +83,16 @@ const businessFlowMiddlewareLogic: Middleware =
       return next({ ...action, payload: continueBusinessFlow });
     }
     if (action.payload === 'exitExamSuspended') {
-      // Notify backend with different interfaces for completed and suspended 暂时不通知后端
+      // Notify backend with different interfaces for completed and suspended
+      const studyId =
+        (store.getState() as RootState)?.bodyPositionList?.selectedBodyPosition
+          ?.work?.StudyID ?? '';
+      if (!studyId) {
+        console.error(
+          '[businessFlowMiddleware] No study ID found for the selected body position.'
+        );
+      }
+      await suspendOrCompleteStudy(studyId, 'InProgress');
       console.log(
         `[businessFlowMiddleware] Notifying backend for ${action.payload}`
       );