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