feat(actions): simplify action corner api through the toolbarService (#5033)
This commit is contained in:
1 parent
f71b88e639
commit
7c15bb8901
246 files changed
+7930
-4270
No files matched your search
@@ -4,12 +4,20 @@ import {
|
||||
setupSegmentationDataModifiedHandler,
|
||||
setupSegmentationModifiedHandler,
|
||||
} from './segmentationHandlers';
|
||||
import promptHydrationDialog, {
|
||||
HydrationDialogProps,
|
||||
HydrationCallback,
|
||||
HydrationSRResult,
|
||||
} from './promptHydrationDialog';
|
||||
|
||||
const utils = {
|
||||
handleSegmentChange,
|
||||
isReferenceViewable,
|
||||
setupSegmentationDataModifiedHandler,
|
||||
setupSegmentationModifiedHandler,
|
||||
promptHydrationDialog,
|
||||
};
|
||||
|
||||
export type { HydrationDialogProps, HydrationCallback, HydrationSRResult };
|
||||
|
||||
export default utils;
|
||||
@@ -26,7 +26,7 @@ const Length = {
|
||||
|
||||
const isLocked = getIsLocked(annotationUID);
|
||||
const isVisible = getIsVisible(annotationUID);
|
||||
const colorString = config.style.getStyleProperty('color', { annotationUID });
|
||||
// const colorString = config.style.getStyleProperty('color', { annotationUID });
|
||||
|
||||
// color string is like 'rgb(255, 255, 255)' we need them to be in RGBA array [255, 255, 255, 255]
|
||||
// Todo: this should be in a utility
|
||||
|
||||
@@ -21,7 +21,7 @@ const LivewireContour = {
|
||||
*/
|
||||
toMeasurement: (
|
||||
csToolsEventDetail,
|
||||
DisplaySetService,
|
||||
displaySetService,
|
||||
CornerstoneViewportService,
|
||||
getValueTypeFromToolType,
|
||||
customizationService
|
||||
@@ -43,16 +43,16 @@ const LivewireContour = {
|
||||
}
|
||||
|
||||
const { SOPInstanceUID, SeriesInstanceUID, frameNumber, StudyInstanceUID } =
|
||||
getSOPInstanceAttributes(referencedImageId);
|
||||
getSOPInstanceAttributes(referencedImageId, displaySetService, annotation);
|
||||
|
||||
let displaySet;
|
||||
if (SOPInstanceUID) {
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
displaySet = displaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
displaySet = DisplaySetService.getDisplaySetsForSeries(SeriesInstanceUID);
|
||||
displaySet = displaySetService.getDisplaySetsForSeries(SeriesInstanceUID);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -64,13 +64,14 @@ const LivewireContour = {
|
||||
metadata,
|
||||
frameNumber,
|
||||
referenceSeriesUID: SeriesInstanceUID,
|
||||
referencedImageId,
|
||||
referenceStudyUID: StudyInstanceUID,
|
||||
toolName: metadata.toolName,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
label: data.label,
|
||||
isLocked,
|
||||
isVisible,
|
||||
displayText: getDisplayText(annotation, displaySet),
|
||||
displayText: getDisplayText(annotation, displaySet, displaySetService),
|
||||
data: data.cachedStats,
|
||||
type: getValueTypeFromToolType(toolName),
|
||||
getReport: () => getColumnValueReport(annotation, customizationService),
|
||||
@@ -122,20 +123,27 @@ function getColumnValueReport(annotation, customizationService) {
|
||||
*
|
||||
* @param {Object} annotation - The annotation object.
|
||||
* @param {Object} displaySet - The display set object.
|
||||
* @returns {string[]} - An array of display text.
|
||||
* @returns {object} - An object with primary and secondary text arrays.
|
||||
*/
|
||||
function getDisplayText(annotation, displaySet) {
|
||||
function getDisplayText(annotation, displaySet, displaySetService) {
|
||||
const { metadata, data } = annotation;
|
||||
|
||||
const displayText = {
|
||||
primary: [],
|
||||
secondary: [],
|
||||
};
|
||||
|
||||
if (!data.cachedStats || !data.cachedStats[`imageId:${metadata.referencedImageId}`]) {
|
||||
return [];
|
||||
return displayText;
|
||||
}
|
||||
|
||||
const { area, areaUnit } = data.cachedStats[`imageId:${metadata.referencedImageId}`];
|
||||
|
||||
const { SOPInstanceUID, frameNumber } = getSOPInstanceAttributes(metadata.referencedImageId);
|
||||
|
||||
const displayText = [];
|
||||
const { SOPInstanceUID, frameNumber } = getSOPInstanceAttributes(
|
||||
metadata.referencedImageId,
|
||||
displaySetService,
|
||||
annotation
|
||||
);
|
||||
|
||||
const instance = displaySet.instances.find(image => image.SOPInstanceUID === SOPInstanceUID);
|
||||
let InstanceNumber;
|
||||
@@ -152,21 +160,15 @@ function getDisplayText(annotation, displaySet) {
|
||||
seriesText = `S: ${SeriesNumber}${instanceText}${frameText}`;
|
||||
}
|
||||
|
||||
const texts = [];
|
||||
if (area) {
|
||||
const roundedArea = utils.roundNumber(area || 0, 2);
|
||||
texts.push(`${roundedArea} ${getDisplayUnit(areaUnit)}`);
|
||||
displayText.primary.push(`${roundedArea} ${getDisplayUnit(areaUnit)}`);
|
||||
}
|
||||
|
||||
if (seriesText) {
|
||||
texts.push(seriesText);
|
||||
displayText.secondary.push(seriesText);
|
||||
}
|
||||
|
||||
displayText.push({
|
||||
text: texts,
|
||||
series: seriesText,
|
||||
});
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
export type HydrationCallback = (params: any) => Promise<boolean>;
|
||||
|
||||
export const HydrationType = {
|
||||
SEG: 'SEG',
|
||||
SR: 'SR',
|
||||
RTSTRUCT: 'RTSTRUCT',
|
||||
} as const;
|
||||
|
||||
export interface HydrationDialogProps {
|
||||
servicesManager: AppTypes.ServicesManager;
|
||||
viewportId: string;
|
||||
displaySet: AppTypes.DisplaySet;
|
||||
preHydrateCallbacks?: HydrationCallback[];
|
||||
hydrateCallback: HydrationCallback;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface HydrationSRResult {
|
||||
userResponse: number;
|
||||
displaySetInstanceUID: string;
|
||||
srSeriesInstanceUID: string;
|
||||
viewportId: string;
|
||||
StudyInstanceUID?: string;
|
||||
SeriesInstanceUIDs?: string[];
|
||||
}
|
||||
|
||||
const RESPONSE = {
|
||||
NO_NEVER: -1,
|
||||
CANCEL: 0,
|
||||
CREATE_REPORT: 1,
|
||||
ADD_SERIES: 2,
|
||||
SET_STUDY_AND_SERIES: 3,
|
||||
NO_NOT_FOR_SERIES: 4,
|
||||
HYDRATE: 5,
|
||||
};
|
||||
|
||||
function getCustomizationMessageKey(type: string): string {
|
||||
switch (type) {
|
||||
case HydrationType.RTSTRUCT:
|
||||
return 'viewportNotification.hydrateRTMessage';
|
||||
case HydrationType.SEG:
|
||||
return 'viewportNotification.hydrateSEGMessage';
|
||||
case HydrationType.SR:
|
||||
return 'viewportNotification.hydrateSRMessage';
|
||||
default:
|
||||
return 'viewportNotification.hydrateMessage';
|
||||
}
|
||||
}
|
||||
|
||||
function getDialogId(type: string): string {
|
||||
switch (type) {
|
||||
case HydrationType.RTSS:
|
||||
return 'promptHydrateRT';
|
||||
case HydrationType.SEG:
|
||||
return 'promptHydrateSEG';
|
||||
case HydrationType.SR:
|
||||
return 'promptHydrateSR';
|
||||
default:
|
||||
return 'promptHydrate';
|
||||
}
|
||||
}
|
||||
|
||||
function promptHydrationDialog({
|
||||
servicesManager,
|
||||
viewportId,
|
||||
displaySet,
|
||||
preHydrateCallbacks = [],
|
||||
hydrateCallback,
|
||||
type,
|
||||
}: HydrationDialogProps): Promise<boolean | HydrationSRResult> {
|
||||
const { uiViewportDialogService, customizationService } = servicesManager.services;
|
||||
const extensionManager = servicesManager._extensionManager;
|
||||
const appConfig = extensionManager._appConfig;
|
||||
|
||||
// Todo: make this use enum from the extension, we should move the enum
|
||||
const standardMode = appConfig?.measurementTrackingMode === 'standard';
|
||||
|
||||
return new Promise(async function (resolve, reject) {
|
||||
// For RT and SEG, we check disableConfirmationPrompts
|
||||
// For SR, we check if standardMode is true
|
||||
const shouldPrompt =
|
||||
type === HydrationType.SR ? standardMode : !appConfig?.disableConfirmationPrompts;
|
||||
|
||||
const promptResult = shouldPrompt
|
||||
? await _askHydrate(uiViewportDialogService, customizationService, viewportId, type)
|
||||
: RESPONSE.HYDRATE;
|
||||
|
||||
if (promptResult === RESPONSE.HYDRATE) {
|
||||
// Execute preHydrate callbacks
|
||||
preHydrateCallbacks?.forEach(callback => {
|
||||
callback();
|
||||
});
|
||||
|
||||
if (type === HydrationType.SEG) {
|
||||
// SEG needs setTimeout
|
||||
window.setTimeout(async () => {
|
||||
const isHydrated = await hydrateCallback({
|
||||
segDisplaySet: displaySet,
|
||||
viewportId,
|
||||
});
|
||||
|
||||
resolve(isHydrated);
|
||||
}, 0);
|
||||
} else if (type === HydrationType.RTSTRUCT) {
|
||||
// RT hydration
|
||||
const isHydrated = await hydrateCallback({
|
||||
rtDisplaySet: displaySet,
|
||||
viewportId,
|
||||
servicesManager,
|
||||
});
|
||||
|
||||
resolve(isHydrated);
|
||||
} else if (type === HydrationType.SR) {
|
||||
// SR has a different result structure
|
||||
const hydrationResult = await hydrateCallback(displaySet);
|
||||
|
||||
resolve({
|
||||
userResponse: promptResult,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
srSeriesInstanceUID: displaySet.SeriesInstanceUID,
|
||||
viewportId,
|
||||
StudyInstanceUID: hydrationResult?.StudyInstanceUID,
|
||||
SeriesInstanceUIDs: hydrationResult?.SeriesInstanceUIDs,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (type === HydrationType.SR) {
|
||||
resolve({
|
||||
userResponse: promptResult,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
srSeriesInstanceUID: displaySet.SeriesInstanceUID,
|
||||
viewportId,
|
||||
});
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _askHydrate(
|
||||
uiViewportDialogService: AppTypes.UIViewportDialogService,
|
||||
customizationService: AppTypes.CustomizationService,
|
||||
viewportId: string,
|
||||
type: string
|
||||
) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
const messageKey = getCustomizationMessageKey(type);
|
||||
const message = customizationService.getCustomization(messageKey);
|
||||
const actions = [
|
||||
{
|
||||
id: 'no-hydrate',
|
||||
type: 'secondary',
|
||||
text: 'No',
|
||||
value: RESPONSE.CANCEL,
|
||||
},
|
||||
{
|
||||
id: 'yes-hydrate',
|
||||
type: 'primary',
|
||||
text: 'Yes',
|
||||
value: RESPONSE.HYDRATE,
|
||||
},
|
||||
];
|
||||
const onSubmit = result => {
|
||||
uiViewportDialogService.hide();
|
||||
resolve(result);
|
||||
};
|
||||
|
||||
uiViewportDialogService.show({
|
||||
id: getDialogId(type),
|
||||
viewportId,
|
||||
type: 'info',
|
||||
message,
|
||||
actions,
|
||||
onSubmit,
|
||||
onOutsideClick: () => {
|
||||
uiViewportDialogService.hide();
|
||||
resolve(RESPONSE.CANCEL);
|
||||
},
|
||||
onKeyPress: event => {
|
||||
if (event.key === 'Enter') {
|
||||
onSubmit(RESPONSE.HYDRATE);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default promptHydrationDialog;
|
||||
@@ -2,18 +2,17 @@ import SegmentationServiceType from '../services/SegmentationService';
|
||||
|
||||
export const handleSegmentChange = ({
|
||||
direction,
|
||||
segDisplaySet,
|
||||
segmentationId,
|
||||
viewportId,
|
||||
selectedSegmentObjectIndex,
|
||||
segmentationService,
|
||||
}: {
|
||||
direction: number;
|
||||
segDisplaySet: AppTypes.DisplaySet;
|
||||
segmentationId: string;
|
||||
viewportId: string;
|
||||
selectedSegmentObjectIndex: number;
|
||||
segmentationService: SegmentationServiceType;
|
||||
}) => {
|
||||
const segmentationId = segDisplaySet.displaySetInstanceUID;
|
||||
const segmentation = segmentationService.getSegmentation(segmentationId);
|
||||
|
||||
const { segments } = segmentation;
|
||||
|
||||
Reference in new issue
Block a user