feat: make hanging protocol work on displaySets instead of series (#2837)

* feat(HP): Apply HP to display sets, fix race condition

* fix: displaySetService no event not needed (#2912)

* fix various styles and renamings

* feat: refactored hp service

* fix: use HP service event for viewport grid

* remove unnecessary doc

* fix test

* apply review comment

* fix: segmentation creation

Co-authored-by: Alireza <ar.sedghi@gmail.com>
This commit is contained in:
Bill WallaceandAlireza authored and GitHub committed 2022-09-07 11:59:11 -04:00
1 parent 7c0756824e
commit e1d366e1e1
26 files changed
+893 -979

No files matched your search

+28 -29
View File
@@ -28,32 +28,32 @@ export default function PanelPetSUV({ servicesManager, commandsManager }) {
DisplaySetService,
ToolGroupService,
ToolBarService,
HangingProtocolService,
} = servicesManager.services;
const [metadata, setMetadata] = useState(DEFAULT_MEATADATA);
const [ptDisplaySet, setPtDisplaySet] = useState(null);
const handleMetadataChange = useCallback(
metadata => {
setMetadata(prevState => {
const newState = { ...prevState };
Object.keys(metadata).forEach(key => {
if (typeof metadata[key] === 'object') {
newState[key] = {
...prevState[key],
...metadata[key],
};
} else {
newState[key] = metadata[key];
}
});
return newState;
const handleMetadataChange = metadata => {
setMetadata(prevState => {
const newState = { ...prevState };
Object.keys(metadata).forEach(key => {
if (typeof metadata[key] === 'object') {
newState[key] = {
...prevState[key],
...metadata[key],
};
} else {
newState[key] = metadata[key];
}
});
},
[metadata]
);
return newState;
});
};
const getMatchingPTDisplaySet = useCallback(() => {
const ptDisplaySet = commandsManager.runCommand('getMatchingPTDisplaySet');
const getMatchingPTDisplaySet = viewportMatchDetails => {
const ptDisplaySet = commandsManager.runCommand('getMatchingPTDisplaySet', {
viewportMatchDetails,
});
if (!ptDisplaySet) {
return;
@@ -67,16 +67,16 @@ export default function PanelPetSUV({ servicesManager, commandsManager }) {
ptDisplaySet,
metadata,
};
}, []);
};
useEffect(() => {
const displaySets = DisplaySetService.activeDisplaySets;
const displaySets = DisplaySetService.getActiveDisplaySets();
const { viewportMatchDetails } = HangingProtocolService.getMatchDetails();
if (!displaySets.length) {
return;
}
const displaySetInfo = getMatchingPTDisplaySet();
const displaySetInfo = getMatchingPTDisplaySet(viewportMatchDetails);
if (!displaySetInfo) {
return;
@@ -89,15 +89,14 @@ export default function PanelPetSUV({ servicesManager, commandsManager }) {
// get the patientMetadata from the StudyInstanceUIDs and update the state
useEffect(() => {
const { unsubscribe } = DisplaySetService.subscribe(
DisplaySetService.EVENTS.DISPLAY_SETS_ADDED,
() => {
const displaySetInfo = getMatchingPTDisplaySet();
const { unsubscribe } = HangingProtocolService.subscribe(
HangingProtocolService.EVENTS.PROTOCOL_CHANGED,
({ viewportMatchDetails }) => {
const displaySetInfo = getMatchingPTDisplaySet(viewportMatchDetails);
if (!displaySetInfo) {
return;
}
const { ptDisplaySet, metadata } = displaySetInfo;
setPtDisplaySet(ptDisplaySet);
setMetadata(metadata);
+21 -18
View File
@@ -41,9 +41,9 @@ const commandsModule = ({
}
function _getMatchedViewportsToolGroupIds() {
const [matchedViewports] = HangingProtocolService.getState();
const { viewportMatchDetails } = HangingProtocolService.getMatchDetails();
const toolGroupIds = [];
matchedViewports.forEach(({ viewportOptions }) => {
viewportMatchDetails.forEach(({ viewportOptions }) => {
const { toolGroupId } = viewportOptions;
if (toolGroupIds.indexOf(toolGroupId) === -1) {
toolGroupIds.push(toolGroupId);
@@ -54,33 +54,30 @@ const commandsModule = ({
}
const actions = {
getMatchingPTDisplaySet: () => {
getMatchingPTDisplaySet: ({ viewportMatchDetails }) => {
// Todo: this is assuming that the hanging protocol has successfully matched
// the correct PT. For future, we should have a way to filter out the PTs
// that are in the viewer layout (but then we have the problem of the attenuation
// corrected PT vs the non-attenuation correct PT)
const matches = HangingProtocolService.getDisplaySetsMatchDetails();
const matchedSeriesInstanceUIDs = Array.from(matches.values()).map(
({ SeriesInstanceUID }) => SeriesInstanceUID
);
let ptDisplaySet = null;
for (const SeriesInstanceUID of matchedSeriesInstanceUIDs) {
const displaySets = DisplaySetService.getDisplaySetsForSeries(
SeriesInstanceUID
for (const matched of viewportMatchDetails) {
const { displaySetsInfo } = matched;
const displaySets = displaySetsInfo.map(({ displaySetInstanceUID }) =>
DisplaySetService.getDisplaySetByUID(displaySetInstanceUID)
);
if (!displaySets || displaySets.length === 0) {
continue;
}
const displaySet = displaySets[0];
if (displaySet.Modality !== 'PT') {
continue;
}
ptDisplaySet = displaySets.find(
displaySet => displaySet.Modality === 'PT'
);
ptDisplaySet = displaySet;
if (ptDisplaySet) {
break;
}
}
return ptDisplaySet;
@@ -121,7 +118,10 @@ const commandsModule = ({
createNewLabelmapFromPT: async () => {
// Create a segmentation of the same resolution as the source data
// using volumeLoader.createAndCacheDerivedVolume.
const ptDisplaySet = actions.getMatchingPTDisplaySet();
const { viewportMatchDetails } = HangingProtocolService.getMatchDetails();
const ptDisplaySet = actions.getMatchingPTDisplaySet({
viewportMatchDetails,
});
if (!ptDisplaySet) {
UINotificationService.error('No matching PT display set found');
@@ -565,8 +565,11 @@ const commandsModule = ({
},
setFusionPTColormap: ({ toolGroupId, colormap }) => {
const toolGroup = ToolGroupService.getToolGroup(toolGroupId);
const { viewportMatchDetails } = HangingProtocolService.getMatchDetails();
const ptDisplaySet = actions.getMatchingPTDisplaySet();
const ptDisplaySet = actions.getMatchingPTDisplaySet({
viewportMatchDetails,
});
if (!ptDisplaySet) {
return;