|
@@ -30,11 +30,13 @@ export interface ExtendedBodyPosition extends BodyPosition {
|
|
interface BodyPositionListState {
|
|
interface BodyPositionListState {
|
|
bodyPositions: ExtendedBodyPosition[];
|
|
bodyPositions: ExtendedBodyPosition[];
|
|
selectedBodyPosition: ExtendedBodyPosition | null;
|
|
selectedBodyPosition: ExtendedBodyPosition | null;
|
|
|
|
+ exposureStatus: 'Half Exposed' | 'Fully Exposed' | 'Not Exposed' | null;
|
|
}
|
|
}
|
|
|
|
|
|
const initialState: BodyPositionListState = {
|
|
const initialState: BodyPositionListState = {
|
|
bodyPositions: [],
|
|
bodyPositions: [],
|
|
selectedBodyPosition: null,
|
|
selectedBodyPosition: null,
|
|
|
|
+ exposureStatus: null,
|
|
};
|
|
};
|
|
|
|
|
|
emitter.on('TASK_SUCCESS', (message: MqttMessage) => {
|
|
emitter.on('TASK_SUCCESS', (message: MqttMessage) => {
|
|
@@ -101,6 +103,14 @@ const bodyPositionListSlice = createSlice({
|
|
name: 'bodyPositionList',
|
|
name: 'bodyPositionList',
|
|
initialState,
|
|
initialState,
|
|
reducers: {
|
|
reducers: {
|
|
|
|
+ setExposureStatus: (
|
|
|
|
+ state,
|
|
|
|
+ action: PayloadAction<
|
|
|
|
+ 'Half Exposed' | 'Fully Exposed' | 'Not Exposed' | null
|
|
|
|
+ >
|
|
|
|
+ ) => {
|
|
|
|
+ state.exposureStatus = action.payload;
|
|
|
|
+ },
|
|
addBodyPosition: (state, action: PayloadAction<ExtendedBodyPosition>) => {
|
|
addBodyPosition: (state, action: PayloadAction<ExtendedBodyPosition>) => {
|
|
state.bodyPositions.push(action.payload);
|
|
state.bodyPositions.push(action.payload);
|
|
},
|
|
},
|
|
@@ -125,7 +135,6 @@ const bodyPositionListSlice = createSlice({
|
|
state.selectedBodyPosition = state.bodyPositions[action.payload];
|
|
state.selectedBodyPosition = state.bodyPositions[action.payload];
|
|
}
|
|
}
|
|
},
|
|
},
|
|
-
|
|
|
|
addViewsToBodyPosition: (
|
|
addViewsToBodyPosition: (
|
|
state,
|
|
state,
|
|
action: PayloadAction<{ instanceUid: string; dviews: dview[] }>
|
|
action: PayloadAction<{ instanceUid: string; dviews: dview[] }>
|
|
@@ -143,7 +152,6 @@ const bodyPositionListSlice = createSlice({
|
|
state.bodyPositions.push(newBodyPosition);
|
|
state.bodyPositions.push(newBodyPosition);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
-
|
|
|
|
removeBodyPositionBySopInstanceUid: (
|
|
removeBodyPositionBySopInstanceUid: (
|
|
state,
|
|
state,
|
|
action: PayloadAction<string>
|
|
action: PayloadAction<string>
|
|
@@ -152,7 +160,6 @@ const bodyPositionListSlice = createSlice({
|
|
(bodyPosition) => bodyPosition.sop_instance_uid !== action.payload
|
|
(bodyPosition) => bodyPosition.sop_instance_uid !== action.payload
|
|
);
|
|
);
|
|
},
|
|
},
|
|
-
|
|
|
|
updateBodyPositionDview: (
|
|
updateBodyPositionDview: (
|
|
state,
|
|
state,
|
|
action: PayloadAction<{ sopInstanceUid: string; msg: MqttMessage }>
|
|
action: PayloadAction<{ sopInstanceUid: string; msg: MqttMessage }>
|
|
@@ -192,8 +199,45 @@ const bodyPositionListSlice = createSlice({
|
|
}
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
+ extraReducers: (builder) => {
|
|
|
|
+ builder.addMatcher(
|
|
|
|
+ (action) =>
|
|
|
|
+ action.type === setBodyPositions.type ||
|
|
|
|
+ action.type === addViewsToBodyPosition.type ||
|
|
|
|
+ action.type === removeBodyPositionBySopInstanceUid.type ||
|
|
|
|
+ action.type === updateBodyPositionDview.type,
|
|
|
|
+ (state) => {
|
|
|
|
+ const newExposureStatus = determineExposureStatus(state.bodyPositions);
|
|
|
|
+ state.exposureStatus = newExposureStatus;
|
|
|
|
+ bodyPositionListSlice.caseReducers.setExposureStatus(state, {
|
|
|
|
+ payload: newExposureStatus,
|
|
|
|
+ type: 'setExposureStatus',
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ },
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+const determineExposureStatus = (
|
|
|
|
+ bodyPositions: ExtendedBodyPosition[]
|
|
|
|
+): 'Half Exposed' | 'Fully Exposed' | 'Not Exposed' | null => {
|
|
|
|
+ if (bodyPositions.length === 0) return null;
|
|
|
|
+ const allExposed = bodyPositions.every(
|
|
|
|
+ (bp) => bp.dview.expose_status === 'Exposed'
|
|
|
|
+ );
|
|
|
|
+ const allUnExposed = bodyPositions.every(
|
|
|
|
+ (bp) => bp.dview.expose_status === 'UnExposed'
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (allExposed) {
|
|
|
|
+ return 'Fully Exposed';
|
|
|
|
+ } else if (allUnExposed) {
|
|
|
|
+ return 'Not Exposed';
|
|
|
|
+ } else {
|
|
|
|
+ return 'Half Exposed';
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
export const {
|
|
export const {
|
|
addBodyPosition,
|
|
addBodyPosition,
|
|
setBodyPositions,
|
|
setBodyPositions,
|
|
@@ -201,6 +245,7 @@ export const {
|
|
setByIndex,
|
|
setByIndex,
|
|
addViewsToBodyPosition,
|
|
addViewsToBodyPosition,
|
|
removeBodyPositionBySopInstanceUid,
|
|
removeBodyPositionBySopInstanceUid,
|
|
|
|
+ updateBodyPositionDview,
|
|
} = bodyPositionListSlice.actions;
|
|
} = bodyPositionListSlice.actions;
|
|
export default bodyPositionListSlice.reducer;
|
|
export default bodyPositionListSlice.reducer;
|
|
export { worksListenerMiddleware };
|
|
export { worksListenerMiddleware };
|