@ohif/extension-default 3.14.0-beta.98 → 3.14.0-beta.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ohif-extension-default.umd.js +1 -1
- package/package.json +9 -6
- package/src/Actions/createReportAsync.tsx +45 -0
- package/src/Components/DataSourceConfigurationComponent.tsx +142 -0
- package/src/Components/DataSourceConfigurationModalComponent.tsx +200 -0
- package/src/Components/ItemListComponent.tsx +95 -0
- package/src/Components/LineChartViewport/LineChartViewport.tsx +31 -0
- package/src/Components/LineChartViewport/index.ts +1 -0
- package/src/Components/MoreDropdownMenu.tsx +112 -0
- package/src/Components/ProgressDropdownWithService.tsx +101 -0
- package/src/Components/SidePanelWithServices.tsx +122 -0
- package/src/CustomizableContextMenu/ContextMenuController.tsx +216 -0
- package/src/CustomizableContextMenu/ContextMenuItemsBuilder.test.js +29 -0
- package/src/CustomizableContextMenu/ContextMenuItemsBuilder.ts +176 -0
- package/src/CustomizableContextMenu/index.ts +5 -0
- package/src/CustomizableContextMenu/types.ts +126 -0
- package/src/DataSourceConfigurationAPI/GoogleCloudDataSourceConfigurationAPI.ts +236 -0
- package/src/DicomJSONDataSource/index.js +326 -0
- package/src/DicomLocalDataSource/index.js +273 -0
- package/src/DicomTagBrowser/DicomTagBrowser.css +49 -0
- package/src/DicomTagBrowser/DicomTagBrowser.tsx +454 -0
- package/src/DicomTagBrowser/DicomTagTable.tsx +311 -0
- package/src/DicomWebDataSource/dcm4cheeReject.js +45 -0
- package/src/DicomWebDataSource/exampleInstances.js +280 -0
- package/src/DicomWebDataSource/index.ts +808 -0
- package/src/DicomWebDataSource/qido.js +215 -0
- package/src/DicomWebDataSource/retrieveBulkData.test.ts +35 -0
- package/src/DicomWebDataSource/retrieveBulkData.ts +31 -0
- package/src/DicomWebDataSource/retrieveRendered.test.ts +147 -0
- package/src/DicomWebDataSource/retrieveRendered.ts +141 -0
- package/src/DicomWebDataSource/retrieveStudyMetadata.js +108 -0
- package/src/DicomWebDataSource/retrieveStudyMetadata.test.js +75 -0
- package/src/DicomWebDataSource/retrieveThumbnail.ts +346 -0
- package/src/DicomWebDataSource/serviceUrls.test.ts +143 -0
- package/src/DicomWebDataSource/utils/StaticWadoClient.ts +272 -0
- package/src/DicomWebDataSource/utils/cleanDenaturalizedDataset.ts +78 -0
- package/src/DicomWebDataSource/utils/findIndexOfString.ts +47 -0
- package/src/DicomWebDataSource/utils/fixBulkDataURI.test.ts +68 -0
- package/src/DicomWebDataSource/utils/fixBulkDataURI.ts +78 -0
- package/src/DicomWebDataSource/utils/fixMultiValueKeys.ts +12 -0
- package/src/DicomWebDataSource/utils/fixMultipart.ts +70 -0
- package/src/DicomWebDataSource/utils/getImageId.js +54 -0
- package/src/DicomWebDataSource/utils/getWADORSImageId.js +51 -0
- package/src/DicomWebDataSource/utils/index.ts +9 -0
- package/src/DicomWebDataSource/utils/retrieveMetadataFiltered.js +61 -0
- package/src/DicomWebDataSource/wado/retrieveMetadata.js +41 -0
- package/src/DicomWebDataSource/wado/retrieveMetadataLoader.js +64 -0
- package/src/DicomWebDataSource/wado/retrieveMetadataLoaderAsync.js +159 -0
- package/src/DicomWebDataSource/wado/retrieveMetadataLoaderSync.js +58 -0
- package/src/DicomWebProxyDataSource/index.ts +90 -0
- package/src/MergeDataSource/index.test.ts +212 -0
- package/src/MergeDataSource/index.ts +319 -0
- package/src/MergeDataSource/types.ts +46 -0
- package/src/Panels/DataSourceSelector.tsx +55 -0
- package/src/Panels/StudyBrowser/PanelStudyBrowser.tsx +612 -0
- package/src/Panels/StudyBrowser/PanelStudyBrowserHeader.tsx +88 -0
- package/src/Panels/StudyBrowser/constants/actionIcons.ts +12 -0
- package/src/Panels/StudyBrowser/constants/index.ts +4 -0
- package/src/Panels/StudyBrowser/constants/viewPresets.ts +16 -0
- package/src/Panels/StudyBrowser/resolveThumbnailDetails.test.ts +197 -0
- package/src/Panels/StudyBrowser/resolveThumbnailDetails.ts +132 -0
- package/src/Panels/StudyBrowser/types/actionIcon.ts +9 -0
- package/src/Panels/StudyBrowser/types/index.ts +4 -0
- package/src/Panels/StudyBrowser/types/viewPreset.ts +7 -0
- package/src/Panels/WrappedPanelStudyBrowser.tsx +61 -0
- package/src/Panels/createReportDialogPrompt.tsx +128 -0
- package/src/Panels/debounce.js +25 -0
- package/src/Panels/getImageSrcFromImageId.js +16 -0
- package/src/Panels/getStudiesForPatientByMRN.js +19 -0
- package/src/Panels/index.js +5 -0
- package/src/Panels/requestDisplaySetCreationForStudy.js +19 -0
- package/src/SOPClassHandlers/chartSOPClassHandler.test.ts +81 -0
- package/src/SOPClassHandlers/chartSOPClassHandler.ts +127 -0
- package/src/Toolbar/ToolBoxWrapper.tsx +64 -0
- package/src/Toolbar/ToolButtonListWrapper.tsx +77 -0
- package/src/Toolbar/ToolButtonWrapper.tsx +32 -0
- package/src/Toolbar/ToolRowWrapper.tsx +41 -0
- package/src/Toolbar/Toolbar.tsx +98 -0
- package/src/Toolbar/ToolbarDivider.tsx +5 -0
- package/src/Toolbar/ToolbarLayoutSelector.tsx +195 -0
- package/src/Toolbar/index.ts +7 -0
- package/src/ViewerLayout/HeaderPatientInfo/HeaderPatientInfo.tsx +96 -0
- package/src/ViewerLayout/HeaderPatientInfo/index.js +3 -0
- package/src/ViewerLayout/HeaderUndoRedo.tsx +47 -0
- package/src/ViewerLayout/ResizablePanelsHook.tsx +334 -0
- package/src/ViewerLayout/ViewerHeader.tsx +124 -0
- package/src/ViewerLayout/constants/panels.ts +42 -0
- package/src/ViewerLayout/index.tsx +227 -0
- package/src/ViewerLayout/useUndoRedoState.ts +75 -0
- package/src/__tests__/commandsModuleToggleOneUp.test.ts +147 -0
- package/src/commandsModule.ts +970 -0
- package/src/customizations/aboutModalCustomization.tsx +42 -0
- package/src/customizations/appearanceModalCustomization.tsx +143 -0
- package/src/customizations/contextMenuCustomization.ts +25 -0
- package/src/customizations/contextMenuUICustomization.ts +5 -0
- package/src/customizations/customRoutesCustomization.ts +6 -0
- package/src/customizations/dataSourceConfigurationCustomization.ts +19 -0
- package/src/customizations/datasourcesCustomization.tsx +14 -0
- package/src/customizations/defaultContextMenuCustomization.ts +22 -0
- package/src/customizations/hangingProtocolsCustomization.ts +15 -0
- package/src/customizations/headerRightSideCustomization.ts +19 -0
- package/src/customizations/helloPageCustomization.tsx +14 -0
- package/src/customizations/hideHeaderUndoRedoCustomization.ts +22 -0
- package/src/customizations/hotkeyBindingsCustomization.ts +5 -0
- package/src/customizations/instanceSortingCriteriaCustomization.ts +6 -0
- package/src/customizations/labellingFlowCustomization.tsx +5 -0
- package/src/customizations/loadingIndicatorProgressCustomization.tsx +5 -0
- package/src/customizations/loadingIndicatorTotalPercentCustomization.tsx +5 -0
- package/src/customizations/menuContentCustomization.tsx +67 -0
- package/src/customizations/metadataContextCustomization.test.ts +22 -0
- package/src/customizations/metadataContextCustomization.ts +28 -0
- package/src/customizations/metadataDisplaySetCustomization.ts +55 -0
- package/src/customizations/missingReferenceDisplaySetHandler.ts +5 -0
- package/src/customizations/multimonitorCustomization.ts +63 -0
- package/src/customizations/notificationCustomization.ts +29 -0
- package/src/customizations/onDropHandlerCustomization.ts +5 -0
- package/src/customizations/onboardingCustomization.ts +200 -0
- package/src/customizations/overlayItemCustomization.tsx +33 -0
- package/src/customizations/progressDropdownCustomization.ts +5 -0
- package/src/customizations/progressLoadingBarCustomization.tsx +5 -0
- package/src/customizations/reportDialogCustomization.test.ts +701 -0
- package/src/customizations/reportDialogCustomization.tsx +661 -0
- package/src/customizations/sortingCriteriaCustomization.ts +14 -0
- package/src/customizations/studyBrowserCustomization.test.ts +69 -0
- package/src/customizations/studyBrowserCustomization.ts +95 -0
- package/src/customizations/thumbnailDetailsCustomization.ts +91 -0
- package/src/customizations/userPreferencesCustomization.tsx +342 -0
- package/src/customizations/workListCustomization.ts +107 -0
- package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.test.ts +181 -0
- package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.ts +240 -0
- package/src/displaySetSplitting/makeImageSetDisplaySet.ts +276 -0
- package/src/displaySetSplitting/stackSopClassUids.ts +60 -0
- package/src/displaySetSplitting/urlSplitModules.test.ts +333 -0
- package/src/findViewportsByPosition.ts +102 -0
- package/src/getCustomizationModule.tsx +109 -0
- package/src/getDataSourcesModule.js +44 -0
- package/src/getDisplaySetMessages.ts +54 -0
- package/src/getDisplaySetsFromUnsupportedSeries.js +63 -0
- package/src/getDisplaySetsFromUnsupportedSeries.test.js +14 -0
- package/src/getHangingProtocolModule.js +155 -0
- package/src/getLayoutTemplateModule.js +28 -0
- package/src/getPTImageIdInstanceMetadata.test.ts +102 -0
- package/src/getPTImageIdInstanceMetadata.ts +124 -0
- package/src/getPanelModule.tsx +29 -0
- package/src/getSopClassHandlerModule.js +152 -0
- package/src/getSopClassHandlerModule.test.js +78 -0
- package/src/getToolbarModule.tsx +63 -0
- package/src/getViewportModule.tsx +12 -0
- package/src/hangingprotocols/hpCompare.ts +189 -0
- package/src/hangingprotocols/hpEcgCustomization.test.ts +104 -0
- package/src/hangingprotocols/hpMNGrid.test.ts +120 -0
- package/src/hangingprotocols/hpMNGrid.ts +419 -0
- package/src/hangingprotocols/hpMammo.ts +202 -0
- package/src/hangingprotocols/hpScale.ts +132 -0
- package/src/hangingprotocols/index.ts +16 -0
- package/src/hangingprotocols/protocolMatchChanges.test.ts +73 -0
- package/src/hangingprotocols/utils/isNewestOfModality.ts +19 -0
- package/src/hangingprotocols/utils/laterality.ts +9 -0
- package/src/hangingprotocols/utils/mammoDisplaySetSelector.ts +214 -0
- package/src/hangingprotocols/utils/registerHangingProtocolAttributes.ts +14 -0
- package/src/hangingprotocols/utils/seriesSelectors.ts +62 -0
- package/src/hangingprotocols/utils/studySelectors.ts +14 -0
- package/src/hangingprotocols/utils/viewCode.test.js +25 -0
- package/src/hangingprotocols/utils/viewCode.ts +17 -0
- package/src/hangingprotocols/utils/viewportOptions.ts +18 -0
- package/src/hooks/usePatientInfo.tsx +63 -0
- package/src/id.js +5 -0
- package/src/index.ts +113 -0
- package/src/init.ts +169 -0
- package/src/stores/index.ts +7 -0
- package/src/stores/useDisplaySetSelectorStore.ts +83 -0
- package/src/stores/useHangingProtocolStageIndexStore.ts +76 -0
- package/src/stores/useToggleHangingProtocolStore.ts +76 -0
- package/src/stores/useToggleOneUpViewportGridStore.ts +19 -0
- package/src/stores/useUIStateStore.ts +87 -0
- package/src/stores/useViewportGridStore.ts +89 -0
- package/src/stores/useViewportsByPositionStore.ts +100 -0
- package/src/types/AppTypes.ts +20 -0
- package/src/types/commandModuleTypes.tsx +6 -0
- package/src/utils/Toolbox.tsx +123 -0
- package/src/utils/_shared/PROMPT_RESPONSES.ts +10 -0
- package/src/utils/addIcon.ts +6 -0
- package/src/utils/appendFrameQueryToImageId.js +9 -0
- package/src/utils/callInputDialog.tsx +126 -0
- package/src/utils/colorPickerDialog.css +4 -0
- package/src/utils/colorPickerDialog.tsx +45 -0
- package/src/utils/createRenderedRetrieve.js +32 -0
- package/src/utils/createRenderedRetrieve.test.js +46 -0
- package/src/utils/dicomWriter.test.ts +228 -0
- package/src/utils/dicomWriter.ts +110 -0
- package/src/utils/getBulkdataValue.js +45 -0
- package/src/utils/getBulkdataValue.test.js +105 -0
- package/src/utils/getDirectURL.test.ts +207 -0
- package/src/utils/getDirectURL.ts +65 -0
- package/src/utils/getSRSeriesAndInstanceNumber.js +48 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/layerConfigurationUtils.ts +202 -0
- package/src/utils/promptLabelAnnotation.js +47 -0
- package/src/utils/promptSaveReport.test.ts +106 -0
- package/src/utils/promptSaveReport.tsx +117 -0
- package/src/utils/registerNaturalizedDatasetForLocalWadouri.js +146 -0
- package/src/utils/registerNaturalizedDatasetForLocalWadouri.test.js +177 -0
- package/src/utils/registerStoredInstanceImageId.test.ts +73 -0
- package/src/utils/registerStoredInstanceImageId.ts +66 -0
- package/src/utils/reuseCachedLayouts.ts +92 -0
- package/src/utils/secureConfigFetch.js +115 -0
- package/src/utils/secureConfigFetch.test.js +163 -0
- package/src/utils/seriesDescriptionHistory.ts +83 -0
- package/src/utils/validations/areAllImageComponentsEqual.ts +24 -0
- package/src/utils/validations/areAllImageDimensionsEqual.test.ts +41 -0
- package/src/utils/validations/areAllImageDimensionsEqual.ts +27 -0
- package/src/utils/validations/areAllImagePositionsEqual.ts +75 -0
- package/src/utils/validations/areAllImageSpacingEqual.ts +66 -0
- package/src/utils/validations/checkMultiframe.ts +25 -0
- package/src/utils/validations/checkSingleFrames.ts +36 -0
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
import { Types, DicomMetadataStore, utils } from '@ohif/core';
|
|
2
|
+
import { datasetToDicomBlob, setNonEnumerableInstanceProperty } from './utils/dicomWriter';
|
|
3
|
+
import { registerNaturalizedDatasetsForLocalWadouri } from './utils/registerNaturalizedDatasetForLocalWadouri';
|
|
4
|
+
import { registerStoredInstanceImageIds } from './utils/registerStoredInstanceImageId';
|
|
5
|
+
|
|
6
|
+
const { downloadBlob } = utils;
|
|
7
|
+
|
|
8
|
+
import { ContextMenuController } from './CustomizableContextMenu';
|
|
9
|
+
import DicomTagBrowser from './DicomTagBrowser/DicomTagBrowser';
|
|
10
|
+
import reuseCachedLayouts from './utils/reuseCachedLayouts';
|
|
11
|
+
import {
|
|
12
|
+
configureViewportForLayerAddition,
|
|
13
|
+
configureViewportForLayerRemoval,
|
|
14
|
+
canAddDisplaySetToViewport,
|
|
15
|
+
DERIVED_OVERLAY_MODALITIES,
|
|
16
|
+
} from './utils/layerConfigurationUtils';
|
|
17
|
+
import findViewportsByPosition, {
|
|
18
|
+
findOrCreateViewport as layoutFindOrCreate,
|
|
19
|
+
} from './findViewportsByPosition';
|
|
20
|
+
|
|
21
|
+
import { ContextMenuProps } from './CustomizableContextMenu/types';
|
|
22
|
+
import { NavigateHistory } from './types/commandModuleTypes';
|
|
23
|
+
import { history } from '@ohif/app';
|
|
24
|
+
import { useViewportGridStore } from './stores/useViewportGridStore';
|
|
25
|
+
import { useDisplaySetSelectorStore } from './stores/useDisplaySetSelectorStore';
|
|
26
|
+
import { useHangingProtocolStageIndexStore } from './stores/useHangingProtocolStageIndexStore';
|
|
27
|
+
import { useToggleHangingProtocolStore } from './stores/useToggleHangingProtocolStore';
|
|
28
|
+
import { useViewportsByPositionStore } from './stores/useViewportsByPositionStore';
|
|
29
|
+
import { useToggleOneUpViewportGridStore } from './stores/useToggleOneUpViewportGridStore';
|
|
30
|
+
import requestDisplaySetCreationForStudy from './Panels/requestDisplaySetCreationForStudy';
|
|
31
|
+
import promptSaveReport from './utils/promptSaveReport';
|
|
32
|
+
|
|
33
|
+
export type HangingProtocolParams = {
|
|
34
|
+
protocolId?: string;
|
|
35
|
+
stageIndex?: number;
|
|
36
|
+
activeStudyUID?: string;
|
|
37
|
+
stageId?: string;
|
|
38
|
+
reset?: false;
|
|
39
|
+
restoreCachedLayout?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type UpdateViewportDisplaySetParams = {
|
|
43
|
+
direction: number;
|
|
44
|
+
excludeNonImageModalities?: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const commandsModule = ({
|
|
48
|
+
servicesManager,
|
|
49
|
+
commandsManager,
|
|
50
|
+
extensionManager,
|
|
51
|
+
}: Types.Extensions.ExtensionParams): Types.Extensions.CommandsModule => {
|
|
52
|
+
const {
|
|
53
|
+
customizationService,
|
|
54
|
+
measurementService,
|
|
55
|
+
hangingProtocolService,
|
|
56
|
+
uiNotificationService,
|
|
57
|
+
viewportGridService,
|
|
58
|
+
displaySetService,
|
|
59
|
+
multiMonitorService,
|
|
60
|
+
} = servicesManager.services;
|
|
61
|
+
|
|
62
|
+
// Define a context menu controller for use with any context menus
|
|
63
|
+
const contextMenuController = new ContextMenuController(servicesManager, commandsManager);
|
|
64
|
+
|
|
65
|
+
const actions = {
|
|
66
|
+
/**
|
|
67
|
+
* Adds a display set as a layer to the specified viewport
|
|
68
|
+
*
|
|
69
|
+
* @param options.viewportId - The ID of the viewport to add the layer to
|
|
70
|
+
* @param options.displaySetInstanceUID - The UID of the display set to add as a layer
|
|
71
|
+
* @param options.removeFirst - Optional flag to remove the display set first if it's already added
|
|
72
|
+
*/
|
|
73
|
+
addDisplaySetAsLayer: ({ viewportId, displaySetInstanceUID, removeFirst = false }) => {
|
|
74
|
+
if (!viewportId) {
|
|
75
|
+
const { activeViewportId } = servicesManager.services.viewportGridService.getState();
|
|
76
|
+
viewportId = activeViewportId;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!viewportId || !displaySetInstanceUID) {
|
|
80
|
+
console.warn('Missing required parameters for addDisplaySetAsLayer command');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const { displaySetService, viewportGridService, hangingProtocolService } =
|
|
85
|
+
servicesManager.services;
|
|
86
|
+
|
|
87
|
+
// Get the display set
|
|
88
|
+
const displaySet = displaySetService.getDisplaySetByUID(displaySetInstanceUID);
|
|
89
|
+
if (!displaySet) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Get current display sets for the viewport
|
|
94
|
+
const currentDisplaySetUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
|
95
|
+
|
|
96
|
+
// Check if we can add this display set to the viewport
|
|
97
|
+
const canAdd = canAddDisplaySetToViewport({
|
|
98
|
+
viewportId,
|
|
99
|
+
displaySetInstanceUID,
|
|
100
|
+
servicesManager,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (!canAdd) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Adding a layer is a per-viewport action: it shows the display set in the
|
|
108
|
+
// one viewport it is given, and leaves `isHydrated` and the segmentation
|
|
109
|
+
// presentation store alone. Those two are display-set-global ("show this
|
|
110
|
+
// wherever it logically belongs"), so a viewport re-created after a
|
|
111
|
+
// per-viewport add re-applies whatever hydration says rather than
|
|
112
|
+
// inheriting the add. The global statement is made by the hydration
|
|
113
|
+
// commands (hydrateSecondaryDisplaySet / loadSegmentationDisplaySetsForViewport
|
|
114
|
+
// in extensions/cornerstone), which record it themselves; the removal
|
|
115
|
+
// counterpart here is `removeDisplaySetLayer`'s `unhydrate` flag, which
|
|
116
|
+
// exists because removal has callers that are themselves global.
|
|
117
|
+
//
|
|
118
|
+
// Add the display set to the viewport
|
|
119
|
+
const updatedViewports = hangingProtocolService.getViewportsRequireUpdate(
|
|
120
|
+
viewportId,
|
|
121
|
+
displaySetInstanceUID
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Configure each viewport for layer addition
|
|
125
|
+
updatedViewports.forEach(viewport => {
|
|
126
|
+
configureViewportForLayerAddition({
|
|
127
|
+
viewport,
|
|
128
|
+
displaySetInstanceUID,
|
|
129
|
+
currentDisplaySetUIDs,
|
|
130
|
+
servicesManager,
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Update position presentation
|
|
135
|
+
commandsManager.runCommand('updateStoredPositionPresentation', {
|
|
136
|
+
viewportId,
|
|
137
|
+
displaySetInstanceUIDs: updatedViewports[0].displaySetInstanceUIDs,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Run command to update viewports
|
|
141
|
+
commandsManager.run('setDisplaySetsForViewports', {
|
|
142
|
+
viewportsToUpdate: updatedViewports,
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Removes a display set layer from the specified viewport
|
|
148
|
+
*
|
|
149
|
+
* @param options.viewportId - The ID of the viewport to remove the layer from
|
|
150
|
+
* @param options.displaySetInstanceUID - The UID of the display set to remove
|
|
151
|
+
* @param options.unhydrate - Whether this removal also means "stop showing
|
|
152
|
+
* this display set anywhere" (see the note below).
|
|
153
|
+
*/
|
|
154
|
+
removeDisplaySetLayer: ({ viewportId, displaySetInstanceUID, unhydrate = false }) => {
|
|
155
|
+
if (!viewportId || !displaySetInstanceUID) {
|
|
156
|
+
console.warn('Missing required parameters for removeDisplaySetLayer command');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const {
|
|
161
|
+
displaySetService,
|
|
162
|
+
viewportGridService,
|
|
163
|
+
hangingProtocolService,
|
|
164
|
+
segmentationService,
|
|
165
|
+
} = servicesManager.services;
|
|
166
|
+
|
|
167
|
+
// Get the display set
|
|
168
|
+
const displaySet = displaySetService.getDisplaySetByUID(displaySetInstanceUID);
|
|
169
|
+
if (!displaySet) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Check if it's a segmentation and handle accordingly.
|
|
174
|
+
// Note that for the sake of hydrated segmentations, we remove the
|
|
175
|
+
// segmentation before checking if the display set is indeed in the viewport.
|
|
176
|
+
// This is because hydrated segmentations are not in the viewport per se
|
|
177
|
+
// {i.e. they are not layered) but are simply referenced by the display
|
|
178
|
+
// set in the viewport.
|
|
179
|
+
const isSegmentation = DERIVED_OVERLAY_MODALITIES.includes(displaySet.Modality);
|
|
180
|
+
if (isSegmentation) {
|
|
181
|
+
segmentationService.removeRepresentationsFromViewport(viewportId, {
|
|
182
|
+
segmentationId: displaySetInstanceUID,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// By default this command is the single-viewport primitive: it removes
|
|
186
|
+
// the layer from the one viewport it is given and leaves
|
|
187
|
+
// `displaySet.isHydrated` and the segmentation presentation store alone,
|
|
188
|
+
// both of which are display-set-global ("show this wherever it
|
|
189
|
+
// logically belongs"). That is what the viewport overlay menu wants -
|
|
190
|
+
// its Remove hides the overlay here, and a viewport re-created later
|
|
191
|
+
// re-applies whatever hydration says. Clearing them unconditionally
|
|
192
|
+
// would also let a layer *replacement* (remove + add) silently
|
|
193
|
+
// un-hydrate the display set everywhere.
|
|
194
|
+
//
|
|
195
|
+
// `unhydrate: true` is the global statement, used by the removal paths
|
|
196
|
+
// that are themselves global - the segmentation panel's Remove from
|
|
197
|
+
// Viewport, and the SEGMENTATION_REMOVED handler in
|
|
198
|
+
// extensions/cornerstone/src/utils/setUpSegmentationEventHandlers.ts
|
|
199
|
+
// (which records it itself, before this loop over viewports). Recording
|
|
200
|
+
// `hydrated: false` rather than dropping the entry keeps the store a
|
|
201
|
+
// statement of desired state, so a viewport created later converges on
|
|
202
|
+
// "not shown" instead of replaying an earlier `hydrated: true`.
|
|
203
|
+
if (unhydrate) {
|
|
204
|
+
displaySet.isHydrated = false;
|
|
205
|
+
|
|
206
|
+
commandsManager.runCommand('updateStoredSegmentationPresentation', {
|
|
207
|
+
displaySet,
|
|
208
|
+
hydrated: false,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Get current display sets for the viewport
|
|
214
|
+
const currentDisplaySetUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
|
215
|
+
|
|
216
|
+
// If the display set is not in the viewport, no need to remove it
|
|
217
|
+
if (!currentDisplaySetUIDs.includes(displaySetInstanceUID)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const updatedViewports = hangingProtocolService.getViewportsRequireUpdate(
|
|
222
|
+
viewportId,
|
|
223
|
+
displaySetInstanceUID
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
// Configure each viewport for layer removal
|
|
227
|
+
updatedViewports.forEach(viewport => {
|
|
228
|
+
configureViewportForLayerRemoval({
|
|
229
|
+
viewport,
|
|
230
|
+
displaySetInstanceUID,
|
|
231
|
+
currentDisplaySetUIDs,
|
|
232
|
+
servicesManager,
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Update position presentation
|
|
237
|
+
commandsManager.runCommand('updateStoredPositionPresentation', {
|
|
238
|
+
viewportId,
|
|
239
|
+
displaySetInstanceUIDs: updatedViewports[0].displaySetInstanceUIDs,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Update the viewports
|
|
243
|
+
commandsManager.run('setDisplaySetsForViewports', {
|
|
244
|
+
viewportsToUpdate: updatedViewports,
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
/**
|
|
248
|
+
* Runs a command in multi-monitor mode. No-op if not multi-monitor.
|
|
249
|
+
*/
|
|
250
|
+
multimonitor: async options => {
|
|
251
|
+
const { screenDelta, StudyInstanceUID, commands, hashParams } = options;
|
|
252
|
+
if (multiMonitorService.numberOfScreens < 2) {
|
|
253
|
+
return options.fallback?.(options);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const newWindow = await multiMonitorService.launchWindow(
|
|
257
|
+
StudyInstanceUID,
|
|
258
|
+
screenDelta,
|
|
259
|
+
hashParams
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
// Only run commands if we successfully got a window with a commands manager
|
|
263
|
+
if (newWindow && commands) {
|
|
264
|
+
// Todo: fix this properly, but it takes time for the new window to load
|
|
265
|
+
// and then the commandsManager is available for it
|
|
266
|
+
setTimeout(() => {
|
|
267
|
+
multiMonitorService.run(screenDelta, commands, options);
|
|
268
|
+
}, 1000);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
/** Displays a prompt and then save the report if relevant */
|
|
273
|
+
promptSaveReport: props => {
|
|
274
|
+
const { StudyInstanceUID } = props;
|
|
275
|
+
promptSaveReport({ servicesManager, commandsManager, extensionManager }, props, {
|
|
276
|
+
data: { StudyInstanceUID },
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Ensures that the specified study is available for display
|
|
282
|
+
* Then, if commands is specified, runs the given commands list/instance
|
|
283
|
+
*/
|
|
284
|
+
loadStudy: async options => {
|
|
285
|
+
const { StudyInstanceUID } = options;
|
|
286
|
+
const displaySets = displaySetService.getActiveDisplaySets();
|
|
287
|
+
const isActive = displaySets.find(ds => ds.StudyInstanceUID === StudyInstanceUID);
|
|
288
|
+
if (isActive) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const [dataSource] = extensionManager.getActiveDataSource();
|
|
292
|
+
await requestDisplaySetCreationForStudy(dataSource, displaySetService, StudyInstanceUID);
|
|
293
|
+
|
|
294
|
+
const study = DicomMetadataStore.getStudy(StudyInstanceUID);
|
|
295
|
+
hangingProtocolService.addStudy(study);
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Show the context menu.
|
|
300
|
+
* @param options.menuId defines the menu name to lookup, from customizationService
|
|
301
|
+
* @param options.defaultMenu contains the default menu set to use
|
|
302
|
+
* @param options.element is the element to show the menu within
|
|
303
|
+
* @param options.event is the event that caused the context menu
|
|
304
|
+
* @param options.selectorProps is the set of selection properties to use
|
|
305
|
+
*/
|
|
306
|
+
showContextMenu: (options: ContextMenuProps) => {
|
|
307
|
+
const {
|
|
308
|
+
menuCustomizationId,
|
|
309
|
+
element,
|
|
310
|
+
event,
|
|
311
|
+
selectorProps,
|
|
312
|
+
defaultPointsPosition = [],
|
|
313
|
+
} = options;
|
|
314
|
+
|
|
315
|
+
const optionsToUse = { ...options };
|
|
316
|
+
|
|
317
|
+
if (menuCustomizationId) {
|
|
318
|
+
Object.assign(optionsToUse, customizationService.getCustomization(menuCustomizationId));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// TODO - make the selectorProps richer by including the study metadata and display set.
|
|
322
|
+
const { protocol, stage } = hangingProtocolService.getActiveProtocol();
|
|
323
|
+
optionsToUse.selectorProps = {
|
|
324
|
+
event,
|
|
325
|
+
protocol,
|
|
326
|
+
stage,
|
|
327
|
+
...selectorProps,
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
contextMenuController.showContextMenu(optionsToUse, element, defaultPointsPosition);
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
/** Close a context menu currently displayed */
|
|
334
|
+
closeContextMenu: () => {
|
|
335
|
+
contextMenuController.closeContextMenu();
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
displayNotification: ({ text, title, type }) => {
|
|
339
|
+
uiNotificationService.show({
|
|
340
|
+
title: title,
|
|
341
|
+
message: text,
|
|
342
|
+
type: type,
|
|
343
|
+
});
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
clearMeasurements: options => {
|
|
347
|
+
measurementService.clearMeasurements(options.measurementFilter);
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Sets the specified protocol
|
|
352
|
+
* 1. Records any existing state using the viewport grid service
|
|
353
|
+
* 2. Finds the destination state - this can be one of:
|
|
354
|
+
* a. The specified protocol stage
|
|
355
|
+
* b. An alternate (toggled or restored) protocol stage
|
|
356
|
+
* c. A restored custom layout
|
|
357
|
+
* 3. Finds the parameters for the specified state
|
|
358
|
+
* a. Gets the displaySetSelectorMap
|
|
359
|
+
* b. Gets the map by position
|
|
360
|
+
* c. Gets any toggle mapping to map position to/from current view
|
|
361
|
+
* 4. If restore, then sets layout
|
|
362
|
+
* a. Maps viewport position by currently displayed viewport map id
|
|
363
|
+
* b. Uses toggle information to map display set id
|
|
364
|
+
* 5. Else applies the hanging protocol
|
|
365
|
+
* a. HP Service is provided displaySetSelectorMap
|
|
366
|
+
* b. HP Service will throw an exception if it isn't applicable
|
|
367
|
+
* @param options - contains information on the HP to apply
|
|
368
|
+
* @param options.activeStudyUID - the updated study to apply the HP to
|
|
369
|
+
* @param options.protocolId - the protocol ID to change to
|
|
370
|
+
* @param options.stageId - the stageId to apply
|
|
371
|
+
* @param options.stageIndex - the index of the stage to go to.
|
|
372
|
+
* @param options.reset - flag to indicate if the HP should be reset to its original and not restored to a previous state
|
|
373
|
+
*
|
|
374
|
+
* commandsManager.run('setHangingProtocol', {
|
|
375
|
+
* activeStudyUID: '1.2.3',
|
|
376
|
+
* protocolId: 'myProtocol',
|
|
377
|
+
* stageId: 'myStage',
|
|
378
|
+
* stageIndex: 0,
|
|
379
|
+
* reset: false,
|
|
380
|
+
* });
|
|
381
|
+
*/
|
|
382
|
+
setHangingProtocol: ({
|
|
383
|
+
activeStudyUID = '',
|
|
384
|
+
StudyInstanceUID = '',
|
|
385
|
+
protocolId,
|
|
386
|
+
stageId,
|
|
387
|
+
stageIndex,
|
|
388
|
+
reset = false,
|
|
389
|
+
restoreCachedLayout = true,
|
|
390
|
+
}: HangingProtocolParams): boolean => {
|
|
391
|
+
const toUseStudyInstanceUID = activeStudyUID || StudyInstanceUID;
|
|
392
|
+
try {
|
|
393
|
+
// Stores in the state the display set selector id to displaySetUID mapping
|
|
394
|
+
// Pass in viewportId for the active viewport. This item will get set as
|
|
395
|
+
// the activeViewportId
|
|
396
|
+
const state = viewportGridService.getState();
|
|
397
|
+
const hpInfo = hangingProtocolService.getState();
|
|
398
|
+
reuseCachedLayouts(state, hangingProtocolService);
|
|
399
|
+
const { hangingProtocolStageIndexMap } = useHangingProtocolStageIndexStore.getState();
|
|
400
|
+
const { displaySetSelectorMap } = useDisplaySetSelectorStore.getState();
|
|
401
|
+
|
|
402
|
+
if (!protocolId) {
|
|
403
|
+
// Reuse the previous protocol id, and optionally stage
|
|
404
|
+
protocolId = hpInfo.protocolId;
|
|
405
|
+
if (stageId === undefined && stageIndex === undefined) {
|
|
406
|
+
stageIndex = hpInfo.stageIndex;
|
|
407
|
+
}
|
|
408
|
+
} else if (stageIndex === undefined && stageId === undefined) {
|
|
409
|
+
// Re-set the same stage as was previously used
|
|
410
|
+
const hangingId = `${toUseStudyInstanceUID || hpInfo.activeStudyUID}:${protocolId}`;
|
|
411
|
+
stageIndex = hangingProtocolStageIndexMap[hangingId]?.stageIndex;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const useStageIdx =
|
|
415
|
+
stageIndex ??
|
|
416
|
+
hangingProtocolService.getStageIndex(protocolId, {
|
|
417
|
+
stageId,
|
|
418
|
+
stageIndex,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const activeStudyChanged = hangingProtocolService.setActiveStudyUID(toUseStudyInstanceUID);
|
|
422
|
+
|
|
423
|
+
const storedHanging = `${toUseStudyInstanceUID || hangingProtocolService.getState().activeStudyUID}:${protocolId}:${
|
|
424
|
+
useStageIdx || 0
|
|
425
|
+
}`;
|
|
426
|
+
|
|
427
|
+
const { viewportGridState } = useViewportGridStore.getState();
|
|
428
|
+
// An explicit preset selection passes restoreCachedLayout: false so the stage layout wins over a stale cached grid
|
|
429
|
+
const restoreProtocol = !reset && restoreCachedLayout && viewportGridState[storedHanging];
|
|
430
|
+
|
|
431
|
+
if (
|
|
432
|
+
reset ||
|
|
433
|
+
(activeStudyChanged &&
|
|
434
|
+
!viewportGridState[storedHanging] &&
|
|
435
|
+
stageIndex === undefined &&
|
|
436
|
+
stageId === undefined)
|
|
437
|
+
) {
|
|
438
|
+
// Run the hanging protocol fresh, re-using the existing study data
|
|
439
|
+
// This is done on reset or when the study changes and we haven't yet
|
|
440
|
+
// applied it, and don't specify exact stage to use.
|
|
441
|
+
const displaySets = displaySetService.getActiveDisplaySets();
|
|
442
|
+
const activeStudy = {
|
|
443
|
+
StudyInstanceUID: toUseStudyInstanceUID,
|
|
444
|
+
displaySets,
|
|
445
|
+
};
|
|
446
|
+
hangingProtocolService.run(activeStudy, protocolId);
|
|
447
|
+
} else if (
|
|
448
|
+
protocolId === hpInfo.protocolId &&
|
|
449
|
+
useStageIdx === hpInfo.stageIndex &&
|
|
450
|
+
!toUseStudyInstanceUID
|
|
451
|
+
) {
|
|
452
|
+
// Clear the HP setting to reset them
|
|
453
|
+
hangingProtocolService.setProtocol(protocolId, {
|
|
454
|
+
stageId,
|
|
455
|
+
stageIndex: useStageIdx,
|
|
456
|
+
displaySetSelectorMap,
|
|
457
|
+
});
|
|
458
|
+
} else {
|
|
459
|
+
hangingProtocolService.setProtocol(protocolId, {
|
|
460
|
+
displaySetSelectorMap,
|
|
461
|
+
stageId,
|
|
462
|
+
stageIndex: useStageIdx,
|
|
463
|
+
restoreProtocol,
|
|
464
|
+
});
|
|
465
|
+
if (restoreProtocol) {
|
|
466
|
+
viewportGridService.set(viewportGridState[storedHanging]);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// Do this after successfully applying the update
|
|
470
|
+
const { setDisplaySetSelector } = useDisplaySetSelectorStore.getState();
|
|
471
|
+
setDisplaySetSelector(
|
|
472
|
+
`${toUseStudyInstanceUID || hpInfo.activeStudyUID}:activeDisplaySet:0`,
|
|
473
|
+
null
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
// An applied protocol is an explicit layout change, so abandon any pending one-up toggle
|
|
477
|
+
useToggleOneUpViewportGridStore.getState().clearToggleOneUpViewportGridStore();
|
|
478
|
+
return true;
|
|
479
|
+
} catch (e) {
|
|
480
|
+
console.error(e);
|
|
481
|
+
uiNotificationService.show({
|
|
482
|
+
title: 'Apply Hanging Protocol',
|
|
483
|
+
message: 'The hanging protocol could not be applied.',
|
|
484
|
+
type: 'error',
|
|
485
|
+
duration: 3000,
|
|
486
|
+
});
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
toggleHangingProtocol: ({ protocolId, stageIndex }: HangingProtocolParams): boolean => {
|
|
492
|
+
const {
|
|
493
|
+
protocol,
|
|
494
|
+
stageIndex: desiredStageIndex,
|
|
495
|
+
activeStudy,
|
|
496
|
+
} = hangingProtocolService.getActiveProtocol();
|
|
497
|
+
const { toggleHangingProtocol, setToggleHangingProtocol } =
|
|
498
|
+
useToggleHangingProtocolStore.getState();
|
|
499
|
+
const storedHanging = `${activeStudy.StudyInstanceUID}:${protocolId}:${stageIndex | 0}`;
|
|
500
|
+
if (
|
|
501
|
+
protocol.id === protocolId &&
|
|
502
|
+
(stageIndex === undefined || stageIndex === desiredStageIndex)
|
|
503
|
+
) {
|
|
504
|
+
// Toggling off - restore to previous state
|
|
505
|
+
const previousState = toggleHangingProtocol[storedHanging] || {
|
|
506
|
+
protocolId: 'default',
|
|
507
|
+
};
|
|
508
|
+
return actions.setHangingProtocol(previousState);
|
|
509
|
+
} else {
|
|
510
|
+
setToggleHangingProtocol(storedHanging, {
|
|
511
|
+
protocolId: protocol.id,
|
|
512
|
+
stageIndex: desiredStageIndex,
|
|
513
|
+
});
|
|
514
|
+
return actions.setHangingProtocol({
|
|
515
|
+
protocolId,
|
|
516
|
+
stageIndex,
|
|
517
|
+
reset: true,
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
|
|
522
|
+
deltaStage: ({ direction }) => {
|
|
523
|
+
const { protocolId, stageIndex: oldStageIndex } = hangingProtocolService.getState();
|
|
524
|
+
const { protocol } = hangingProtocolService.getActiveProtocol();
|
|
525
|
+
for (
|
|
526
|
+
let stageIndex = oldStageIndex + direction;
|
|
527
|
+
stageIndex >= 0 && stageIndex < protocol.stages.length;
|
|
528
|
+
stageIndex += direction
|
|
529
|
+
) {
|
|
530
|
+
if (protocol.stages[stageIndex].status !== 'disabled') {
|
|
531
|
+
return actions.setHangingProtocol({
|
|
532
|
+
protocolId,
|
|
533
|
+
stageIndex,
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
uiNotificationService.show({
|
|
538
|
+
title: 'Change Stage',
|
|
539
|
+
message: 'The hanging protocol has no more applicable stages',
|
|
540
|
+
type: 'info',
|
|
541
|
+
duration: 3000,
|
|
542
|
+
});
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Changes the viewport grid layout in terms of the MxN layout.
|
|
547
|
+
*/
|
|
548
|
+
setViewportGridLayout: ({ numRows, numCols, isHangingProtocolLayout = false }) => {
|
|
549
|
+
const { protocol } = hangingProtocolService.getActiveProtocol();
|
|
550
|
+
const onLayoutChange = protocol.callbacks?.onLayoutChange;
|
|
551
|
+
if (commandsManager.run(onLayoutChange, { numRows, numCols }) === false) {
|
|
552
|
+
// Don't apply the layout if the run command returns false
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// An explicit grid selection abandons any pending one-up toggle; clear only past the onLayoutChange veto
|
|
557
|
+
useToggleOneUpViewportGridStore.getState().clearToggleOneUpViewportGridStore();
|
|
558
|
+
|
|
559
|
+
const completeLayout = () => {
|
|
560
|
+
const state = viewportGridService.getState();
|
|
561
|
+
findViewportsByPosition(state, { numRows, numCols });
|
|
562
|
+
|
|
563
|
+
const { viewportsByPosition, initialInDisplay } = useViewportsByPositionStore.getState();
|
|
564
|
+
|
|
565
|
+
const findOrCreateViewport = layoutFindOrCreate.bind(
|
|
566
|
+
null,
|
|
567
|
+
hangingProtocolService,
|
|
568
|
+
isHangingProtocolLayout,
|
|
569
|
+
{ ...viewportsByPosition, initialInDisplay }
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
viewportGridService.setLayout({
|
|
573
|
+
numRows,
|
|
574
|
+
numCols,
|
|
575
|
+
findOrCreateViewport,
|
|
576
|
+
isHangingProtocolLayout,
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
// Need to finish any work in the callback
|
|
580
|
+
window.setTimeout(completeLayout, 0);
|
|
581
|
+
},
|
|
582
|
+
|
|
583
|
+
toggleOneUp() {
|
|
584
|
+
const viewportGridState = viewportGridService.getState();
|
|
585
|
+
const { activeViewportId, viewports, layout, isHangingProtocolLayout } = viewportGridState;
|
|
586
|
+
const { displaySetInstanceUIDs, displaySetOptions, viewportOptions } =
|
|
587
|
+
viewports.get(activeViewportId);
|
|
588
|
+
|
|
589
|
+
if (layout.numCols === 1 && layout.numRows === 1) {
|
|
590
|
+
// The viewer is in one-up. Check if there is a state to restore/toggle back to.
|
|
591
|
+
const { toggleOneUpViewportGridStore } = useToggleOneUpViewportGridStore.getState();
|
|
592
|
+
|
|
593
|
+
if (!toggleOneUpViewportGridStore) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
// There is a state to toggle back to. The viewport that was
|
|
597
|
+
// originally toggled to one up was the former active viewport.
|
|
598
|
+
const viewportIdToUpdate = toggleOneUpViewportGridStore.activeViewportId;
|
|
599
|
+
|
|
600
|
+
// We are restoring the previous layout but taking into the account that
|
|
601
|
+
// the current one up viewport might have a new displaySet dragged and dropped on it.
|
|
602
|
+
// updatedViewportsViaHP below contains the viewports applicable to the HP that existed
|
|
603
|
+
// prior to the toggle to one-up - including the updated viewports if a display
|
|
604
|
+
// set swap were to have occurred.
|
|
605
|
+
const updatedViewportsViaHP =
|
|
606
|
+
displaySetInstanceUIDs.length > 1
|
|
607
|
+
? []
|
|
608
|
+
: displaySetInstanceUIDs
|
|
609
|
+
.map(displaySetInstanceUID =>
|
|
610
|
+
hangingProtocolService.getViewportsRequireUpdate(
|
|
611
|
+
viewportIdToUpdate,
|
|
612
|
+
displaySetInstanceUID,
|
|
613
|
+
isHangingProtocolLayout
|
|
614
|
+
)
|
|
615
|
+
)
|
|
616
|
+
.flat();
|
|
617
|
+
|
|
618
|
+
// findOrCreateViewport returns either one of the updatedViewportsViaHP
|
|
619
|
+
// returned from the HP service OR if there is not one from the HP service then
|
|
620
|
+
// simply returns what was in the previous state for a given position in the layout.
|
|
621
|
+
const findOrCreateViewport = (position: number, positionId: string) => {
|
|
622
|
+
// Find the viewport for the given position prior to the toggle to one-up.
|
|
623
|
+
const preOneUpViewport = Array.from(toggleOneUpViewportGridStore.viewports.values()).find(
|
|
624
|
+
viewport => viewport.positionId === positionId
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
// Use the viewport id from before the toggle to one-up to find any updates to the viewport.
|
|
628
|
+
const viewport = updatedViewportsViaHP.find(
|
|
629
|
+
viewport => viewport.viewportId === preOneUpViewport.viewportId
|
|
630
|
+
);
|
|
631
|
+
|
|
632
|
+
return viewport
|
|
633
|
+
? // Use the applicable viewport from the HP updated viewports
|
|
634
|
+
{ viewportOptions, displaySetOptions, ...viewport }
|
|
635
|
+
: // Use the previous viewport for the given position
|
|
636
|
+
preOneUpViewport;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
const layoutOptions = viewportGridService.getLayoutOptionsFromState(
|
|
640
|
+
toggleOneUpViewportGridStore
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
// Restore the previous layout including the active viewport.
|
|
644
|
+
viewportGridService.setLayout({
|
|
645
|
+
numRows: toggleOneUpViewportGridStore.layout.numRows,
|
|
646
|
+
numCols: toggleOneUpViewportGridStore.layout.numCols,
|
|
647
|
+
activeViewportId: viewportIdToUpdate,
|
|
648
|
+
layoutOptions,
|
|
649
|
+
findOrCreateViewport,
|
|
650
|
+
isHangingProtocolLayout: true,
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// Toggled back, so drop the stored layout; the store only holds a currently active one-up
|
|
654
|
+
useToggleOneUpViewportGridStore.getState().clearToggleOneUpViewportGridStore();
|
|
655
|
+
|
|
656
|
+
// Reset crosshairs after restoring the layout
|
|
657
|
+
setTimeout(() => {
|
|
658
|
+
commandsManager.runCommand('resetCrosshairs');
|
|
659
|
+
}, 0);
|
|
660
|
+
} else {
|
|
661
|
+
// We are not in one-up, so toggle to one up.
|
|
662
|
+
|
|
663
|
+
// Store the current viewport grid state so we can toggle it back later.
|
|
664
|
+
const { setToggleOneUpViewportGridStore } = useToggleOneUpViewportGridStore.getState();
|
|
665
|
+
setToggleOneUpViewportGridStore(viewportGridState);
|
|
666
|
+
|
|
667
|
+
// one being toggled to one up.
|
|
668
|
+
const findOrCreateViewport = () => {
|
|
669
|
+
return {
|
|
670
|
+
displaySetInstanceUIDs,
|
|
671
|
+
displaySetOptions,
|
|
672
|
+
viewportOptions,
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// Set the layout to be 1x1/one-up.
|
|
677
|
+
viewportGridService.setLayout({
|
|
678
|
+
numRows: 1,
|
|
679
|
+
numCols: 1,
|
|
680
|
+
findOrCreateViewport,
|
|
681
|
+
isHangingProtocolLayout: true,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Exposes the browser history navigation used by OHIF. This command can be used to either replace or
|
|
688
|
+
* push a new entry into the browser history. For example, the following will replace the current
|
|
689
|
+
* browser history entry with the specified relative URL which changes the study displayed to the
|
|
690
|
+
* study with study instance UID 1.2.3. Note that as a result of using `options.replace = true`, the
|
|
691
|
+
* page prior to invoking this command cannot be returned to via the browser back button.
|
|
692
|
+
*
|
|
693
|
+
* navigateHistory({
|
|
694
|
+
* to: 'viewer?StudyInstanceUIDs=1.2.3',
|
|
695
|
+
* options: { replace: true },
|
|
696
|
+
* });
|
|
697
|
+
*
|
|
698
|
+
* @param historyArgs - arguments for the history function;
|
|
699
|
+
* the `to` property is the URL;
|
|
700
|
+
* the `options.replace` is a boolean indicating if the current browser history entry
|
|
701
|
+
* should be replaced or a new entry pushed onto the history (stack); the default value
|
|
702
|
+
* for `replace` is false
|
|
703
|
+
*/
|
|
704
|
+
navigateHistory(historyArgs: NavigateHistory) {
|
|
705
|
+
history.navigate(historyArgs.to, historyArgs.options);
|
|
706
|
+
},
|
|
707
|
+
|
|
708
|
+
openDICOMTagViewer({ displaySetInstanceUID }: { displaySetInstanceUID?: string }) {
|
|
709
|
+
const { activeViewportId, viewports } = viewportGridService.getState();
|
|
710
|
+
const activeViewportSpecificData = viewports.get(activeViewportId);
|
|
711
|
+
const { displaySetInstanceUIDs } = activeViewportSpecificData;
|
|
712
|
+
|
|
713
|
+
const displaySets = displaySetService.activeDisplaySets;
|
|
714
|
+
const { UIModalService } = servicesManager.services;
|
|
715
|
+
|
|
716
|
+
const defaultDisplaySetInstanceUID =
|
|
717
|
+
displaySetInstanceUID || displaySetInstanceUIDs[0] || displaySets[0]?.displaySetInstanceUID;
|
|
718
|
+
|
|
719
|
+
UIModalService.show({
|
|
720
|
+
content: DicomTagBrowser,
|
|
721
|
+
contentProps: {
|
|
722
|
+
displaySets,
|
|
723
|
+
displaySetInstanceUID: defaultDisplaySetInstanceUID,
|
|
724
|
+
},
|
|
725
|
+
title: 'DICOM Tag Browser',
|
|
726
|
+
containerClassName: 'max-w-3xl',
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Toggle viewport overlay (the information panel shown on the four corners
|
|
732
|
+
* of the viewport)
|
|
733
|
+
* @see ViewportOverlay and CustomizableViewportOverlay components
|
|
734
|
+
*/
|
|
735
|
+
toggleOverlays: () => {
|
|
736
|
+
const overlays = document.getElementsByClassName('viewport-overlay');
|
|
737
|
+
for (let i = 0; i < overlays.length; i++) {
|
|
738
|
+
overlays.item(i).classList.toggle('hidden');
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
|
|
742
|
+
scrollActiveThumbnailIntoView: () => {
|
|
743
|
+
const { activeViewportId, viewports } = viewportGridService.getState();
|
|
744
|
+
|
|
745
|
+
const activeViewport = viewports.get(activeViewportId);
|
|
746
|
+
const activeDisplaySetInstanceUID = activeViewport?.displaySetInstanceUIDs?.[0];
|
|
747
|
+
|
|
748
|
+
if (!activeDisplaySetInstanceUID) {
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const thumbnailList = document.querySelector('#ohif-thumbnail-list');
|
|
753
|
+
|
|
754
|
+
if (!thumbnailList) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const thumbnail = document.querySelector(`#thumbnail-${activeDisplaySetInstanceUID}`);
|
|
759
|
+
|
|
760
|
+
if (!thumbnail) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
thumbnail.scrollIntoView({ behavior: 'smooth' });
|
|
765
|
+
},
|
|
766
|
+
|
|
767
|
+
updateViewportDisplaySet: ({
|
|
768
|
+
direction,
|
|
769
|
+
excludeNonImageModalities,
|
|
770
|
+
}: UpdateViewportDisplaySetParams) => {
|
|
771
|
+
const nonImageModalities = ['SR', 'SEG', 'SM', 'RTSTRUCT', 'RTPLAN', 'RTDOSE'];
|
|
772
|
+
|
|
773
|
+
const currentDisplaySets = [...displaySetService.activeDisplaySets];
|
|
774
|
+
|
|
775
|
+
const { activeViewportId, viewports, isHangingProtocolLayout } =
|
|
776
|
+
viewportGridService.getState();
|
|
777
|
+
|
|
778
|
+
const { displaySetInstanceUIDs } = viewports.get(activeViewportId);
|
|
779
|
+
|
|
780
|
+
const activeDisplaySetIndex = currentDisplaySets.findIndex(displaySet =>
|
|
781
|
+
displaySetInstanceUIDs.includes(displaySet.displaySetInstanceUID)
|
|
782
|
+
);
|
|
783
|
+
|
|
784
|
+
let displaySetIndexToShow: number;
|
|
785
|
+
|
|
786
|
+
for (
|
|
787
|
+
displaySetIndexToShow = activeDisplaySetIndex + direction;
|
|
788
|
+
displaySetIndexToShow > -1 && displaySetIndexToShow < currentDisplaySets.length;
|
|
789
|
+
displaySetIndexToShow += direction
|
|
790
|
+
) {
|
|
791
|
+
const nextDisplaySet = currentDisplaySets[displaySetIndexToShow];
|
|
792
|
+
if (nextDisplaySet.madeInClient) {
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
if (!excludeNonImageModalities || !nonImageModalities.includes(nextDisplaySet.Modality)) {
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
if (displaySetIndexToShow < 0 || displaySetIndexToShow >= currentDisplaySets.length) {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
const { displaySetInstanceUID } = currentDisplaySets[displaySetIndexToShow];
|
|
805
|
+
|
|
806
|
+
let updatedViewports = [];
|
|
807
|
+
|
|
808
|
+
try {
|
|
809
|
+
updatedViewports = hangingProtocolService.getViewportsRequireUpdate(
|
|
810
|
+
activeViewportId,
|
|
811
|
+
displaySetInstanceUID,
|
|
812
|
+
isHangingProtocolLayout
|
|
813
|
+
);
|
|
814
|
+
} catch (error) {
|
|
815
|
+
console.warn(error);
|
|
816
|
+
uiNotificationService.show({
|
|
817
|
+
title: 'Navigate Viewport Display Set',
|
|
818
|
+
message:
|
|
819
|
+
'The requested display sets could not be added to the viewport due to a mismatch in the Hanging Protocol rules.',
|
|
820
|
+
type: 'info',
|
|
821
|
+
duration: 3000,
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
commandsManager.run('setDisplaySetsForViewports', { viewportsToUpdate: updatedViewports });
|
|
826
|
+
|
|
827
|
+
setTimeout(() => actions.scrollActiveThumbnailIntoView(), 0);
|
|
828
|
+
},
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Creates a store function based on the data source type.
|
|
832
|
+
* @param dataSource - 'download', 'copyToClipboard', or a named data source
|
|
833
|
+
* @param defaultFileName - Default filename for download/clipboard
|
|
834
|
+
* @param defaultContentType - Default content type for clipboard
|
|
835
|
+
* @returns A store function, or null if no valid store exists
|
|
836
|
+
*/
|
|
837
|
+
createStoreFunction: ({ dataSource, defaultFileName, defaultContentType }) => {
|
|
838
|
+
if (dataSource === 'download') {
|
|
839
|
+
return async dicom => {
|
|
840
|
+
const instances = Array.isArray(dicom) ? dicom : [dicom];
|
|
841
|
+
registerNaturalizedDatasetsForLocalWadouri(instances);
|
|
842
|
+
DicomMetadataStore.addInstances(instances, true);
|
|
843
|
+
if (instances.length !== 1) {
|
|
844
|
+
throw new Error('Download only supports a single DICOM instance');
|
|
845
|
+
}
|
|
846
|
+
const reportBlob = datasetToDicomBlob(instances[0]);
|
|
847
|
+
downloadBlob(reportBlob, { filename: defaultFileName || 'dicom.dcm' });
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
if (dataSource === 'copyToClipboard') {
|
|
852
|
+
return async dicom => {
|
|
853
|
+
const instances = Array.isArray(dicom) ? dicom : [dicom];
|
|
854
|
+
registerNaturalizedDatasetsForLocalWadouri(instances);
|
|
855
|
+
DicomMetadataStore.addInstances(instances, true);
|
|
856
|
+
if (instances.length !== 1) {
|
|
857
|
+
throw new Error('Copy to clipboard only supports a single DICOM instance');
|
|
858
|
+
}
|
|
859
|
+
const reportBlob = datasetToDicomBlob(instances[0]);
|
|
860
|
+
const type = defaultContentType || 'application/dicom';
|
|
861
|
+
await navigator.clipboard.write([new ClipboardItem({ [type]: reportBlob })]);
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// DICOM STOW path — resolve the named data source
|
|
866
|
+
const dataSources = extensionManager.getDataSources(dataSource);
|
|
867
|
+
const resolvedDataSource = dataSources?.[0];
|
|
868
|
+
if (!resolvedDataSource?.store?.dicom) {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
return async (dicom, { dicomDict } = {}) => {
|
|
873
|
+
const instances = Array.isArray(dicom) ? dicom : [dicom];
|
|
874
|
+
// Always keep an in-memory wadouri copy so DICOM can be read without re-fetching.
|
|
875
|
+
registerNaturalizedDatasetsForLocalWadouri(instances);
|
|
876
|
+
|
|
877
|
+
if (dataSource !== 'dicomlocal') {
|
|
878
|
+
const config = resolvedDataSource.getConfig?.();
|
|
879
|
+
if (config?.wadoRoot) {
|
|
880
|
+
instances.forEach(instance => {
|
|
881
|
+
setNonEnumerableInstanceProperty(instance, 'wadoRoot', config.wadoRoot);
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// Identify the stored instances before they reach the metadata store, so
|
|
887
|
+
// that the display sets made from them know which instance they came
|
|
888
|
+
// from, and a later save of the same data can extend this series.
|
|
889
|
+
registerStoredInstanceImageIds(instances, resolvedDataSource);
|
|
890
|
+
|
|
891
|
+
DicomMetadataStore.addInstances(instances, true);
|
|
892
|
+
for (const instance of instances) {
|
|
893
|
+
await resolvedDataSource.store.dicom(instance, null, dicomDict);
|
|
894
|
+
}
|
|
895
|
+
const studyUIDs = new Set(instances.map(i => i.StudyInstanceUID).filter(Boolean));
|
|
896
|
+
for (const uid of studyUIDs) {
|
|
897
|
+
resolvedDataSource.deleteStudyMetadataPromise(uid);
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
},
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Launches a workflow (mode) for a study from the worklist. This is the
|
|
904
|
+
* default `workList.onStudyDoubleClick` command.
|
|
905
|
+
*
|
|
906
|
+
* @param study - the StudyRow the action applies to
|
|
907
|
+
* @param workflows - the workflows applicable to the study, in menu order;
|
|
908
|
+
* each has `id`, `displayName`, `isDefault` and `launchWithStudy(study)`
|
|
909
|
+
* @param defaultWorkflow - the user's default workflow when it applies to
|
|
910
|
+
* the study
|
|
911
|
+
* @param workflowId - command option to force a specific workflow (mode id)
|
|
912
|
+
* instead of the default/first applicable one
|
|
913
|
+
*/
|
|
914
|
+
launchDefaultMode: ({ study, workflows = [], defaultWorkflow, workflowId }) => {
|
|
915
|
+
const workflow = workflowId
|
|
916
|
+
? workflows.find(w => w.id === workflowId)
|
|
917
|
+
: (defaultWorkflow ?? workflows[0]);
|
|
918
|
+
if (!workflow) {
|
|
919
|
+
console.warn(
|
|
920
|
+
workflowId
|
|
921
|
+
? `launchDefaultMode: workflow '${workflowId}' is not applicable to the study`
|
|
922
|
+
: 'launchDefaultMode: no workflow is applicable to the study'
|
|
923
|
+
);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
workflow.launchWithStudy(study);
|
|
927
|
+
},
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
const definitions = {
|
|
931
|
+
multimonitor: actions.multimonitor,
|
|
932
|
+
promptSaveReport: actions.promptSaveReport,
|
|
933
|
+
loadStudy: actions.loadStudy,
|
|
934
|
+
showContextMenu: actions.showContextMenu,
|
|
935
|
+
closeContextMenu: actions.closeContextMenu,
|
|
936
|
+
clearMeasurements: actions.clearMeasurements,
|
|
937
|
+
displayNotification: actions.displayNotification,
|
|
938
|
+
setHangingProtocol: actions.setHangingProtocol,
|
|
939
|
+
toggleHangingProtocol: actions.toggleHangingProtocol,
|
|
940
|
+
navigateHistory: actions.navigateHistory,
|
|
941
|
+
nextStage: {
|
|
942
|
+
commandFn: actions.deltaStage,
|
|
943
|
+
options: { direction: 1 },
|
|
944
|
+
},
|
|
945
|
+
previousStage: {
|
|
946
|
+
commandFn: actions.deltaStage,
|
|
947
|
+
options: { direction: -1 },
|
|
948
|
+
},
|
|
949
|
+
setViewportGridLayout: actions.setViewportGridLayout,
|
|
950
|
+
toggleOneUp: actions.toggleOneUp,
|
|
951
|
+
openDICOMTagViewer: actions.openDICOMTagViewer,
|
|
952
|
+
updateViewportDisplaySet: actions.updateViewportDisplaySet,
|
|
953
|
+
scrollActiveThumbnailIntoView: actions.scrollActiveThumbnailIntoView,
|
|
954
|
+
addDisplaySetAsLayer: actions.addDisplaySetAsLayer,
|
|
955
|
+
removeDisplaySetLayer: actions.removeDisplaySetLayer,
|
|
956
|
+
createStoreFunction: actions.createStoreFunction,
|
|
957
|
+
launchDefaultMode: {
|
|
958
|
+
commandFn: actions.launchDefaultMode,
|
|
959
|
+
context: 'WORKLIST',
|
|
960
|
+
},
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
return {
|
|
964
|
+
actions,
|
|
965
|
+
definitions,
|
|
966
|
+
defaultContext: 'DEFAULT',
|
|
967
|
+
};
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
export default commandsModule;
|