@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,117 @@
|
|
|
1
|
+
import { utils } from '@ohif/core';
|
|
2
|
+
|
|
3
|
+
import createReportAsync from '../Actions/createReportAsync';
|
|
4
|
+
import { createReportDialogPrompt } from '../Panels';
|
|
5
|
+
import PROMPT_RESPONSES from './_shared/PROMPT_RESPONSES';
|
|
6
|
+
|
|
7
|
+
const { filterAnd, filterMeasurementsByStudyUID, filterMeasurementsBySeriesUID } =
|
|
8
|
+
utils.MeasurementFilters;
|
|
9
|
+
|
|
10
|
+
async function promptSaveReport({ servicesManager, commandsManager, extensionManager }, ctx, evt) {
|
|
11
|
+
const { measurementService, displaySetService } = servicesManager.services;
|
|
12
|
+
const viewportId = evt.viewportId === undefined ? evt.data.viewportId : evt.viewportId;
|
|
13
|
+
const isBackupSave = evt.isBackupSave === undefined ? evt.data.isBackupSave : evt.isBackupSave;
|
|
14
|
+
const StudyInstanceUID = evt?.data?.StudyInstanceUID || ctx.trackedStudy;
|
|
15
|
+
const SeriesInstanceUID = evt?.data?.SeriesInstanceUID;
|
|
16
|
+
const { displaySetInstanceUID } = evt.data ?? evt;
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
trackedSeries,
|
|
20
|
+
measurementFilter = filterAnd(
|
|
21
|
+
filterMeasurementsByStudyUID(StudyInstanceUID),
|
|
22
|
+
filterMeasurementsBySeriesUID(trackedSeries)
|
|
23
|
+
),
|
|
24
|
+
defaultSaveTitle = 'Save Measurements',
|
|
25
|
+
defaultSeriesDescription = 'Measurements',
|
|
26
|
+
} = ctx;
|
|
27
|
+
let displaySetInstanceUIDs;
|
|
28
|
+
|
|
29
|
+
const measurementData = measurementService.getMeasurements(measurementFilter);
|
|
30
|
+
const predecessorImageId = findPredecessorImageId(measurementData);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const promptResult = await createReportDialogPrompt({
|
|
34
|
+
title: defaultSaveTitle,
|
|
35
|
+
predecessorImageId,
|
|
36
|
+
defaultSeriesDescription,
|
|
37
|
+
minSeriesNumber: 3000,
|
|
38
|
+
extensionManager,
|
|
39
|
+
servicesManager,
|
|
40
|
+
enableDownload: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (promptResult.action === PROMPT_RESPONSES.CREATE_REPORT) {
|
|
44
|
+
const { series, seriesNumber, value: reportName, dataSourceName } = promptResult;
|
|
45
|
+
const SeriesDescription = reportName || defaultSeriesDescription;
|
|
46
|
+
|
|
47
|
+
const getReport = async () =>
|
|
48
|
+
commandsManager.runCommand(
|
|
49
|
+
'storeMeasurements',
|
|
50
|
+
{
|
|
51
|
+
measurementData,
|
|
52
|
+
dataSource: dataSourceName,
|
|
53
|
+
additionalFindingTypes: ['ArrowAnnotate'],
|
|
54
|
+
options: {
|
|
55
|
+
SeriesDescription,
|
|
56
|
+
SeriesNumber: seriesNumber,
|
|
57
|
+
predecessorImageId: series,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
'CORNERSTONE_STRUCTURED_REPORT'
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
displaySetInstanceUIDs = await createReportAsync({
|
|
64
|
+
servicesManager,
|
|
65
|
+
getReport,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// The report just written is what these measurements are now stored as, so
|
|
69
|
+
// saving them again offers to extend that series rather than making
|
|
70
|
+
// another one. Measurements are not reloaded from the report they were
|
|
71
|
+
// stored into, so this is recorded on them directly.
|
|
72
|
+
const storedDisplaySet = displaySetInstanceUIDs?.length
|
|
73
|
+
? displaySetService.getDisplaySetByUID(displaySetInstanceUIDs[0])
|
|
74
|
+
: undefined;
|
|
75
|
+
|
|
76
|
+
if (storedDisplaySet?.predecessorImageId) {
|
|
77
|
+
commandsManager.runCommand('recordMeasurementsPredecessor', {
|
|
78
|
+
measurements: measurementData,
|
|
79
|
+
predecessorImageId: storedDisplaySet.predecessorImageId,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
} else if (promptResult.action === PROMPT_RESPONSES.CANCEL) {
|
|
83
|
+
// Do nothing
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
userResponse: promptResult.action,
|
|
88
|
+
createdDisplaySetInstanceUIDs: displaySetInstanceUIDs,
|
|
89
|
+
StudyInstanceUID,
|
|
90
|
+
SeriesInstanceUID,
|
|
91
|
+
viewportId,
|
|
92
|
+
isBackupSave,
|
|
93
|
+
displaySetInstanceUID,
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.warn('Unable to save report', error);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function findPredecessorImageId(annotations) {
|
|
102
|
+
let predecessorImageId;
|
|
103
|
+
for (const annotation of annotations) {
|
|
104
|
+
if (
|
|
105
|
+
predecessorImageId &&
|
|
106
|
+
annotation.predecessorImageId &&
|
|
107
|
+
annotation.predecessorImageId !== predecessorImageId
|
|
108
|
+
) {
|
|
109
|
+
console.warn('Found multiple source predecessors, not defaulting to same series');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
predecessorImageId ||= annotation.predecessorImageId;
|
|
113
|
+
}
|
|
114
|
+
return predecessorImageId;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default promptSaveReport;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import dicomImageLoader from '@cornerstonejs/dicom-image-loader';
|
|
2
|
+
import OHIF from '@ohif/core';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
datasetToDicomBlob,
|
|
6
|
+
makeExistingPropertiesNonEnumerable,
|
|
7
|
+
setNonEnumerableInstanceProperty,
|
|
8
|
+
} from './dicomWriter';
|
|
9
|
+
import { appendFrameQueryToImageId } from './appendFrameQueryToImageId';
|
|
10
|
+
|
|
11
|
+
const metadataProvider = OHIF.classes.MetadataProvider;
|
|
12
|
+
|
|
13
|
+
const SEG_REGISTER_LOG_PREFIX = '[SEG register]';
|
|
14
|
+
|
|
15
|
+
// Every registration pins a full Part 10 Blob in the fileManager (and, once
|
|
16
|
+
// loaded, a parsed copy in the dataSetCacheManager) with no other owner, so
|
|
17
|
+
// track the imageIds and release them on mode exit.
|
|
18
|
+
const registeredImageIds = new Set();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Releases everything previously registered via
|
|
22
|
+
* {@link registerNaturalizedDatasetForLocalWadouri}: the Part 10 Blob held by the
|
|
23
|
+
* wadouri fileManager and any parsed dataset the dataSetCacheManager retained.
|
|
24
|
+
* Call on mode exit.
|
|
25
|
+
*/
|
|
26
|
+
export function releaseLocalWadouriRegistrations() {
|
|
27
|
+
const { fileManager, dataSetCacheManager } = dicomImageLoader.wadouri;
|
|
28
|
+
|
|
29
|
+
for (const imageId of registeredImageIds) {
|
|
30
|
+
// 'dicomfile:<index>' — the index doubles as the fileManager slot and the
|
|
31
|
+
// dataSetCacheManager uri (the scheme is stripped for cache keys).
|
|
32
|
+
const uri = imageId.substring(imageId.indexOf(':') + 1);
|
|
33
|
+
const fileIndex = Number(uri);
|
|
34
|
+
|
|
35
|
+
if (Number.isInteger(fileIndex) && fileIndex >= 0) {
|
|
36
|
+
fileManager.remove(fileIndex);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// unload() decrements a refcount shared with cornerstone's image decache;
|
|
40
|
+
// nothing may outlive mode exit, so drive it to zero.
|
|
41
|
+
for (let guard = 0; guard < 100000 && dataSetCacheManager.isLoaded(uri); guard++) {
|
|
42
|
+
dataSetCacheManager.unload(uri);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
registeredImageIds.clear();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Registers a naturalized DICOM dataset with the wadouri file manager so it can be
|
|
51
|
+
* loaded like other locally stored instances (blob URL), instead of remote wadors URLs.
|
|
52
|
+
*
|
|
53
|
+
* Datasets without pixel data (SR, RTSTRUCT, ...) are skipped: they have no frames
|
|
54
|
+
* to serve through the image loader, so registering them would only pin their
|
|
55
|
+
* Part 10 Blob in memory for the rest of the session.
|
|
56
|
+
*
|
|
57
|
+
* @param {object} dataset - Naturalized DICOM instance (e.g. generated SEG).
|
|
58
|
+
* @param {object} [options]
|
|
59
|
+
* @param {string[]} [options.referencedImageIds] - Used for logging / frame count hints.
|
|
60
|
+
* @returns {string|undefined} wadouri imageId assigned to dataset.url, or undefined when skipped
|
|
61
|
+
*/
|
|
62
|
+
export function registerNaturalizedDatasetForLocalWadouri(dataset, options = {}) {
|
|
63
|
+
const { referencedImageIds = [] } = options;
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
dataset.PixelData === undefined &&
|
|
67
|
+
!Array.isArray(dataset.PerFrameFunctionalGroupsSequence)
|
|
68
|
+
) {
|
|
69
|
+
OHIF.log.debug(
|
|
70
|
+
SEG_REGISTER_LOG_PREFIX,
|
|
71
|
+
'Skipping local wadouri registration (no pixel data)',
|
|
72
|
+
{ SOPClassUID: dataset.SOPClassUID, SOPInstanceUID: dataset.SOPInstanceUID }
|
|
73
|
+
);
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const blob = datasetToDicomBlob(dataset);
|
|
78
|
+
const imageId = dicomImageLoader.wadouri.fileManager.add(blob);
|
|
79
|
+
registeredImageIds.add(imageId);
|
|
80
|
+
|
|
81
|
+
setNonEnumerableInstanceProperty(dataset, 'url', imageId);
|
|
82
|
+
|
|
83
|
+
const { StudyInstanceUID, SeriesInstanceUID } = dataset;
|
|
84
|
+
const SOPInstanceUID = dataset.SOPInstanceUID || dataset.SopInstanceUID;
|
|
85
|
+
|
|
86
|
+
const perFrameGroups = dataset.PerFrameFunctionalGroupsSequence;
|
|
87
|
+
if (Array.isArray(perFrameGroups) && !dataset.NumberOfFrames) {
|
|
88
|
+
dataset.NumberOfFrames = perFrameGroups.length;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Local only — never written back to the dataset: single-frame IODs (SR,
|
|
92
|
+
// RTSTRUCT) must not gain a NumberOfFrames element in their serialized form.
|
|
93
|
+
const numberOfFrames = Math.max(
|
|
94
|
+
Number(dataset.NumberOfFrames) || 0,
|
|
95
|
+
Array.isArray(perFrameGroups) ? perFrameGroups.length : 0,
|
|
96
|
+
1
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const frameImageIds = [];
|
|
100
|
+
if (StudyInstanceUID && SeriesInstanceUID && SOPInstanceUID) {
|
|
101
|
+
const registerMapping = (id, frameNumber = 1) => {
|
|
102
|
+
metadataProvider.addImageIdToUIDs(id, {
|
|
103
|
+
StudyInstanceUID,
|
|
104
|
+
SeriesInstanceUID,
|
|
105
|
+
SOPInstanceUID,
|
|
106
|
+
frameNumber,
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
for (let frame = 1; frame <= numberOfFrames; frame++) {
|
|
111
|
+
const frameImageId =
|
|
112
|
+
numberOfFrames > 1 ? appendFrameQueryToImageId(imageId, frame) : imageId;
|
|
113
|
+
|
|
114
|
+
frameImageIds.push(frameImageId);
|
|
115
|
+
registerMapping(frameImageId, frame);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
makeExistingPropertiesNonEnumerable(dataset);
|
|
120
|
+
|
|
121
|
+
OHIF.log.debug(SEG_REGISTER_LOG_PREFIX, 'Registered local wadouri instance', {
|
|
122
|
+
StudyInstanceUID,
|
|
123
|
+
SeriesInstanceUID,
|
|
124
|
+
SOPInstanceUID,
|
|
125
|
+
numberOfFrames,
|
|
126
|
+
baseImageId: imageId,
|
|
127
|
+
frameImageIds,
|
|
128
|
+
blobSizeBytes: blob.size,
|
|
129
|
+
referencedImageIdCount: referencedImageIds.length,
|
|
130
|
+
SegmentationType: dataset.SegmentationType,
|
|
131
|
+
SOPClassUID: dataset.SOPClassUID,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return imageId;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function registerNaturalizedDatasetsForLocalWadouri(instances, options = {}) {
|
|
138
|
+
const list = Array.isArray(instances) ? instances : [instances];
|
|
139
|
+
const { referencedImageIds = [] } = options;
|
|
140
|
+
|
|
141
|
+
list.forEach(instance =>
|
|
142
|
+
registerNaturalizedDatasetForLocalWadouri(instance, { referencedImageIds })
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return list;
|
|
146
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { TextEncoder, TextDecoder } from 'util';
|
|
2
|
+
import dicomImageLoader from '@cornerstonejs/dicom-image-loader';
|
|
3
|
+
import OHIF from '@ohif/core';
|
|
4
|
+
import {
|
|
5
|
+
registerNaturalizedDatasetForLocalWadouri,
|
|
6
|
+
releaseLocalWadouriRegistrations,
|
|
7
|
+
} from './registerNaturalizedDatasetForLocalWadouri';
|
|
8
|
+
|
|
9
|
+
// jsdom does not expose TextEncoder/TextDecoder, which dcmjs's buffer streams need.
|
|
10
|
+
if (typeof global.TextEncoder === 'undefined') {
|
|
11
|
+
global.TextEncoder = TextEncoder;
|
|
12
|
+
}
|
|
13
|
+
if (typeof global.TextDecoder === 'undefined') {
|
|
14
|
+
global.TextDecoder = TextDecoder;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
jest.mock('@cornerstonejs/dicom-image-loader', () => ({
|
|
18
|
+
__esModule: true,
|
|
19
|
+
default: {
|
|
20
|
+
wadouri: {
|
|
21
|
+
fileManager: {
|
|
22
|
+
add: jest.fn(() => 'dicomfile:0'),
|
|
23
|
+
remove: jest.fn(),
|
|
24
|
+
},
|
|
25
|
+
dataSetCacheManager: {
|
|
26
|
+
isLoaded: jest.fn(() => false),
|
|
27
|
+
unload: jest.fn(),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock('@ohif/core', () => ({
|
|
34
|
+
__esModule: true,
|
|
35
|
+
default: {
|
|
36
|
+
classes: {
|
|
37
|
+
MetadataProvider: {
|
|
38
|
+
addImageIdToUIDs: jest.fn(),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
log: {
|
|
42
|
+
debug: jest.fn(),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const EXPLICIT_VR_LITTLE_ENDIAN = '1.2.840.10008.1.2.1';
|
|
48
|
+
|
|
49
|
+
const addBlob = dicomImageLoader.wadouri.fileManager.add;
|
|
50
|
+
const addImageIdToUIDs = OHIF.classes.MetadataProvider.addImageIdToUIDs;
|
|
51
|
+
|
|
52
|
+
function makeDataset(extra = {}) {
|
|
53
|
+
return {
|
|
54
|
+
_meta: { TransferSyntaxUID: { vr: 'UI', Value: [EXPLICIT_VR_LITTLE_ENDIAN] } },
|
|
55
|
+
SOPInstanceUID: '1.2.3.4.5',
|
|
56
|
+
StudyInstanceUID: '1.2.3.4',
|
|
57
|
+
SeriesInstanceUID: '1.2.3.4.1',
|
|
58
|
+
PatientID: 'TEST-PATIENT',
|
|
59
|
+
...extra,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('registerNaturalizedDatasetForLocalWadouri', () => {
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
jest.clearAllMocks();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
// Drain the module-level registration tracking between tests.
|
|
70
|
+
releaseLocalWadouriRegistrations();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('skips datasets without pixel data (SR/RTSTRUCT) and does not mutate them', () => {
|
|
74
|
+
const dataset = makeDataset({
|
|
75
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.88.33',
|
|
76
|
+
Modality: 'SR',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const imageId = registerNaturalizedDatasetForLocalWadouri(dataset);
|
|
80
|
+
|
|
81
|
+
// No frames to serve through the image loader: nothing registered, no Blob pinned.
|
|
82
|
+
expect(imageId).toBeUndefined();
|
|
83
|
+
expect(addBlob).not.toHaveBeenCalled();
|
|
84
|
+
expect(addImageIdToUIDs).not.toHaveBeenCalled();
|
|
85
|
+
|
|
86
|
+
// The serialized form of an SR must not gain a (0028,0008) element or a url.
|
|
87
|
+
expect(Object.prototype.hasOwnProperty.call(dataset, 'NumberOfFrames')).toBe(false);
|
|
88
|
+
expect(Object.prototype.hasOwnProperty.call(dataset, 'url')).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('registers a single-frame pixel-bearing dataset without stamping NumberOfFrames', () => {
|
|
92
|
+
const dataset = makeDataset({
|
|
93
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.7',
|
|
94
|
+
Modality: 'OT',
|
|
95
|
+
PixelData: new Uint8Array(4).buffer,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const imageId = registerNaturalizedDatasetForLocalWadouri(dataset);
|
|
99
|
+
|
|
100
|
+
expect(Object.prototype.hasOwnProperty.call(dataset, 'NumberOfFrames')).toBe(false);
|
|
101
|
+
|
|
102
|
+
expect(imageId).toBe('dicomfile:0');
|
|
103
|
+
expect(addBlob).toHaveBeenCalledTimes(1);
|
|
104
|
+
// Single frame: the bare imageId is mapped, no ?frame= query.
|
|
105
|
+
expect(addImageIdToUIDs).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(addImageIdToUIDs).toHaveBeenCalledWith('dicomfile:0', {
|
|
107
|
+
StudyInstanceUID: '1.2.3.4',
|
|
108
|
+
SeriesInstanceUID: '1.2.3.4.1',
|
|
109
|
+
SOPInstanceUID: '1.2.3.4.5',
|
|
110
|
+
frameNumber: 1,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('still registers per-frame imageIds (and NumberOfFrames) for a multiframe SEG', () => {
|
|
115
|
+
const dataset = makeDataset({
|
|
116
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
117
|
+
Modality: 'SEG',
|
|
118
|
+
PerFrameFunctionalGroupsSequence: [{}, {}, {}],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
registerNaturalizedDatasetForLocalWadouri(dataset);
|
|
122
|
+
|
|
123
|
+
// Legitimately multiframe: the count is derived from the per-frame groups
|
|
124
|
+
// and must be serialized (enumerable).
|
|
125
|
+
expect(dataset.NumberOfFrames).toBe(3);
|
|
126
|
+
expect(Object.getOwnPropertyDescriptor(dataset, 'NumberOfFrames').enumerable).toBe(true);
|
|
127
|
+
|
|
128
|
+
expect(addImageIdToUIDs).toHaveBeenCalledTimes(3);
|
|
129
|
+
for (let frame = 1; frame <= 3; frame++) {
|
|
130
|
+
expect(addImageIdToUIDs).toHaveBeenNthCalledWith(frame, `dicomfile:0?frame=${frame}`, {
|
|
131
|
+
StudyInstanceUID: '1.2.3.4',
|
|
132
|
+
SeriesInstanceUID: '1.2.3.4.1',
|
|
133
|
+
SOPInstanceUID: '1.2.3.4.5',
|
|
134
|
+
frameNumber: frame,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('keeps the wadouri imageId on the dataset without making it serializable', () => {
|
|
140
|
+
const dataset = makeDataset({
|
|
141
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
142
|
+
Modality: 'SEG',
|
|
143
|
+
PixelData: new Uint8Array(4).buffer,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
registerNaturalizedDatasetForLocalWadouri(dataset);
|
|
147
|
+
|
|
148
|
+
expect(dataset.url).toBe('dicomfile:0');
|
|
149
|
+
expect(Object.getOwnPropertyDescriptor(dataset, 'url').enumerable).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('releases the retained Blob and cached dataset on releaseLocalWadouriRegistrations', () => {
|
|
153
|
+
const dataset = makeDataset({
|
|
154
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
155
|
+
Modality: 'SEG',
|
|
156
|
+
PixelData: new Uint8Array(4).buffer,
|
|
157
|
+
});
|
|
158
|
+
dicomImageLoader.wadouri.fileManager.add.mockReturnValueOnce('dicomfile:7');
|
|
159
|
+
// Simulate a parsed dataset held with a refcount of 2 (e.g. two frame loads).
|
|
160
|
+
dicomImageLoader.wadouri.dataSetCacheManager.isLoaded
|
|
161
|
+
.mockReturnValueOnce(true)
|
|
162
|
+
.mockReturnValueOnce(true)
|
|
163
|
+
.mockReturnValue(false);
|
|
164
|
+
|
|
165
|
+
registerNaturalizedDatasetForLocalWadouri(dataset);
|
|
166
|
+
releaseLocalWadouriRegistrations();
|
|
167
|
+
|
|
168
|
+
expect(dicomImageLoader.wadouri.fileManager.remove).toHaveBeenCalledWith(7);
|
|
169
|
+
expect(dicomImageLoader.wadouri.dataSetCacheManager.unload).toHaveBeenCalledTimes(2);
|
|
170
|
+
expect(dicomImageLoader.wadouri.dataSetCacheManager.unload).toHaveBeenCalledWith('7');
|
|
171
|
+
|
|
172
|
+
// Idempotent: the tracking set was drained.
|
|
173
|
+
dicomImageLoader.wadouri.fileManager.remove.mockClear();
|
|
174
|
+
releaseLocalWadouriRegistrations();
|
|
175
|
+
expect(dicomImageLoader.wadouri.fileManager.remove).not.toHaveBeenCalled();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import OHIF from '@ohif/core';
|
|
2
|
+
|
|
3
|
+
import { registerStoredInstanceImageId } from './registerStoredInstanceImageId';
|
|
4
|
+
|
|
5
|
+
const metadataProvider = OHIF.classes.MetadataProvider;
|
|
6
|
+
|
|
7
|
+
const UIDS = {
|
|
8
|
+
StudyInstanceUID: '1.2.3',
|
|
9
|
+
SeriesInstanceUID: '1.2.3.4',
|
|
10
|
+
SOPInstanceUID: '1.2.3.4.5',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('registerStoredInstanceImageId', () => {
|
|
14
|
+
it('gives the instance the imageId the data source would load it with', () => {
|
|
15
|
+
const instance = { ...UIDS };
|
|
16
|
+
const dataSource = {
|
|
17
|
+
getImageIdsForInstance: jest.fn(
|
|
18
|
+
() => 'wadors:/studies/1.2.3/series/1.2.3.4/instances/1.2.3.4.5/frames/1'
|
|
19
|
+
),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const imageId = registerStoredInstanceImageId(instance, dataSource);
|
|
23
|
+
|
|
24
|
+
expect(imageId).toBe('wadors:/studies/1.2.3/series/1.2.3.4/instances/1.2.3.4.5/frames/1');
|
|
25
|
+
expect(instance.imageId).toBe(imageId);
|
|
26
|
+
expect(dataSource.getImageIdsForInstance).toHaveBeenCalledWith({ instance });
|
|
27
|
+
// Which is what lets the predecessor of a later save be resolved from it.
|
|
28
|
+
expect(metadataProvider.getUIDsFromImageID(imageId)).toMatchObject(UIDS);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('does not add the imageId as a stored attribute', () => {
|
|
32
|
+
const instance = { ...UIDS };
|
|
33
|
+
registerStoredInstanceImageId(instance, { getImageIdsForInstance: () => 'wadors:/an-image' });
|
|
34
|
+
|
|
35
|
+
expect(Object.keys(instance)).not.toContain('imageId');
|
|
36
|
+
expect(JSON.parse(JSON.stringify(instance)).imageId).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('falls back to the locally registered instance', () => {
|
|
40
|
+
// Instances with pixel data are registered with the wadouri file manager,
|
|
41
|
+
// which puts that imageId on `url`.
|
|
42
|
+
const instance = { ...UIDS, url: 'dicomfile:3' };
|
|
43
|
+
|
|
44
|
+
expect(registerStoredInstanceImageId(instance, {})).toBe('dicomfile:3');
|
|
45
|
+
expect(instance.imageId).toBe('dicomfile:3');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('keeps an imageId the instance already has', () => {
|
|
49
|
+
const instance = { ...UIDS, imageId: 'wadors:/already-known', url: 'dicomfile:4' };
|
|
50
|
+
const dataSource = { getImageIdsForInstance: jest.fn() };
|
|
51
|
+
|
|
52
|
+
expect(registerStoredInstanceImageId(instance, dataSource)).toBe('wadors:/already-known');
|
|
53
|
+
expect(dataSource.getImageIdsForInstance).not.toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('does nothing when there is no imageId to be had', () => {
|
|
57
|
+
const instance = { ...UIDS };
|
|
58
|
+
|
|
59
|
+
expect(registerStoredInstanceImageId(instance, undefined)).toBeUndefined();
|
|
60
|
+
expect(instance.imageId).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('survives a data source that cannot make an imageId for the instance', () => {
|
|
64
|
+
const instance = { ...UIDS, url: 'dicomfile:5' };
|
|
65
|
+
const dataSource = {
|
|
66
|
+
getImageIdsForInstance: () => {
|
|
67
|
+
throw new Error('not an image instance');
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
expect(registerStoredInstanceImageId(instance, dataSource)).toBe('dicomfile:5');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import OHIF from '@ohif/core';
|
|
2
|
+
|
|
3
|
+
import { setNonEnumerableInstanceProperty } from './dicomWriter';
|
|
4
|
+
|
|
5
|
+
const metadataProvider = OHIF.classes.MetadataProvider;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gives a just stored instance the imageId that loading it back would use, and
|
|
9
|
+
* maps that imageId to the instance's UIDs.
|
|
10
|
+
*
|
|
11
|
+
* Instances that arrive through a data source's metadata request are given this
|
|
12
|
+
* as part of that request. An instance stored from the viewer is added to the
|
|
13
|
+
* metadata store directly, so it has to be done here - and until it is, the
|
|
14
|
+
* display set made from the stored instance does not know which instance it came
|
|
15
|
+
* from. That is what makes a just stored object the predecessor of the next save
|
|
16
|
+
* of the same data, so that the next save can offer to extend the series just
|
|
17
|
+
* written instead of creating another one.
|
|
18
|
+
*
|
|
19
|
+
* @param instance - naturalized instance that has just been stored
|
|
20
|
+
* @param dataSource - the data source it was stored to, when there is one
|
|
21
|
+
* @returns the imageId of the instance, or undefined when none can be determined
|
|
22
|
+
*/
|
|
23
|
+
export function registerStoredInstanceImageId(instance, dataSource?): string | undefined {
|
|
24
|
+
if (!instance) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (instance.imageId) {
|
|
29
|
+
return instance.imageId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let imageId: string | undefined;
|
|
33
|
+
try {
|
|
34
|
+
imageId = dataSource?.getImageIdsForInstance?.({ instance });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
OHIF.log.debug('Unable to derive the imageId of a stored instance', error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Instances with pixel data have already been registered with the local
|
|
40
|
+
// wadouri file manager, which puts that imageId on `url` and maps it.
|
|
41
|
+
imageId ||= instance.url;
|
|
42
|
+
|
|
43
|
+
if (!imageId || typeof imageId !== 'string') {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setNonEnumerableInstanceProperty(instance, 'imageId', imageId);
|
|
48
|
+
|
|
49
|
+
const { StudyInstanceUID, SeriesInstanceUID } = instance;
|
|
50
|
+
const SOPInstanceUID = instance.SOPInstanceUID || instance.SopInstanceUID;
|
|
51
|
+
|
|
52
|
+
if (StudyInstanceUID && SeriesInstanceUID && SOPInstanceUID) {
|
|
53
|
+
metadataProvider.addImageIdToUIDs(imageId, {
|
|
54
|
+
StudyInstanceUID,
|
|
55
|
+
SeriesInstanceUID,
|
|
56
|
+
SOPInstanceUID,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return imageId;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function registerStoredInstanceImageIds(instances, dataSource?): void {
|
|
64
|
+
const list = Array.isArray(instances) ? instances : [instances];
|
|
65
|
+
list.forEach(instance => registerStoredInstanceImageId(instance, dataSource));
|
|
66
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { HangingProtocolService, Types } from '@ohif/core';
|
|
2
|
+
import { useViewportGridStore } from '../stores/useViewportGridStore';
|
|
3
|
+
import { useDisplaySetSelectorStore } from '../stores/useDisplaySetSelectorStore';
|
|
4
|
+
import { useHangingProtocolStageIndexStore } from '../stores/useHangingProtocolStageIndexStore';
|
|
5
|
+
|
|
6
|
+
export type ReturnType = {
|
|
7
|
+
hangingProtocolStageIndexMap: Record<string, Types.HangingProtocol.HPInfo>;
|
|
8
|
+
viewportGridStore: Record<string, unknown>;
|
|
9
|
+
displaySetSelectorMap: Record<string, Array<string>>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calculates a set of state information for hanging protocols and viewport grid
|
|
14
|
+
* which defines the currently applied hanging protocol state.
|
|
15
|
+
* @param state is the viewport grid state
|
|
16
|
+
* @param syncService is the state sync service to use for getting existing state
|
|
17
|
+
* @returns Set of states that can be applied to the state sync to remember
|
|
18
|
+
* the current view state.
|
|
19
|
+
*/
|
|
20
|
+
const reuseCachedLayout = (state, hangingProtocolService: HangingProtocolService): ReturnType => {
|
|
21
|
+
const { activeViewportId } = state;
|
|
22
|
+
const { protocol } = hangingProtocolService.getActiveProtocol();
|
|
23
|
+
|
|
24
|
+
if (!protocol) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const hpInfo = hangingProtocolService.getState();
|
|
29
|
+
const { protocolId, stageIndex, activeStudyUID } = hpInfo;
|
|
30
|
+
|
|
31
|
+
const { viewportGridState, setViewportGridState } = useViewportGridStore.getState();
|
|
32
|
+
const { displaySetSelectorMap, setDisplaySetSelector } = useDisplaySetSelectorStore.getState();
|
|
33
|
+
const { hangingProtocolStageIndexMap, setHangingProtocolStageIndex } =
|
|
34
|
+
useHangingProtocolStageIndexStore.getState();
|
|
35
|
+
|
|
36
|
+
const stage = protocol.stages[stageIndex];
|
|
37
|
+
const storeId = `${activeStudyUID}:${protocolId}:${stageIndex}`;
|
|
38
|
+
const cacheId = `${activeStudyUID}:${protocolId}`;
|
|
39
|
+
const { rows, columns } = stage.viewportStructure.properties;
|
|
40
|
+
const custom =
|
|
41
|
+
stage.viewports.length !== state.viewports.size ||
|
|
42
|
+
state.layout.numRows !== rows ||
|
|
43
|
+
state.layout.numCols !== columns;
|
|
44
|
+
|
|
45
|
+
hangingProtocolStageIndexMap[cacheId] = hpInfo;
|
|
46
|
+
|
|
47
|
+
if (storeId && custom) {
|
|
48
|
+
setViewportGridState(storeId, { ...state });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
state.viewports.forEach((viewport, viewportId) => {
|
|
52
|
+
const { displaySetOptions, displaySetInstanceUIDs } = viewport;
|
|
53
|
+
if (!displaySetOptions) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const activeDisplaySetUIDs = [];
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < displaySetOptions.length; i++) {
|
|
59
|
+
const displaySetUID = displaySetInstanceUIDs[i];
|
|
60
|
+
if (!displaySetUID) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (viewportId === activeViewportId) {
|
|
64
|
+
activeDisplaySetUIDs.push(displaySetUID);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// The activeDisplaySet selector should only be set once (i.e. for the actual active display set)
|
|
68
|
+
if (displaySetOptions[i]?.id && displaySetOptions[i].id !== 'activeDisplaySet') {
|
|
69
|
+
// TODO: handle multiple layers/display sets for the non-active viewports
|
|
70
|
+
setDisplaySetSelector(
|
|
71
|
+
hangingProtocolService.getDisplaySetSelectorMapKey(activeStudyUID, displaySetOptions[i]),
|
|
72
|
+
[displaySetUID]
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (viewportId === activeViewportId) {
|
|
78
|
+
// After going through all the display set options for the active viewport, store the display set selector array
|
|
79
|
+
setDisplaySetSelector(`${activeStudyUID}:activeDisplaySet:0`, activeDisplaySetUIDs);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
setHangingProtocolStageIndex(cacheId, hpInfo);
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
hangingProtocolStageIndexMap,
|
|
87
|
+
viewportGridStore: viewportGridState,
|
|
88
|
+
displaySetSelectorMap,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default reuseCachedLayout;
|