|
@@ -10,9 +10,13 @@ import {
|
|
|
setBodyPositions,
|
|
|
transformWorksToBodyPositions,
|
|
|
} from './exam/bodyPositionListSlice';
|
|
|
-import { worklistToProcess } from '@/domain/patient/worklistToExam';
|
|
|
+import {
|
|
|
+ worklistToProcess,
|
|
|
+ prepareWorksForExam,
|
|
|
+} from '@/domain/patient/worklistToExam';
|
|
|
import { executeRegisterLogic } from '@/domain/patient/registerLogic';
|
|
|
import registerToExam from '@/domain/patient/registerToExam';
|
|
|
+import { addWork, clearWorks } from './exam/examWorksCacheSlice';
|
|
|
|
|
|
let continueBusinessFlow = '';
|
|
|
|
|
@@ -50,20 +54,57 @@ const businessFlowMiddlewareLogic: Middleware =
|
|
|
return;
|
|
|
}
|
|
|
if (currentKey === 'worklist' || currentKey === 'history') {
|
|
|
- //进入检查之前准备数据
|
|
|
const state = store.getState();
|
|
|
- const works = state.examWorksCache.works;
|
|
|
- await transformWorksToBodyPositions(works)
|
|
|
- .then((bodyPositions) => {
|
|
|
- store.dispatch(setBodyPositions(bodyPositions));
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.error(
|
|
|
- '[businessFlowMiddleware] Transform works to body positions failed:',
|
|
|
- error
|
|
|
- );
|
|
|
- return; // 阻止进入exam
|
|
|
- });
|
|
|
+
|
|
|
+ // 获取选中的 study
|
|
|
+ const selectedIds =
|
|
|
+ currentKey === 'worklist'
|
|
|
+ ? state.workSelection.selectedIds
|
|
|
+ : state.historySelection.selectedIds;
|
|
|
+
|
|
|
+ const entitiesData =
|
|
|
+ currentKey === 'worklist'
|
|
|
+ ? state.workEntities.data
|
|
|
+ : state.historyEntities.data;
|
|
|
+
|
|
|
+ if (selectedIds.length === 0) {
|
|
|
+ console.warn('[businessFlowMiddleware] No study selected for exam');
|
|
|
+ return; // 阻止进入 exam
|
|
|
+ }
|
|
|
+
|
|
|
+ const selectedWork = entitiesData.find(
|
|
|
+ (work) => work.StudyID === selectedIds[0]
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!selectedWork) {
|
|
|
+ console.error('[businessFlowMiddleware] Selected study not found');
|
|
|
+ return; // 阻止进入 exam
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用公共函数准备数据
|
|
|
+ const [updatedTask] = await prepareWorksForExam(selectedWork);
|
|
|
+
|
|
|
+ // 清空并更新缓存
|
|
|
+ store.dispatch(clearWorks());
|
|
|
+ store.dispatch(addWork(updatedTask));
|
|
|
+
|
|
|
+ // 转换为 body positions
|
|
|
+ const bodyPositions = await transformWorksToBodyPositions([
|
|
|
+ updatedTask,
|
|
|
+ ]);
|
|
|
+ store.dispatch(setBodyPositions(bodyPositions));
|
|
|
+
|
|
|
+ console.log(
|
|
|
+ `[businessFlowMiddleware] Successfully prepared ${bodyPositions.length} body positions for exam`
|
|
|
+ );
|
|
|
+ } catch (error) {
|
|
|
+ console.error(
|
|
|
+ '[businessFlowMiddleware] Failed to prepare data for exam:',
|
|
|
+ error
|
|
|
+ );
|
|
|
+ return; // 阻止进入 exam
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 进入检查前,如果是从register来的,则判断数据合法性,执行注册等逻辑
|