@ohif/extension-cornerstone 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/915.ohif-extension-cornerstone.umd.js +1 -1
- package/dist/ohif-extension-cornerstone.umd.js +1 -5
- package/package.json +18 -8
- package/src/Viewport/OHIFCornerstoneViewport.css +46 -0
- package/src/Viewport/OHIFCornerstoneViewport.tsx +502 -0
- package/src/Viewport/Overlays/CornerstoneOverlays.tsx +103 -0
- package/src/Viewport/Overlays/CustomizableViewportOverlay.css +25 -0
- package/src/Viewport/Overlays/CustomizableViewportOverlay.tsx +469 -0
- package/src/Viewport/Overlays/ViewportImageScrollbar.tsx +106 -0
- package/src/Viewport/Overlays/ViewportImageSliceLoadingIndicator.tsx +87 -0
- package/src/Viewport/Overlays/ViewportOrientationMarkers.css +41 -0
- package/src/Viewport/Overlays/ViewportOrientationMarkers.tsx +136 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/ViewportSliceProgressScrollbar.tsx +195 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/helpers.ts +46 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/hooks.ts +383 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/index.ts +1 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/types.ts +17 -0
- package/src/Viewport/Overlays/utils.ts +66 -0
- package/src/commandsModule.ts +2951 -0
- package/src/components/AccordionGroup/AccordionGroup.tsx +195 -0
- package/src/components/AccordionGroup/index.ts +4 -0
- package/src/components/ActiveViewportWindowLevel/ActiveViewportWindowLevel.tsx +23 -0
- package/src/components/ActiveViewportWindowLevel/index.js +1 -0
- package/src/components/AdvancedRenderingControls/AdvancedRenderingControls.tsx +149 -0
- package/src/components/AdvancedRenderingControls/index.ts +1 -0
- package/src/components/CinePlayer/CinePlayer.tsx +247 -0
- package/src/components/CinePlayer/index.ts +3 -0
- package/src/components/DicomUpload/DicomUpload.tsx +111 -0
- package/src/components/DicomUpload/DicomUploadProgress.tsx +396 -0
- package/src/components/DicomUpload/DicomUploadProgressItem.tsx +119 -0
- package/src/components/ExportSegmentationSubMenuItem.tsx +75 -0
- package/src/components/MeasurementItems.tsx +70 -0
- package/src/components/MeasurementTableNested.tsx +30 -0
- package/src/components/MeasurementsMenu.tsx +84 -0
- package/src/components/MeasurementsOrAdditionalFindings.tsx +82 -0
- package/src/components/ModalityLoadBadge/ModalityLoadBadge.tsx +171 -0
- package/src/components/ModalityLoadBadge/index.ts +1 -0
- package/src/components/NavigationComponent/NavigationComponent.tsx +138 -0
- package/src/components/NavigationComponent/index.ts +3 -0
- package/src/components/OHIFViewportActionCorners.tsx +94 -0
- package/src/components/OpacityMenu/OpacityMenu.tsx +54 -0
- package/src/components/OpacityMenu/OpacityMenuWrapper.tsx +85 -0
- package/src/components/OpacityMenu/index.ts +2 -0
- package/src/components/PanelAccordionTrigger.tsx +48 -0
- package/src/components/SegmentationToolConfig.tsx +71 -0
- package/src/components/SegmentationUtilityButton.tsx +61 -0
- package/src/components/SelectItemWithModality.tsx +29 -0
- package/src/components/SeriesMeasurements.tsx +90 -0
- package/src/components/SeriesSummaryFromDisplaySet.tsx +21 -0
- package/src/components/StudyMeasurements.tsx +88 -0
- package/src/components/StudyMeasurementsActions.tsx +75 -0
- package/src/components/StudySummaryFromMetadata.test.ts +47 -0
- package/src/components/StudySummaryFromMetadata.tsx +31 -0
- package/src/components/StudySummaryWithActions.tsx +14 -0
- package/src/components/ThresholdMenu/ThresholdMenu.tsx +104 -0
- package/src/components/ThresholdMenu/ThresholdMenuWrapper.tsx +85 -0
- package/src/components/ThresholdMenu/index.ts +2 -0
- package/src/components/TrackingStatus/TrackingStatus.tsx +32 -0
- package/src/components/TrackingStatus/index.ts +1 -0
- package/src/components/VOIManualControlMenu/VOIManualControlMenu.tsx +190 -0
- package/src/components/VOIManualControlMenu/VOIManualControlMenuWrapper.tsx +85 -0
- package/src/components/VOIManualControlMenu/index.ts +2 -0
- package/src/components/ViewportColorbar/ViewportColorbar.tsx +150 -0
- package/src/components/ViewportColorbar/ViewportColorbarsContainer.tsx +125 -0
- package/src/components/ViewportColorbar/index.ts +5 -0
- package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenu.tsx +538 -0
- package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenuWrapper.tsx +91 -0
- package/src/components/ViewportDataOverlaySettingMenu/utils.ts +118 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +29 -0
- package/src/components/ViewportWindowLevel/ViewportWindowLevel.tsx +261 -0
- package/src/components/ViewportWindowLevel/getViewportVolumeHistogram.ts +72 -0
- package/src/components/ViewportWindowLevel/histogramWorker.js +97 -0
- package/src/components/ViewportWindowLevel/index.js +1 -0
- package/src/components/ViewportWindowLevel/utils.ts +176 -0
- package/src/components/WindowLevelActionMenu/Colorbar.tsx +30 -0
- package/src/components/WindowLevelActionMenu/Colormap.tsx +121 -0
- package/src/components/WindowLevelActionMenu/VolumeLighting.tsx +82 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingOptions.tsx +38 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingPresets.tsx +36 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingPresetsContent.tsx +78 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingQuality.tsx +64 -0
- package/src/components/WindowLevelActionMenu/VolumeShade.tsx +47 -0
- package/src/components/WindowLevelActionMenu/VolumeShift.tsx +92 -0
- package/src/components/WindowLevelActionMenu/WindowLevel.tsx +157 -0
- package/src/components/WindowLevelActionMenu/WindowLevelActionMenu.tsx +102 -0
- package/src/components/WindowLevelActionMenu/WindowLevelActionMenuWrapper.tsx +131 -0
- package/src/components/WindowLevelActionMenu/defaultWindowLevelPresets.ts +23 -0
- package/src/components/WindowLevelActionMenu/index.ts +11 -0
- package/src/components/WindowLevelActionMenu/windowLevelPresetHotkeys.test.ts +19 -0
- package/src/components/index.ts +12 -0
- package/src/constants/index.ts +13 -0
- package/src/customizations/CustomDropdownMenuContent.tsx +106 -0
- package/src/customizations/CustomSegmentStatisticsHeader.tsx +140 -0
- package/src/customizations/captureViewportModalCustomization.tsx +175 -0
- package/src/customizations/colorbarCustomization.ts +93 -0
- package/src/customizations/gpuSettingsPresetCustomization.ts +8 -0
- package/src/customizations/layoutSelectorCustomization.ts +104 -0
- package/src/customizations/measurementsCustomization.ts +124 -0
- package/src/customizations/miscCustomization.ts +22 -0
- package/src/customizations/modalityColorMapCustomization.ts +23 -0
- package/src/customizations/segmentationHydrationCustomization.ts +16 -0
- package/src/customizations/segmentationPanelCustomization.tsx +119 -0
- package/src/customizations/segmentationToolbarCustomization.ts +964 -0
- package/src/customizations/toolGroupToolsCustomization.ts +204 -0
- package/src/customizations/toolbarButtonsCustomization.ts +805 -0
- package/src/customizations/viewportClickCommandsCustomization.ts +15 -0
- package/src/customizations/viewportDownloadWarningCustomization.tsx +6 -0
- package/src/customizations/viewportOverlayCustomization.tsx +46 -0
- package/src/customizations/viewportScrollbarCustomization.tsx +27 -0
- package/src/customizations/viewportToolsCustomization.ts +33 -0
- package/src/customizations/volumeRenderingCustomization.ts +14 -0
- package/src/customizations/windowLevelPresetsCustomization.ts +5 -0
- package/src/enums.ts +9 -0
- package/src/getCustomizationModule.tsx +54 -0
- package/src/getHangingProtocolModule.ts +47 -0
- package/src/getPanelModule.tsx +128 -0
- package/src/getSopClassHandlerModule.js +284 -0
- package/src/getToolbarModule.tsx +622 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useActiveViewportSegmentationRepresentations.ts +14 -0
- package/src/hooks/useMeasurementTracking.ts +132 -0
- package/src/hooks/useMeasurements.ts +104 -0
- package/src/hooks/useSegmentations.ts +147 -0
- package/src/hooks/useViewportDisplaySets.ts +284 -0
- package/src/hooks/useViewportHover.ts +77 -0
- package/src/hooks/useViewportRendering.tsx +868 -0
- package/src/hooks/useViewportSegmentations.ts +245 -0
- package/src/hps/fourUp.ts +117 -0
- package/src/hps/frameView.ts +1581 -0
- package/src/hps/main3D.ts +142 -0
- package/src/hps/mpr.ts +197 -0
- package/src/hps/mprAnd3DVolumeViewport.ts +124 -0
- package/src/hps/only3D.ts +70 -0
- package/src/hps/primary3D.ts +142 -0
- package/src/hps/primaryAxial.ts +114 -0
- package/src/id.js +5 -0
- package/src/index.tsx +350 -0
- package/src/init.tsx +445 -0
- package/src/initCineService.ts +75 -0
- package/src/initContextMenu.ts +94 -0
- package/src/initCornerstoneTools.js +188 -0
- package/src/initDoubleClick.ts +82 -0
- package/src/initMeasurementService.ts +576 -0
- package/src/initStudyPrefetcherService.ts +33 -0
- package/src/initWADOImageLoader.js +56 -0
- package/src/panels/PanelMeasurement.tsx +84 -0
- package/src/panels/PanelSegmentation.tsx +338 -0
- package/src/services/ColorbarService/ColorbarService.ts +242 -0
- package/src/services/ColorbarService/index.ts +2 -0
- package/src/services/CornerstoneCacheService/CornerstoneCacheService.ts +326 -0
- package/src/services/CornerstoneCacheService/index.js +3 -0
- package/src/services/SegmentationService/RTSTRUCT/mapROIContoursToRTStructData.ts +36 -0
- package/src/services/SegmentationService/SegmentationService.test.ts +3698 -0
- package/src/services/SegmentationService/SegmentationService.ts +2376 -0
- package/src/services/SegmentationService/backends/ISegmentationBackend.ts +102 -0
- package/src/services/SegmentationService/backends/ISegmentationServiceInternals.ts +44 -0
- package/src/services/SegmentationService/backends/LegacySegmentationBackend.ts +139 -0
- package/src/services/SegmentationService/backends/NextSegmentationBackend.ts +159 -0
- package/src/services/SegmentationService/backends/index.ts +4 -0
- package/src/services/SegmentationService/index.ts +3 -0
- package/src/services/SyncGroupService/SyncGroupService.ts +264 -0
- package/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +118 -0
- package/src/services/SyncGroupService/index.js +3 -0
- package/src/services/ToolGroupService/ToolGroupService.test.ts +83 -0
- package/src/services/ToolGroupService/ToolGroupService.ts +541 -0
- package/src/services/ToolGroupService/index.js +3 -0
- package/src/services/ViewedDataService/ViewedDataService.ts +58 -0
- package/src/services/ViewedDataService/index.ts +3 -0
- package/src/services/ViewportService/CornerstoneViewportService.ts +1814 -0
- package/src/services/ViewportService/IViewportService.ts +64 -0
- package/src/services/ViewportService/Viewport.ts +372 -0
- package/src/services/ViewportService/adapter/IViewportAdapter.contract.test.ts +467 -0
- package/src/services/ViewportService/adapter/IViewportAdapter.ts +179 -0
- package/src/services/ViewportService/adapter/LegacyViewportAdapter.ts +240 -0
- package/src/services/ViewportService/adapter/NextViewportAdapter.ts +241 -0
- package/src/services/ViewportService/adapter/getViewportAdapter.ts +62 -0
- package/src/services/ViewportService/adapter/index.ts +16 -0
- package/src/services/ViewportService/backends/IViewportBackend.ts +195 -0
- package/src/services/ViewportService/backends/IViewportOperations.ts +98 -0
- package/src/services/ViewportService/backends/IViewportServiceInternals.ts +47 -0
- package/src/services/ViewportService/backends/LegacyViewportBackend.ts +264 -0
- package/src/services/ViewportService/backends/LegacyViewportOperations.ts +272 -0
- package/src/services/ViewportService/backends/NextViewportBackend.ts +671 -0
- package/src/services/ViewportService/backends/NextViewportOperations.ts +169 -0
- package/src/services/ViewportService/backends/README.md +62 -0
- package/src/services/ViewportService/backends/dataIdRegistry.ts +121 -0
- package/src/services/ViewportService/backends/viewportOperations.ts +71 -0
- package/src/services/ViewportService/constants.ts +3 -0
- package/src/state.ts +34 -0
- package/src/stores/index.ts +5 -0
- package/src/stores/presentationUtils.ts +42 -0
- package/src/stores/useLutPresentationStore.ts +166 -0
- package/src/stores/usePositionPresentationStore.ts +172 -0
- package/src/stores/useSegmentationPresentationStore.test.ts +146 -0
- package/src/stores/useSegmentationPresentationStore.ts +417 -0
- package/src/stores/useSelectedSegmentationsForViewportStore.ts +85 -0
- package/src/stores/useSynchronizersStore.ts +84 -0
- package/src/synchronizers/frameViewSynchronizer.ts +52 -0
- package/src/tools/CalibrationLineTool.ts +97 -0
- package/src/tools/ImageOverlayViewerTool.tsx +279 -0
- package/src/tools/OverlayPlaneModuleProvider.ts +40 -0
- package/src/tools/WindowLevelTool.test.ts +55 -0
- package/src/tools/WindowLevelTool.ts +22 -0
- package/src/types/AppTypes.ts +70 -0
- package/src/types/Colorbar.ts +114 -0
- package/src/types/Colormap.ts +16 -0
- package/src/types/CornerstoneCacheService.ts +40 -0
- package/src/types/CornerstoneServices.ts +18 -0
- package/src/types/Presentation.ts +83 -0
- package/src/types/SelectedSegmentationByTypeMap.ts +3 -0
- package/src/types/ViewportPresets.ts +53 -0
- package/src/types/VolumeLighting.ts +7 -0
- package/src/types/VolumeRenderingConfig.ts +8 -0
- package/src/types/WindowLevel.ts +5 -0
- package/src/types/index.ts +10 -0
- package/src/utils/ActiveViewportBehavior.tsx +80 -0
- package/src/utils/CornerstoneViewportDownloadForm.tsx +319 -0
- package/src/utils/DicomFileUploader.ts +204 -0
- package/src/utils/JumpPresets.ts +14 -0
- package/src/utils/autoHydrateViewportTypes.ts +69 -0
- package/src/utils/colormaps.js +1597 -0
- package/src/utils/createSegmentationForViewport.ts +83 -0
- package/src/utils/dicomLoaderService.js +225 -0
- package/src/utils/ecgMetadata.test.ts +137 -0
- package/src/utils/ecgMetadata.ts +109 -0
- package/src/utils/findNearbyToolData.test.ts +125 -0
- package/src/utils/findNearbyToolData.ts +21 -0
- package/src/utils/generateSegmentationCSVReport.test.ts +324 -0
- package/src/utils/generateSegmentationCSVReport.ts +131 -0
- package/src/utils/getActiveViewportEnabledElement.test.ts +70 -0
- package/src/utils/getActiveViewportEnabledElement.ts +8 -0
- package/src/utils/getCenterExtent.test.ts +313 -0
- package/src/utils/getCenterExtent.ts +46 -0
- package/src/utils/getCornerstoneBlendMode.test.ts +59 -0
- package/src/utils/getCornerstoneBlendMode.ts +25 -0
- package/src/utils/getCornerstoneOrientation.test.ts +78 -0
- package/src/utils/getCornerstoneOrientation.ts +31 -0
- package/src/utils/getCornerstoneViewportType.test.ts +169 -0
- package/src/utils/getCornerstoneViewportType.ts +88 -0
- package/src/utils/getInterleavedFrames.test.ts +85 -0
- package/src/utils/getInterleavedFrames.ts +73 -0
- package/src/utils/getLegacyViewportType.ts +64 -0
- package/src/utils/getNthFrames.test.ts +145 -0
- package/src/utils/getNthFrames.ts +31 -0
- package/src/utils/getViewportEnabledElement.test.ts +83 -0
- package/src/utils/getViewportEnabledElement.ts +8 -0
- package/src/utils/getViewportOrientationFromImageOrientationPatient.test.ts +50 -0
- package/src/utils/getViewportOrientationFromImageOrientationPatient.ts +56 -0
- package/src/utils/hydrationUtils.test.ts +572 -0
- package/src/utils/hydrationUtils.ts +197 -0
- package/src/utils/imageSliceSync/calculateViewportRegistrations.ts +28 -0
- package/src/utils/imageSliceSync/toggleImageSliceSync.ts +101 -0
- package/src/utils/index.ts +29 -0
- package/src/utils/initGpuSettingsPreset.ts +51 -0
- package/src/utils/initViewTiming.test.ts +342 -0
- package/src/utils/initViewTiming.ts +52 -0
- package/src/utils/initWebWorkerProgressHandler.test.ts +381 -0
- package/src/utils/initWebWorkerProgressHandler.ts +110 -0
- package/src/utils/interleave.test.ts +304 -0
- package/src/utils/interleave.ts +32 -0
- package/src/utils/interleaveCenterLoader.test.ts +547 -0
- package/src/utils/interleaveCenterLoader.ts +143 -0
- package/src/utils/interleaveTopToBottom.test.ts +487 -0
- package/src/utils/interleaveTopToBottom.ts +132 -0
- package/src/utils/isAnyDisplaySetCommon.ts +18 -0
- package/src/utils/isDisplaySetOverlayable.ts +96 -0
- package/src/utils/isMeasurementWithinViewport.test.ts +340 -0
- package/src/utils/isMeasurementWithinViewport.ts +33 -0
- package/src/utils/isReferenceViewable.test.ts +581 -0
- package/src/utils/isReferenceViewable.ts +95 -0
- package/src/utils/loadDisplaySetData.ts +49 -0
- package/src/utils/measurementServiceMappings/Angle.ts +200 -0
- package/src/utils/measurementServiceMappings/ArrowAnnotate.ts +176 -0
- package/src/utils/measurementServiceMappings/Bidirectional.ts +193 -0
- package/src/utils/measurementServiceMappings/CircleROI.ts +227 -0
- package/src/utils/measurementServiceMappings/CobbAngle.ts +206 -0
- package/src/utils/measurementServiceMappings/EllipticalROI.ts +221 -0
- package/src/utils/measurementServiceMappings/Length.ts +206 -0
- package/src/utils/measurementServiceMappings/LivewireContour.ts +175 -0
- package/src/utils/measurementServiceMappings/PlanarFreehandROI.ts +228 -0
- package/src/utils/measurementServiceMappings/Probe.ts +192 -0
- package/src/utils/measurementServiceMappings/RectangleROI.ts +225 -0
- package/src/utils/measurementServiceMappings/SegmentBidirectional.ts +184 -0
- package/src/utils/measurementServiceMappings/SplineROI.ts +227 -0
- package/src/utils/measurementServiceMappings/UltrasoundDirectional.ts +214 -0
- package/src/utils/measurementServiceMappings/UltrasoundPleuraBLine.ts +179 -0
- package/src/utils/measurementServiceMappings/constants/supportedTools.js +21 -0
- package/src/utils/measurementServiceMappings/index.ts +3 -0
- package/src/utils/measurementServiceMappings/measurementServiceMappingsFactory.ts +324 -0
- package/src/utils/measurementServiceMappings/utils/getDisplayUnit.js +3 -0
- package/src/utils/measurementServiceMappings/utils/getHandlesFromPoints.js +14 -0
- package/src/utils/measurementServiceMappings/utils/getIsLocked.ts +5 -0
- package/src/utils/measurementServiceMappings/utils/getIsVisible.ts +6 -0
- package/src/utils/measurementServiceMappings/utils/getSOPInstanceAttributes.js +66 -0
- package/src/utils/measurementServiceMappings/utils/getValueDisplayString.js +12 -0
- package/src/utils/measurementServiceMappings/utils/index.ts +17 -0
- package/src/utils/measurementServiceMappings/utils/selection.ts +33 -0
- package/src/utils/mpr/getProtocolViewportStructureFromGridViewports.ts +74 -0
- package/src/utils/nextViewportPolicies.ts +41 -0
- package/src/utils/nextViewports.ts +157 -0
- package/src/utils/nthLoader.test.ts +317 -0
- package/src/utils/nthLoader.ts +78 -0
- package/src/utils/presentations/getViewportPresentations.test.ts +280 -0
- package/src/utils/presentations/getViewportPresentations.ts +151 -0
- package/src/utils/promptHydrationDialog.test.ts +490 -0
- package/src/utils/promptHydrationDialog.ts +197 -0
- package/src/utils/removeViewportSegmentationRepresentations.test.ts +129 -0
- package/src/utils/removeViewportSegmentationRepresentations.ts +17 -0
- package/src/utils/segmentUtils.test.ts +515 -0
- package/src/utils/segmentUtils.ts +46 -0
- package/src/utils/segmentationExportUtils.test.ts +100 -0
- package/src/utils/segmentationExportUtils.ts +171 -0
- package/src/utils/segmentationHandlers.test.ts +614 -0
- package/src/utils/segmentationHandlers.ts +164 -0
- package/src/utils/setUpAnnotationEventHandlers.ts +26 -0
- package/src/utils/setUpSegmentationEventHandlers.test.ts +372 -0
- package/src/utils/setUpSegmentationEventHandlers.ts +122 -0
- package/src/utils/toggleVOISliceSync.test.ts +606 -0
- package/src/utils/toggleVOISliceSync.ts +103 -0
- package/src/utils/transitions.test.ts +351 -0
- package/src/utils/transitions.ts +300 -0
- package/src/utils/updateSegmentationStats.test.ts +942 -0
- package/src/utils/updateSegmentationStats.ts +192 -0
- package/src/utils/viewportDataShape.ts +85 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
2
|
+
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
|
|
3
|
+
import i18n from '@ohif/i18n';
|
|
4
|
+
import { ServicesManager } from '@ohif/core';
|
|
5
|
+
|
|
6
|
+
function _createDefaultSegments(createInitialSegment?: boolean) {
|
|
7
|
+
return createInitialSegment
|
|
8
|
+
? {
|
|
9
|
+
1: {
|
|
10
|
+
label: `${i18n.t('Tools:Segment')} 1`,
|
|
11
|
+
active: true,
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
: {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type CreateSegmentationForViewportOptions = {
|
|
18
|
+
displaySetInstanceUID?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
segmentationId?: string;
|
|
21
|
+
createInitialSegment?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type CreateSegmentationForViewportParams = {
|
|
25
|
+
viewportId: string;
|
|
26
|
+
options?: CreateSegmentationForViewportOptions;
|
|
27
|
+
segmentationType: SegmentationRepresentations;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a segmentation for the active viewport
|
|
32
|
+
*
|
|
33
|
+
* The created segmentation will be registered as a display set and also added
|
|
34
|
+
* as a segmentation representation to the viewport.
|
|
35
|
+
*/
|
|
36
|
+
export async function createSegmentationForViewport(
|
|
37
|
+
servicesManager: ServicesManager,
|
|
38
|
+
{ viewportId, options = {}, segmentationType }: CreateSegmentationForViewportParams
|
|
39
|
+
): Promise<string | undefined> {
|
|
40
|
+
const { viewportGridService, displaySetService, segmentationService } = servicesManager.services;
|
|
41
|
+
const { viewports } = viewportGridService.getState();
|
|
42
|
+
const targetViewportId = viewportId;
|
|
43
|
+
|
|
44
|
+
const viewport = viewports.get(targetViewportId);
|
|
45
|
+
|
|
46
|
+
// Todo: add support for multiple display sets
|
|
47
|
+
// Guard against the grid not having this viewport yet (a transient race when
|
|
48
|
+
// "Add segmentation" runs before the viewport is registered in the grid). Bail
|
|
49
|
+
// gracefully instead of throwing, which would surface an uncaught error overlay.
|
|
50
|
+
const displaySetInstanceUID =
|
|
51
|
+
options.displaySetInstanceUID || viewport?.displaySetInstanceUIDs?.[0];
|
|
52
|
+
|
|
53
|
+
if (!displaySetInstanceUID) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const segs = segmentationService.getSegmentations();
|
|
58
|
+
|
|
59
|
+
const label = options.label || `${i18n.t('Tools:Segmentation')} ${segs.length + 1}`;
|
|
60
|
+
const segmentationId = options.segmentationId || `${csUtils.uuidv4()}`;
|
|
61
|
+
|
|
62
|
+
const displaySet = displaySetService.getDisplaySetByUID(displaySetInstanceUID);
|
|
63
|
+
|
|
64
|
+
const segmentationCreationOptions = {
|
|
65
|
+
label,
|
|
66
|
+
segmentationId,
|
|
67
|
+
labelIsGenerated: !options.label,
|
|
68
|
+
segments: _createDefaultSegments(options.createInitialSegment),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// This will create the segmentation and register it as a display set
|
|
72
|
+
const generatedSegmentationId = await (segmentationType === SegmentationRepresentations.Labelmap
|
|
73
|
+
? segmentationService.createLabelmapForDisplaySet(displaySet, segmentationCreationOptions)
|
|
74
|
+
: segmentationService.createContourForDisplaySet(displaySet, segmentationCreationOptions));
|
|
75
|
+
|
|
76
|
+
// Also add the segmentation representation to the viewport
|
|
77
|
+
await segmentationService.addSegmentationRepresentation(viewportId, {
|
|
78
|
+
segmentationId,
|
|
79
|
+
type: segmentationType,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return generatedSegmentationId;
|
|
83
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { imageLoader } from '@cornerstonejs/core';
|
|
2
|
+
import dicomImageLoader from '@cornerstonejs/dicom-image-loader';
|
|
3
|
+
import { api } from 'dicomweb-client';
|
|
4
|
+
import { DICOMWeb, errorHandler } from '@ohif/core';
|
|
5
|
+
|
|
6
|
+
const getImageId = imageObj => {
|
|
7
|
+
if (!imageObj) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return typeof imageObj.getImageId === 'function' ? imageObj.getImageId() : imageObj.url;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const findImageIdOnStudies = (studies, displaySetInstanceUID) => {
|
|
15
|
+
const study = studies.find(study => {
|
|
16
|
+
const displaySet = study.displaySets.some(
|
|
17
|
+
displaySet => displaySet.displaySetInstanceUID === displaySetInstanceUID
|
|
18
|
+
);
|
|
19
|
+
return displaySet;
|
|
20
|
+
});
|
|
21
|
+
const { series = [] } = study;
|
|
22
|
+
const { instances = [] } = series[0] || {};
|
|
23
|
+
const instance = instances[0];
|
|
24
|
+
|
|
25
|
+
return getImageId(instance);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const someInvalidStrings = strings => {
|
|
29
|
+
const stringsArray = Array.isArray(strings) ? strings : [strings];
|
|
30
|
+
const emptyString = string => !string;
|
|
31
|
+
let invalid = stringsArray.some(emptyString);
|
|
32
|
+
return invalid;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const getImageInstance = dataset => {
|
|
36
|
+
return dataset && dataset.images && dataset.images[0];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getNonImageInstance = dataset => {
|
|
40
|
+
return dataset && dataset.instance;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const getImageInstanceId = imageInstance => {
|
|
44
|
+
return getImageId(imageInstance);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const fetchIt = (url, headers = DICOMWeb.getAuthorizationHeader()) => {
|
|
48
|
+
return fetch(url, headers).then(response => response.arrayBuffer());
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const cornerstoneRetriever = imageId => {
|
|
52
|
+
return imageLoader.loadAndCacheImage(imageId).then(image => {
|
|
53
|
+
return image && image.data && image.data.byteArray.buffer;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const wadorsRetriever = (
|
|
58
|
+
url,
|
|
59
|
+
studyInstanceUID,
|
|
60
|
+
seriesInstanceUID,
|
|
61
|
+
sopInstanceUID,
|
|
62
|
+
headers = DICOMWeb.getAuthorizationHeader(),
|
|
63
|
+
errorInterceptor = errorHandler.getHTTPErrorHandler()
|
|
64
|
+
) => {
|
|
65
|
+
const config = {
|
|
66
|
+
url,
|
|
67
|
+
headers,
|
|
68
|
+
errorInterceptor,
|
|
69
|
+
};
|
|
70
|
+
const dicomWeb = new api.DICOMwebClient(config);
|
|
71
|
+
|
|
72
|
+
return dicomWeb.retrieveInstance({
|
|
73
|
+
studyInstanceUID,
|
|
74
|
+
seriesInstanceUID,
|
|
75
|
+
sopInstanceUID,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getImageLoaderType = imageId => {
|
|
80
|
+
const loaderRegExp = /^\w+\:/;
|
|
81
|
+
const loaderType = loaderRegExp.exec(imageId);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
(loaderRegExp.lastIndex === 0 &&
|
|
85
|
+
loaderType &&
|
|
86
|
+
loaderType[0] &&
|
|
87
|
+
loaderType[0].replace(':', '')) ||
|
|
88
|
+
''
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
class DicomLoaderService {
|
|
93
|
+
getLocalData(dataset, studies) {
|
|
94
|
+
// Use referenced imageInstance
|
|
95
|
+
const imageInstance = getImageInstance(dataset);
|
|
96
|
+
const nonImageInstance = getNonImageInstance(dataset);
|
|
97
|
+
|
|
98
|
+
if (
|
|
99
|
+
(!imageInstance && !nonImageInstance) ||
|
|
100
|
+
!nonImageInstance.imageId?.startsWith('dicomfile')
|
|
101
|
+
) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const instance = imageInstance || nonImageInstance;
|
|
106
|
+
|
|
107
|
+
let imageId = getImageInstanceId(instance);
|
|
108
|
+
|
|
109
|
+
// or Try to get it from studies
|
|
110
|
+
if (someInvalidStrings(imageId)) {
|
|
111
|
+
imageId = findImageIdOnStudies(studies, dataset.displaySetInstanceUID);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!someInvalidStrings(imageId)) {
|
|
115
|
+
return dicomImageLoader.wadouri.loadFileRequest(imageId);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getDataByImageType(dataset) {
|
|
120
|
+
const imageInstance = getImageInstance(dataset);
|
|
121
|
+
|
|
122
|
+
if (imageInstance) {
|
|
123
|
+
let imageId = getImageInstanceId(imageInstance);
|
|
124
|
+
let getDicomDataMethod = fetchIt;
|
|
125
|
+
const loaderType = getImageLoaderType(imageId);
|
|
126
|
+
|
|
127
|
+
switch (loaderType) {
|
|
128
|
+
case 'dicomfile':
|
|
129
|
+
getDicomDataMethod = cornerstoneRetriever.bind(this, imageId);
|
|
130
|
+
break;
|
|
131
|
+
case 'wadors':
|
|
132
|
+
const url = imageInstance.getData().wadoRoot;
|
|
133
|
+
const studyInstanceUID = imageInstance.getStudyInstanceUID();
|
|
134
|
+
const seriesInstanceUID = imageInstance.getSeriesInstanceUID();
|
|
135
|
+
const sopInstanceUID = imageInstance.getSOPInstanceUID();
|
|
136
|
+
const invalidParams = someInvalidStrings([
|
|
137
|
+
url,
|
|
138
|
+
studyInstanceUID,
|
|
139
|
+
seriesInstanceUID,
|
|
140
|
+
sopInstanceUID,
|
|
141
|
+
]);
|
|
142
|
+
if (invalidParams) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getDicomDataMethod = wadorsRetriever.bind(
|
|
147
|
+
this,
|
|
148
|
+
url,
|
|
149
|
+
studyInstanceUID,
|
|
150
|
+
seriesInstanceUID,
|
|
151
|
+
sopInstanceUID
|
|
152
|
+
);
|
|
153
|
+
break;
|
|
154
|
+
case 'wadouri':
|
|
155
|
+
// Strip out the image loader specifier
|
|
156
|
+
imageId = imageId.substring(imageId.indexOf(':') + 1);
|
|
157
|
+
|
|
158
|
+
if (someInvalidStrings(imageId)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
getDicomDataMethod = fetchIt.bind(this, imageId);
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return getDicomDataMethod();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
getDataByDatasetType(dataset) {
|
|
172
|
+
const {
|
|
173
|
+
StudyInstanceUID,
|
|
174
|
+
SeriesInstanceUID,
|
|
175
|
+
SOPInstanceUID,
|
|
176
|
+
authorizationHeaders,
|
|
177
|
+
wadoRoot,
|
|
178
|
+
wadoUri,
|
|
179
|
+
instance,
|
|
180
|
+
} = dataset;
|
|
181
|
+
// Retrieve wadors or just try to fetch wadouri
|
|
182
|
+
if (!someInvalidStrings(wadoRoot)) {
|
|
183
|
+
return wadorsRetriever(
|
|
184
|
+
wadoRoot,
|
|
185
|
+
StudyInstanceUID,
|
|
186
|
+
SeriesInstanceUID,
|
|
187
|
+
SOPInstanceUID,
|
|
188
|
+
authorizationHeaders
|
|
189
|
+
);
|
|
190
|
+
} else if (!someInvalidStrings(wadoUri)) {
|
|
191
|
+
return fetchIt(wadoUri, { headers: authorizationHeaders });
|
|
192
|
+
} else if (!someInvalidStrings(instance?.url)) {
|
|
193
|
+
// make sure the url is absolute, remove the scope
|
|
194
|
+
// from it if it is not absolute. For instance it might be dicomweb:http://....
|
|
195
|
+
// and we need to remove the dicomweb: part
|
|
196
|
+
const url = instance.url;
|
|
197
|
+
const absoluteUrl = url.startsWith('http') ? url : url.substring(url.indexOf(':') + 1);
|
|
198
|
+
return fetchIt(absoluteUrl, { headers: authorizationHeaders });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
*getLoaderIterator(dataset, studies, headers) {
|
|
203
|
+
yield this.getLocalData(dataset, studies);
|
|
204
|
+
yield this.getDataByImageType(dataset);
|
|
205
|
+
yield this.getDataByDatasetType(dataset);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
findDicomDataPromise(dataset, studies, headers) {
|
|
209
|
+
dataset.authorizationHeaders = headers;
|
|
210
|
+
const loaderIterator = this.getLoaderIterator(dataset, studies);
|
|
211
|
+
// it returns first valid retriever method.
|
|
212
|
+
for (const loader of loaderIterator) {
|
|
213
|
+
if (loader) {
|
|
214
|
+
return loader;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// in case of no valid loader
|
|
219
|
+
throw new Error('Invalid dicom data loader');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const dicomLoaderService = new DicomLoaderService();
|
|
224
|
+
|
|
225
|
+
export default dicomLoaderService;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { utilities as csMetadataUtilities } from '@cornerstonejs/metadata';
|
|
2
|
+
import { buildEcgModule } from './ecgMetadata';
|
|
3
|
+
|
|
4
|
+
jest.mock('@cornerstonejs/metadata', () => {
|
|
5
|
+
const actual = jest.requireActual('@cornerstonejs/metadata');
|
|
6
|
+
const { buildEcgModuleFromInstance } = actual.utilities;
|
|
7
|
+
return {
|
|
8
|
+
...actual,
|
|
9
|
+
utilities: { ...actual.utilities, buildEcgModuleFromInstance: jest.fn(buildEcgModuleFromInstance) },
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Two channels, two samples, interleaved: ch0=[1, -2], ch1=[3, 4].
|
|
14
|
+
const SAMPLES = new Int16Array([1, 3, -2, 4]);
|
|
15
|
+
|
|
16
|
+
const makeInstance = WaveformData => ({
|
|
17
|
+
WaveformSequence: [
|
|
18
|
+
{
|
|
19
|
+
NumberOfWaveformChannels: 2,
|
|
20
|
+
NumberOfWaveformSamples: 2,
|
|
21
|
+
SamplingFrequency: 500,
|
|
22
|
+
WaveformBitsAllocated: 16,
|
|
23
|
+
WaveformSampleInterpretation: 'SS',
|
|
24
|
+
MultiplexGroupLabel: '12 Lead ECG',
|
|
25
|
+
ChannelDefinitionSequence: [
|
|
26
|
+
{ ChannelSourceSequence: [{ CodeMeaning: 'Lead I' }] },
|
|
27
|
+
{ ChannelSourceSequence: [{ CodeMeaning: 'Lead II' }] },
|
|
28
|
+
],
|
|
29
|
+
WaveformData,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const channelsOf = (channels: Int16Array[]) => channels.map(channel => Array.from(channel));
|
|
35
|
+
|
|
36
|
+
describe('buildEcgModule', () => {
|
|
37
|
+
it('returns null when WaveformSequence is absent', () => {
|
|
38
|
+
expect(buildEcgModule({})).toBeNull();
|
|
39
|
+
expect(buildEcgModule({ WaveformSequence: [] })).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('returns the waveform attributes and the lead names', () => {
|
|
43
|
+
const module = buildEcgModule(makeInstance({}));
|
|
44
|
+
|
|
45
|
+
expect(module!.numberOfWaveformChannels).toBe(2);
|
|
46
|
+
expect(module!.numberOfWaveformSamples).toBe(2);
|
|
47
|
+
expect(module!.samplingFrequency).toBe(500);
|
|
48
|
+
expect(module!.multiplexGroupLabel).toBe('12 Lead ECG');
|
|
49
|
+
expect(module!.channelDefinitionSequence[0].channelSourceSequence.codeMeaning).toBe('Lead I');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('decodes InlineBinary data', async () => {
|
|
53
|
+
const base64 = btoa(String.fromCharCode(...new Uint8Array(SAMPLES.buffer)));
|
|
54
|
+
const module = buildEcgModule(makeInstance({ InlineBinary: base64 }));
|
|
55
|
+
|
|
56
|
+
expect(channelsOf(await module!.waveformData.retrieveBulkData())).toEqual([
|
|
57
|
+
[1, -2],
|
|
58
|
+
[3, 4],
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('decodes the bytes that the data source retrieveBulkData returns', async () => {
|
|
63
|
+
const retrieveBulkData = jest.fn().mockResolvedValue(SAMPLES.buffer.slice(0));
|
|
64
|
+
const module = buildEcgModule(
|
|
65
|
+
makeInstance({ BulkDataURI: 'http://example.com/waveform', retrieveBulkData })
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(channelsOf(await module!.waveformData.retrieveBulkData())).toEqual([
|
|
69
|
+
[1, -2],
|
|
70
|
+
[3, 4],
|
|
71
|
+
]);
|
|
72
|
+
expect(retrieveBulkData).toHaveBeenCalledTimes(1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('decodes a typed array from the data source retrieveBulkData', async () => {
|
|
76
|
+
const bytes = new Uint8Array(SAMPLES.buffer.slice(0));
|
|
77
|
+
const module = buildEcgModule(
|
|
78
|
+
makeInstance({ BulkDataURI: 'x', retrieveBulkData: jest.fn().mockResolvedValue(bytes) })
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(channelsOf(await module!.waveformData.retrieveBulkData())).toEqual([
|
|
82
|
+
[1, -2],
|
|
83
|
+
[3, 4],
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('uses the cached Value and does not fetch again on a re-mount', async () => {
|
|
88
|
+
const retrieveBulkData = jest.fn();
|
|
89
|
+
const module = buildEcgModule(
|
|
90
|
+
makeInstance({ BulkDataURI: 'x', Value: SAMPLES.buffer.slice(0), retrieveBulkData })
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
await module!.waveformData.retrieveBulkData();
|
|
94
|
+
expect(channelsOf(await module!.waveformData.retrieveBulkData())).toEqual([
|
|
95
|
+
[1, -2],
|
|
96
|
+
[3, 4],
|
|
97
|
+
]);
|
|
98
|
+
expect(retrieveBulkData).not.toHaveBeenCalled();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('gives the auth headers to the Cornerstone bulkdata fetch', () => {
|
|
102
|
+
const builder = csMetadataUtilities.buildEcgModuleFromInstance as jest.Mock;
|
|
103
|
+
const authHeader = { Authorization: 'Bearer token' };
|
|
104
|
+
buildEcgModule(makeInstance({ BulkDataURI: 'x' }), {
|
|
105
|
+
getAuthorizationHeader: () => authHeader,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const options = builder.mock.lastCall[2] as { getHeaders: () => unknown };
|
|
109
|
+
expect(options.getHeaders()).toBe(authHeader);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('reads lead names from a lowercase codeMeaning', () => {
|
|
113
|
+
const instance = makeInstance({});
|
|
114
|
+
instance.WaveformSequence[0].ChannelDefinitionSequence[0].ChannelSourceSequence = [
|
|
115
|
+
{ codeMeaning: 'Lead I' } as never,
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const module = buildEcgModule(instance);
|
|
119
|
+
|
|
120
|
+
expect(module!.channelDefinitionSequence[0].channelSourceSequence.codeMeaning).toBe('Lead I');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('passes the lead code value and coding scheme', () => {
|
|
124
|
+
const instance = makeInstance({});
|
|
125
|
+
instance.WaveformSequence[0].ChannelDefinitionSequence[1].ChannelSourceSequence = [
|
|
126
|
+
{ CodeValue: '5.6.3-9-2', CodingSchemeDesignator: 'SCPECG', CodeMeaning: 'Lead II' } as never,
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const source = buildEcgModule(instance)!.channelDefinitionSequence[1].channelSourceSequence as {
|
|
130
|
+
codeValue?: string;
|
|
131
|
+
codingSchemeDesignator?: string;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
expect(source.codeValue).toBe('5.6.3-9-2');
|
|
135
|
+
expect(source.codingSchemeDesignator).toBe('SCPECG');
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { utilities as csMetadataUtilities } from '@cornerstonejs/metadata';
|
|
2
|
+
|
|
3
|
+
export type EcgModule = NonNullable<
|
|
4
|
+
ReturnType<typeof csMetadataUtilities.buildEcgModuleFromInstance>
|
|
5
|
+
>;
|
|
6
|
+
|
|
7
|
+
type BuildEcgModuleFromInstance = (
|
|
8
|
+
instance: Record<string, unknown>,
|
|
9
|
+
imageId?: string,
|
|
10
|
+
// Released @cornerstonejs/metadata versions ignore this argument.
|
|
11
|
+
options?: { getHeaders?: () => Record<string, string> | undefined }
|
|
12
|
+
) => EcgModule | null;
|
|
13
|
+
|
|
14
|
+
const buildEcgModuleFromInstance = (...args: Parameters<BuildEcgModuleFromInstance>) =>
|
|
15
|
+
(csMetadataUtilities.buildEcgModuleFromInstance as BuildEcgModuleFromInstance)(...args);
|
|
16
|
+
|
|
17
|
+
/** Returns the items of a naturalized sequence: an array, an array-like, or one item. */
|
|
18
|
+
function toList(value: any): any[] {
|
|
19
|
+
if (!value) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return typeof value.length === 'number' ? Array.from(value) : [value];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Returns the first item of a naturalized value, but keeps binary data whole. */
|
|
26
|
+
function firstItem(value: any): any {
|
|
27
|
+
if (!value || value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return typeof value.length === 'number' ? value[0] : value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Copies the bytes of a typed array into an ArrayBuffer, which every Cornerstone version decodes. */
|
|
34
|
+
function toArrayBuffer(bytes: unknown): unknown {
|
|
35
|
+
return ArrayBuffer.isView(bytes)
|
|
36
|
+
? bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
|
|
37
|
+
: bytes;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function decodeBulkData(group: any, waveformData: any): Promise<Int16Array[]> {
|
|
41
|
+
let bytes = waveformData.Value;
|
|
42
|
+
if (bytes === undefined) {
|
|
43
|
+
bytes = await waveformData.retrieveBulkData();
|
|
44
|
+
}
|
|
45
|
+
const loaded = { WaveformSequence: [{ ...group, WaveformData: toArrayBuffer(bytes) }] };
|
|
46
|
+
const decoded = buildEcgModuleFromInstance(loaded);
|
|
47
|
+
if (!decoded) {
|
|
48
|
+
throw new Error('[ECGViewport] Failed to decode the waveform bulkdata');
|
|
49
|
+
}
|
|
50
|
+
return decoded.waveformData.retrieveBulkData();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Parse the naturalized DICOM instance's WaveformSequence and build the ecgModule
|
|
55
|
+
* that Cornerstone's ECGViewport.setEcg() expects via
|
|
56
|
+
* metaData.get(MetadataModules.ECG, imageId).
|
|
57
|
+
*
|
|
58
|
+
* Cornerstone decodes the waveform. When the data source attached a
|
|
59
|
+
* `retrieveBulkData` to `WaveformData`, that method fetches the bytes, so the
|
|
60
|
+
* data source handles multipart/related, auth and relative bulkdata URIs.
|
|
61
|
+
* The bytes come from `WaveformData.Value` when the data source already
|
|
62
|
+
* cached them there. The decoded channels are kept, so a re-mount of the
|
|
63
|
+
* same display set does not fetch or decode again; a failed load is retried.
|
|
64
|
+
*
|
|
65
|
+
* Returns null if the instance has no WaveformSequence.
|
|
66
|
+
*/
|
|
67
|
+
export function buildEcgModule(instance: any, userAuthenticationService?: any): EcgModule | null {
|
|
68
|
+
if (!instance?.WaveformSequence?.length) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const ecgModule = buildEcgModuleFromInstance(instance, instance.imageId, {
|
|
73
|
+
getHeaders: () => userAuthenticationService?.getAuthorizationHeader?.(),
|
|
74
|
+
});
|
|
75
|
+
if (!ecgModule) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const group = firstItem(instance.WaveformSequence);
|
|
80
|
+
const channelDefinitions = toList(group.ChannelDefinitionSequence);
|
|
81
|
+
// Works around a Cornerstone bug: buildEcgModuleFromInstance reads only an
|
|
82
|
+
// upper-case CodeMeaning, and drops CodeValue and CodingSchemeDesignator.
|
|
83
|
+
// No released Cornerstone viewport reads the lead code yet, so only the unit
|
|
84
|
+
// test covers it.
|
|
85
|
+
ecgModule.channelDefinitionSequence.forEach((definition, index) => {
|
|
86
|
+
const source = definition.channelSourceSequence as Record<string, string> | undefined;
|
|
87
|
+
const raw = firstItem(channelDefinitions[index]?.ChannelSourceSequence);
|
|
88
|
+
if (!source || !raw) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
source.codeMeaning ||= raw.codeMeaning ?? raw.CodeMeaning ?? '';
|
|
92
|
+
source.codeValue ??= raw.CodeValue ?? raw.codeValue;
|
|
93
|
+
source.codingSchemeDesignator ??= raw.CodingSchemeDesignator ?? raw.codingSchemeDesignator;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const waveformData = firstItem(group.WaveformData ?? group.waveformData);
|
|
97
|
+
if (typeof waveformData?.retrieveBulkData === 'function') {
|
|
98
|
+
let channels: Promise<Int16Array[]> | undefined;
|
|
99
|
+
ecgModule.waveformData.retrieveBulkData = () => {
|
|
100
|
+
channels ??= decodeBulkData(group, waveformData).catch(error => {
|
|
101
|
+
channels = undefined;
|
|
102
|
+
throw error;
|
|
103
|
+
});
|
|
104
|
+
return channels;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return ecgModule;
|
|
109
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { findNearbyToolData } from './findNearbyToolData';
|
|
2
|
+
|
|
3
|
+
describe('findNearbyToolData', () => {
|
|
4
|
+
const mockCommandsManager = {
|
|
5
|
+
runCommand: jest.fn(),
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return undefined when event is null', () => {
|
|
13
|
+
const result = findNearbyToolData(mockCommandsManager, null);
|
|
14
|
+
|
|
15
|
+
expect(result).toBeUndefined();
|
|
16
|
+
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return undefined when event is undefined', () => {
|
|
20
|
+
const result = findNearbyToolData(mockCommandsManager, undefined);
|
|
21
|
+
|
|
22
|
+
expect(result).toBeUndefined();
|
|
23
|
+
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return undefined when event has no detail', () => {
|
|
27
|
+
const event = {};
|
|
28
|
+
const result = findNearbyToolData(mockCommandsManager, event);
|
|
29
|
+
|
|
30
|
+
expect(result).toBeUndefined();
|
|
31
|
+
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should return undefined when event detail is null', () => {
|
|
35
|
+
const event = { detail: null };
|
|
36
|
+
const result = findNearbyToolData(mockCommandsManager, event);
|
|
37
|
+
|
|
38
|
+
expect(result).toBeUndefined();
|
|
39
|
+
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should call runCommand with correct parameters when event has valid detail', () => {
|
|
43
|
+
const mockElement = document.createElement('div');
|
|
44
|
+
const mockCurrentPoints = { canvas: { x: 100, y: 200 } };
|
|
45
|
+
const mockToolData = { id: 'annotation-1' };
|
|
46
|
+
const event = {
|
|
47
|
+
detail: {
|
|
48
|
+
element: mockElement,
|
|
49
|
+
currentPoints: mockCurrentPoints,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
mockCommandsManager.runCommand.mockReturnValue(mockToolData);
|
|
54
|
+
|
|
55
|
+
const result = findNearbyToolData(mockCommandsManager, event);
|
|
56
|
+
|
|
57
|
+
expect(mockCommandsManager.runCommand).toHaveBeenCalledWith(
|
|
58
|
+
'getNearbyAnnotation',
|
|
59
|
+
{
|
|
60
|
+
element: mockElement,
|
|
61
|
+
canvasCoordinates: mockCurrentPoints.canvas,
|
|
62
|
+
},
|
|
63
|
+
'CORNERSTONE'
|
|
64
|
+
);
|
|
65
|
+
expect(result).toBe(mockToolData);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should handle event with element but no currentPoints', () => {
|
|
69
|
+
const mockElement = document.createElement('div');
|
|
70
|
+
const event = {
|
|
71
|
+
detail: {
|
|
72
|
+
element: mockElement,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
findNearbyToolData(mockCommandsManager, event);
|
|
77
|
+
|
|
78
|
+
expect(mockCommandsManager.runCommand).toHaveBeenCalledWith(
|
|
79
|
+
'getNearbyAnnotation',
|
|
80
|
+
{
|
|
81
|
+
element: mockElement,
|
|
82
|
+
canvasCoordinates: undefined,
|
|
83
|
+
},
|
|
84
|
+
'CORNERSTONE'
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should handle event with currentPoints but no canvas coordinates', () => {
|
|
89
|
+
const mockElement = document.createElement('div');
|
|
90
|
+
const mockCurrentPoints = {};
|
|
91
|
+
const event = {
|
|
92
|
+
detail: {
|
|
93
|
+
element: mockElement,
|
|
94
|
+
currentPoints: mockCurrentPoints,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
findNearbyToolData(mockCommandsManager, event);
|
|
99
|
+
|
|
100
|
+
expect(mockCommandsManager.runCommand).toHaveBeenCalledWith(
|
|
101
|
+
'getNearbyAnnotation',
|
|
102
|
+
{
|
|
103
|
+
element: mockElement,
|
|
104
|
+
canvasCoordinates: undefined,
|
|
105
|
+
},
|
|
106
|
+
'CORNERSTONE'
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should return result from runCommand', () => {
|
|
111
|
+
const mockToolData = { id: 'test-annotation', data: 'test-data' };
|
|
112
|
+
const event = {
|
|
113
|
+
detail: {
|
|
114
|
+
element: document.createElement('div'),
|
|
115
|
+
currentPoints: { canvas: { x: 50, y: 75 } },
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
mockCommandsManager.runCommand.mockReturnValue(mockToolData);
|
|
120
|
+
|
|
121
|
+
const result = findNearbyToolData(mockCommandsManager, event);
|
|
122
|
+
|
|
123
|
+
expect(result).toBe(mockToolData);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds tool nearby event position triggered.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} commandsManager mannager of commands
|
|
5
|
+
* @param {Object} event that has being triggered
|
|
6
|
+
* @returns cs toolData or undefined if not found.
|
|
7
|
+
*/
|
|
8
|
+
export const findNearbyToolData = (commandsManager, evt) => {
|
|
9
|
+
if (!evt?.detail) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { element, currentPoints } = evt.detail;
|
|
13
|
+
return commandsManager.runCommand(
|
|
14
|
+
'getNearbyAnnotation',
|
|
15
|
+
{
|
|
16
|
+
element,
|
|
17
|
+
canvasCoordinates: currentPoints?.canvas,
|
|
18
|
+
},
|
|
19
|
+
'CORNERSTONE'
|
|
20
|
+
);
|
|
21
|
+
};
|