Преглед изворни кода

feat(exam-flow): implement entry to examination process from worklist, historylist and exam button in navigation area
close #35

sw пре 1 месец
родитељ
комит
764ce94cb4
2 измењених фајлова са 46 додато и 1 уклоњено
  1. 43 0
      src/states/hasEnteredExamMonitor.ts
  2. 3 1
      src/states/store.ts

+ 43 - 0
src/states/hasEnteredExamMonitor.ts

@@ -0,0 +1,43 @@
+import { Middleware, PayloadAction } from '@reduxjs/toolkit';
+import { setBusinessFlow } from './BusinessFlowSlice';
+import { RootState } from './store';
+import worklistToExam from '@/domain/patient/worklistToExam';
+
+const hasEnteredExamMonitor: Middleware =
+  (store) => (next) => (action: PayloadAction<string>) => {
+    if (action.type !== setBusinessFlow.type) {
+      return next(action); // Only handle setBusinessFlow actions
+    }
+
+    const state = store.getState() as RootState;
+    const currentKey = state.BusinessFlow.currentKey;
+
+    const result = next(action);
+    try {
+      // Check if transitioning to 'exam'
+      if (currentKey === 'worklist' && action.payload === 'exam') {
+        // User logic placeholder
+        console.log('检查到成功进入了exam,执行用户逻辑');
+        const studyIds = state.workSelection.selectedIds;
+        const tasks = state.workEntities.data.filter((task) =>
+          studyIds.includes(task.StudyID)
+        );
+        worklistToExam(tasks[0]);
+      }
+      if (currentKey === 'historylist' && action.payload === 'exam') {
+        // User logic placeholder
+        console.log('检查到成功从historylist进入了exam,执行用户逻辑');
+        const studyIds = state.historySelection.selectedIds;
+        const tasks = state.historyEntities.data.filter((task) =>
+          studyIds.includes(task.StudyID)
+        );
+        worklistToExam(tasks[0]);
+      }
+    } catch (error) {
+      console.log(`[hasEnteredExamMonitor] ${error}`);
+    }
+
+    return result;
+  };
+
+export default hasEnteredExamMonitor;

+ 3 - 1
src/states/store.ts

@@ -19,6 +19,7 @@ import functionAreaReducer from './view/functionAreaSlice';
 import searchReducer from './patient/worklist/slices/searchSlice';
 import businessFlowMiddleware from './businessFlowMiddleware';
 import leavingRegisterMonitor from './leavingRegisterMonitor';
+import hasEnteredExamMonitor from './hasEnteredExamMonitor';
 import {
   workEntitiesSlice,
   workFiltersSlice,
@@ -81,7 +82,8 @@ const store = configureStore({
       bodyPositionListenerMiddleware,
       aprMiddleware,
       businessFlowMiddleware,
-      leavingRegisterMonitor
+      leavingRegisterMonitor,
+      hasEnteredExamMonitor
     ),
 });