Browse Source

完善检查模块,实现切换工作位和体型后获取apr曝光参数并显示

dengdx 2 weeks ago
parent
commit
8a2a7ed5e1
3 changed files with 41 additions and 6 deletions
  1. 22 6
      src/states/exam/aprSlice.ts
  2. 4 0
      src/states/exam/bodyPositionListener.ts
  3. 15 0
      src/states/workstation.ts

+ 22 - 6
src/states/exam/aprSlice.ts

@@ -1,5 +1,6 @@
 import { createSlice, PayloadAction, Middleware } from '@reduxjs/toolkit';
 import { AprConfig, getAprExposureParams } from '../../API/exam/APRActions';
+import { workstationIdFromWorkstation } from '../workstation';
 
 interface AprState {
   aprConfig: AprConfig;
@@ -57,16 +58,31 @@ const aprMiddleware: Middleware = (store) => (next) => (action: any) => {
     action.type === aprSlice.actions.setBodysize.type ||
     action.type === aprSlice.actions.setWorkstation.type
   ) {
+    console.log('APR Middleware triggered:', action.type);
     const state = store.getState();
     const id =
       state.bodyPositionList.selectedBodyPosition?.view_id || 'default_id'; // Dynamically determined based on selectedBodyPosition
-    const workStationId = parseInt(state.apr.workstation, 10);
+    const workStationId = workstationIdFromWorkstation(state.apr.workstation);
     const patientSize = state.apr.bodysize;
-
-    if (state.apr.bodysize && state.apr.workstation) {
-      getAprExposureParams(id, workStationId, patientSize).then((data) => {
-        store.dispatch(setAprConfig(data));
-      });
+    console.log(
+      `Fetching APR exposure parameters for ID: ${id}, Workstation ID: ${workStationId}, Patient Size: ${patientSize}`
+    );
+    // Fetch APR exposure parameters based on the current state
+    if (!!patientSize && workStationId !== 0) {
+      getAprExposureParams(id, workStationId, patientSize)
+        .then((data) => {
+          console.log('Received APR exposure parameters:', data);
+          // Dispatch the action to set the APR config in the store
+          if (data) {
+            store.dispatch(setAprConfig(data));
+          }
+        })
+        .catch((error) => {
+          console.error('Error fetching APR exposure parameters:', error);
+        })
+        .finally(() => {
+          console.log('APR exposure parameters fetch attempt finished.');
+        });
     }
   }
   return next(action);

+ 4 - 0
src/states/exam/bodyPositionListener.ts

@@ -16,7 +16,11 @@ bodyPositionListener.startListening({
       const patientSize = selectedBodyPosition.work.PatientSize;
       const workstationId = selectedBodyPosition.work_station_id;
       const workstation = workstationFromWorkstationId(workstationId);
+      console.log(
+        `Selected body position: ${selectedBodyPosition.view_name}, Patient Size: ${patientSize}, Workstation: ${workstation}`
+      );
       listenerApi.dispatch(setBodysize(patientSize));
+      console.log(`Setting workstation to: ${workstation}`);
       listenerApi.dispatch(setWorkstation(workstation));
     }
   },

+ 15 - 0
src/states/workstation.ts

@@ -25,3 +25,18 @@ export function workstationFromWorkstationId(id: number) {
       return WorkstationType.Free;
   }
 }
+
+export function workstationIdFromWorkstation(type: WorkstationType) {
+  switch (type) {
+    case WorkstationType.Free:
+      return 1;
+    case WorkstationType.Direct:
+      return 2;
+    case WorkstationType.Table:
+      return 3;
+    case WorkstationType.Wall:
+      return 4;
+    default:
+      return 0;
+  }
+}