|
@@ -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;
|