|
@@ -2,6 +2,9 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
import { View as BodyPosition } from '../../API/patient/viewActions';
|
|
|
import { Work } from './examWorksCacheSlice';
|
|
|
import { dview } from '@/domain/dview';
|
|
|
+import emitter from '@/utils/eventEmitter';
|
|
|
+import store from '@/states/store';
|
|
|
+import { MqttMessage } from '@/domain/mqttService';
|
|
|
|
|
|
export interface ExtendedBodyPosition extends BodyPosition {
|
|
|
patient_name: string;
|
|
@@ -31,6 +34,22 @@ const initialState: BodyPositionListState = {
|
|
|
selectedBodyPosition: null,
|
|
|
};
|
|
|
|
|
|
+emitter.on('TASK_SUCCESS', (message: MqttMessage) => {
|
|
|
+ console.log(
|
|
|
+ `[bodyPositionListSlice] TASK_SUCCESS received with message:`,
|
|
|
+ message
|
|
|
+ );
|
|
|
+ const { sop } = message;
|
|
|
+ if (sop) {
|
|
|
+ store.dispatch(
|
|
|
+ bodyPositionListSlice.actions.updateBodyPositionDview({
|
|
|
+ sopInstanceUid: sop,
|
|
|
+ msg: message,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
const bodyPositionListSlice = createSlice({
|
|
|
name: 'bodyPositionList',
|
|
|
initialState,
|
|
@@ -86,6 +105,45 @@ const bodyPositionListSlice = createSlice({
|
|
|
(bodyPosition) => bodyPosition.sop_instance_uid !== action.payload
|
|
|
);
|
|
|
},
|
|
|
+
|
|
|
+ updateBodyPositionDview: (
|
|
|
+ state,
|
|
|
+ action: PayloadAction<{ sopInstanceUid: string; msg: MqttMessage }>
|
|
|
+ ) => {
|
|
|
+ const { sopInstanceUid, msg } = action.payload;
|
|
|
+ const index = state.bodyPositions.findIndex(
|
|
|
+ (bp) => bp.sop_instance_uid === sopInstanceUid
|
|
|
+ );
|
|
|
+ if (index === -1) {
|
|
|
+ console.warn(
|
|
|
+ `[bodyPositionListSlice] updateBodyPositionDview: No body position found for SOP Instance UID ${sopInstanceUid}`
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(
|
|
|
+ `[bodyPositionListSlice] updateBodyPositionDview: Updating body position for SOP Instance UID ${sopInstanceUid} with message ${JSON.stringify(msg)} `
|
|
|
+ );
|
|
|
+ const updatedBodyPosition = {
|
|
|
+ ...state.bodyPositions[index],
|
|
|
+ sop_instance_uid: sopInstanceUid,
|
|
|
+ dview: {
|
|
|
+ ...state.bodyPositions[index].dview,
|
|
|
+ PrimarySopUID: sopInstanceUid,
|
|
|
+ thumbnail_file: msg.thumbnail ?? '',
|
|
|
+ image_file: msg.dcm ?? '',
|
|
|
+ expose_status: 'Exposed',
|
|
|
+ } satisfies dview,
|
|
|
+ };
|
|
|
+ state.bodyPositions[index] = updatedBodyPosition;
|
|
|
+ console.log(
|
|
|
+ `[bodyPositionListSlice] updateBodyPositionDview: Updated body position:`,
|
|
|
+ updatedBodyPosition
|
|
|
+ );
|
|
|
+ // Ensure the selectedBodyPosition is updated if it matches the updated bodyPosition
|
|
|
+ if (state.selectedBodyPosition?.sop_instance_uid === sopInstanceUid) {
|
|
|
+ state.selectedBodyPosition = updatedBodyPosition;
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
});
|
|
|
|