| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- import { addWork, clearWorks } from '../../states/exam/examWorksCacheSlice';
- import { setBusinessFlow } from '../../states/BusinessFlowSlice';
- import { fetchTaskDetails } from '../../API/patient/workActions';
- import { Series } from '@/domain/series';
- import { XImage } from '@/domain/xImage';
- import store from '@/states/store';
- import { Task } from '@/domain/work';
- import { dview } from '../dview';
- import {
- transformWorksToBodyPositions,
- setBodyPositions,
- } from '../../states/exam/bodyPositionListSlice';
- /**
- * 准备一个或多个 work 的详细数据用于检查
- * @param works - 单个 Task 对象或 Task 数组
- * @returns 包含完整 Views 数据的 Task 数组
- */
- export const prepareWorksForExam = async (
- works: Task | Task[]
- ): Promise<Task[]> => {
- // 统一转为数组处理
- const workArray = Array.isArray(works) ? works : [works];
- // 并行获取所有 work 的详细数据
- const preparedWorks = await Promise.all(
- workArray.map(async (work) => {
- const taskDetails = await fetchTaskDetails(work.StudyID);
- return {
- ...work,
- Views: taskDetails.series.flatMap<dview>((series: Series) =>
- series.images.map<dview>(
- (image: XImage) =>
- ({
- view_id: image.view_id,
- series_instance_uid: series.series_instance_uid,
- study_instance_uid: taskDetails.study_instance_uid,
- study_id: taskDetails.study_id,
- procedure_id: series.procedure_id,
- view_description: image.view_description,
- view_type: '',
- PrimarySopUID: image.sop_instance_uid,
- expose_status: image.expose_status,
- judged_status: image.judged_status,
- image_file_path: image.image_file_path,
- image_file: image.image_file_path,
- thumbnail_file: image.thumbnail_file || '',
- }) satisfies dview
- )
- ),
- } as Task;
- })
- );
- return preparedWorks;
- };
- const worklistToExam = async (task: Task) => {
- const dispatch = store.dispatch;
- try {
- // 使用公共函数准备数据
- const [updatedTask] = await prepareWorksForExam(task);
- console.log('[worklist进入检查] after prepareWorksForExam');
- // 判断所有体位是否已曝光(需要检查 Views 不为空)
- const allExposed =
- updatedTask.Views.length > 0 &&
- updatedTask.Views.every((view) => view.expose_status === 'Exposed');
- console.log('[worklist进入检查] 判断曝光情况,是否全部体位已曝光:', allExposed);
- // Clear existing works in the cache
- await dispatch(clearWorks());
- // Save the updated task to the cache
- await dispatch(addWork(updatedTask));
- // 需要先转换为体位列表
- const bodyPositions = await transformWorksToBodyPositions([updatedTask]);
- dispatch(setBodyPositions(bodyPositions));
- // 根据曝光状态决定跳转目标
- if (allExposed) {
- // 所有体位已曝光 - 直接进入处理界面
- dispatch(setBusinessFlow('process'));
- } else {
- // 有未曝光体位 - 进入检查界面
- dispatch(setBusinessFlow('exam'));
- }
- } catch (error) {
- console.error('Error in worklistToExam:', error);
- throw error;
- }
- };
- // 批量处理多个选中工单进入图像处理
- const worklistToProcess = async (selectedIds: string[]) => {
- const dispatch = store.dispatch;
- try {
- // Clear existing works in the cache
- dispatch(clearWorks());
- // 批量处理选中的工单
- for (const studyId of selectedIds) {
- // 获取基础Task信息
- const state = store.getState();
- const baseTask = state.workEntities.data.find(
- (task) => task.StudyID === studyId
- );
- if (!baseTask) {
- console.warn(`Task with StudyID ${studyId} not found in workEntities`);
- continue;
- }
- // Fetch task details from the backend
- const taskDetails = await fetchTaskDetails(studyId);
- // Map the fetched task details to the Task type (复用现有映射逻辑)
- const updatedTask: Task = {
- ...baseTask,
- Views: taskDetails.series.flatMap<dview>((series: Series) =>
- series.images.map<dview>(
- (image: XImage) =>
- ({
- view_id: image.view_id,
- series_instance_uid: series.series_instance_uid,
- study_instance_uid: taskDetails.study_instance_uid,
- study_id: taskDetails.study_id,
- procedure_id: series.procedure_id,
- view_description: image.view_description,
- view_type: '',
- PrimarySopUID: image.sop_instance_uid,
- expose_status: image.expose_status,
- judged_status: image.judged_status,
- image_file_path: image.image_file_path,
- image_file: image.image_file_path,
- thumbnail_file: image.thumbnail_file || '',
- }) satisfies dview
- )
- ),
- };
- // Save the updated task to the cache
- dispatch(addWork(updatedTask));
- }
- // 转换为体位列表
- const works = store.getState().examWorksCache.works;
- transformWorksToBodyPositions(works).then((bodyPositions) => {
- store.dispatch(setBodyPositions(bodyPositions));
- });
- } catch (error) {
- console.error('Error in worklistToProcess:', error);
- throw error;
- }
- };
- export default worklistToExam;
- export { worklistToProcess };
|