|
@@ -1,5 +1,5 @@
|
|
|
-import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
-import { AprConfig } from '../../API/exam/APRActions';
|
|
|
+import { createSlice, PayloadAction, Middleware } from '@reduxjs/toolkit';
|
|
|
+import { AprConfig, getAprExposureParams } from '../../API/exam/APRActions';
|
|
|
|
|
|
interface AprState {
|
|
|
aprConfig: AprConfig;
|
|
@@ -51,6 +51,26 @@ const aprSlice = createSlice({
|
|
|
},
|
|
|
},
|
|
|
});
|
|
|
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
+const aprMiddleware: Middleware = (store) => (next) => (action: any) => {
|
|
|
+ if (
|
|
|
+ action.type === aprSlice.actions.setBodysize.type ||
|
|
|
+ action.type === aprSlice.actions.setWorkstation.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 patientSize = state.apr.bodysize;
|
|
|
+
|
|
|
+ if (state.apr.bodysize && state.apr.workstation) {
|
|
|
+ getAprExposureParams(id, workStationId, patientSize).then((data) => {
|
|
|
+ store.dispatch(setAprConfig(data));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return next(action);
|
|
|
+};
|
|
|
|
|
|
export const {
|
|
|
setAprConfig,
|
|
@@ -60,3 +80,4 @@ export const {
|
|
|
setCurrentExposureMode,
|
|
|
} = aprSlice.actions;
|
|
|
export default aprSlice.reducer;
|
|
|
+export { aprMiddleware };
|