@ohif/extension-cornerstone 3.14.0-beta.11 → 3.14.0-beta.110

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.
Files changed (328) hide show
  1. package/dist/915.ohif-extension-cornerstone.umd.js +1 -1
  2. package/dist/ohif-extension-cornerstone.umd.js +1 -5
  3. package/package.json +33 -25
  4. package/src/Viewport/OHIFCornerstoneViewport.css +46 -0
  5. package/src/Viewport/OHIFCornerstoneViewport.tsx +502 -0
  6. package/src/Viewport/Overlays/CornerstoneOverlays.tsx +103 -0
  7. package/src/Viewport/Overlays/CustomizableViewportOverlay.css +25 -0
  8. package/src/Viewport/Overlays/CustomizableViewportOverlay.tsx +469 -0
  9. package/src/Viewport/Overlays/ViewportImageScrollbar.tsx +106 -0
  10. package/src/Viewport/Overlays/ViewportImageSliceLoadingIndicator.tsx +87 -0
  11. package/src/Viewport/Overlays/ViewportOrientationMarkers.css +41 -0
  12. package/src/Viewport/Overlays/ViewportOrientationMarkers.tsx +136 -0
  13. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/ViewportSliceProgressScrollbar.tsx +195 -0
  14. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/helpers.ts +46 -0
  15. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/hooks.ts +383 -0
  16. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/index.ts +1 -0
  17. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/types.ts +17 -0
  18. package/src/Viewport/Overlays/utils.ts +66 -0
  19. package/src/commandsModule.ts +2962 -0
  20. package/src/components/AccordionGroup/AccordionGroup.tsx +195 -0
  21. package/src/components/AccordionGroup/index.ts +4 -0
  22. package/src/components/ActiveViewportWindowLevel/ActiveViewportWindowLevel.tsx +23 -0
  23. package/src/components/ActiveViewportWindowLevel/index.js +1 -0
  24. package/src/components/AdvancedRenderingControls/AdvancedRenderingControls.tsx +149 -0
  25. package/src/components/AdvancedRenderingControls/index.ts +1 -0
  26. package/src/components/CinePlayer/CinePlayer.tsx +247 -0
  27. package/src/components/CinePlayer/index.ts +3 -0
  28. package/src/components/DicomUpload/DicomUpload.tsx +111 -0
  29. package/src/components/DicomUpload/DicomUploadProgress.tsx +396 -0
  30. package/src/components/DicomUpload/DicomUploadProgressItem.tsx +119 -0
  31. package/src/components/ExportSegmentationSubMenuItem.tsx +75 -0
  32. package/src/components/FidelityIndicator/FidelityIndicator.tsx +152 -0
  33. package/src/components/FidelityIndicator/index.ts +1 -0
  34. package/src/components/MeasurementItems.tsx +70 -0
  35. package/src/components/MeasurementTableNested.tsx +30 -0
  36. package/src/components/MeasurementsMenu.tsx +84 -0
  37. package/src/components/MeasurementsOrAdditionalFindings.tsx +82 -0
  38. package/src/components/ModalityLoadBadge/ModalityLoadBadge.tsx +171 -0
  39. package/src/components/ModalityLoadBadge/index.ts +1 -0
  40. package/src/components/NavigationComponent/NavigationComponent.tsx +138 -0
  41. package/src/components/NavigationComponent/index.ts +3 -0
  42. package/src/components/OHIFViewportActionCorners.tsx +109 -0
  43. package/src/components/OpacityMenu/OpacityMenu.tsx +54 -0
  44. package/src/components/OpacityMenu/OpacityMenuWrapper.tsx +85 -0
  45. package/src/components/OpacityMenu/index.ts +2 -0
  46. package/src/components/PanelAccordionTrigger.tsx +48 -0
  47. package/src/components/SegmentationToolConfig.tsx +71 -0
  48. package/src/components/SegmentationUtilityButton.tsx +61 -0
  49. package/src/components/SelectItemWithModality.tsx +29 -0
  50. package/src/components/SeriesMeasurements.tsx +90 -0
  51. package/src/components/SeriesSummaryFromDisplaySet.tsx +21 -0
  52. package/src/components/StudyMeasurements.tsx +88 -0
  53. package/src/components/StudyMeasurementsActions.tsx +75 -0
  54. package/src/components/StudySummaryFromMetadata.test.ts +47 -0
  55. package/src/components/StudySummaryFromMetadata.tsx +31 -0
  56. package/src/components/StudySummaryWithActions.tsx +14 -0
  57. package/src/components/ThresholdMenu/ThresholdMenu.tsx +104 -0
  58. package/src/components/ThresholdMenu/ThresholdMenuWrapper.tsx +85 -0
  59. package/src/components/ThresholdMenu/index.ts +2 -0
  60. package/src/components/TrackingStatus/TrackingStatus.tsx +32 -0
  61. package/src/components/TrackingStatus/index.ts +1 -0
  62. package/src/components/VOIManualControlMenu/VOIManualControlMenu.tsx +190 -0
  63. package/src/components/VOIManualControlMenu/VOIManualControlMenuWrapper.tsx +85 -0
  64. package/src/components/VOIManualControlMenu/index.ts +2 -0
  65. package/src/components/ViewportColorbar/ViewportColorbar.tsx +150 -0
  66. package/src/components/ViewportColorbar/ViewportColorbarsContainer.tsx +125 -0
  67. package/src/components/ViewportColorbar/index.ts +5 -0
  68. package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenu.tsx +538 -0
  69. package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenuWrapper.tsx +91 -0
  70. package/src/components/ViewportDataOverlaySettingMenu/utils.ts +118 -0
  71. package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
  72. package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +29 -0
  73. package/src/components/ViewportWindowLevel/ViewportWindowLevel.tsx +261 -0
  74. package/src/components/ViewportWindowLevel/getViewportVolumeHistogram.ts +72 -0
  75. package/src/components/ViewportWindowLevel/histogramWorker.js +97 -0
  76. package/src/components/ViewportWindowLevel/index.js +1 -0
  77. package/src/components/ViewportWindowLevel/utils.ts +176 -0
  78. package/src/components/WindowLevelActionMenu/Colorbar.tsx +30 -0
  79. package/src/components/WindowLevelActionMenu/Colormap.tsx +121 -0
  80. package/src/components/WindowLevelActionMenu/VolumeLighting.tsx +82 -0
  81. package/src/components/WindowLevelActionMenu/VolumeRenderingOptions.tsx +38 -0
  82. package/src/components/WindowLevelActionMenu/VolumeRenderingPresets.tsx +36 -0
  83. package/src/components/WindowLevelActionMenu/VolumeRenderingPresetsContent.tsx +78 -0
  84. package/src/components/WindowLevelActionMenu/VolumeRenderingQuality.tsx +64 -0
  85. package/src/components/WindowLevelActionMenu/VolumeShade.tsx +47 -0
  86. package/src/components/WindowLevelActionMenu/VolumeShift.tsx +92 -0
  87. package/src/components/WindowLevelActionMenu/WindowLevel.tsx +157 -0
  88. package/src/components/WindowLevelActionMenu/WindowLevelActionMenu.tsx +102 -0
  89. package/src/components/WindowLevelActionMenu/WindowLevelActionMenuWrapper.tsx +131 -0
  90. package/src/components/WindowLevelActionMenu/defaultWindowLevelPresets.ts +23 -0
  91. package/src/components/WindowLevelActionMenu/index.ts +11 -0
  92. package/src/components/WindowLevelActionMenu/windowLevelPresetHotkeys.test.ts +19 -0
  93. package/src/components/index.ts +13 -0
  94. package/src/constants/index.ts +13 -0
  95. package/src/customizations/CustomDropdownMenuContent.tsx +106 -0
  96. package/src/customizations/CustomSegmentStatisticsHeader.tsx +140 -0
  97. package/src/customizations/captureViewportModalCustomization.tsx +175 -0
  98. package/src/customizations/colorbarCustomization.ts +93 -0
  99. package/src/customizations/gpuSettingsPresetCustomization.ts +8 -0
  100. package/src/customizations/layoutSelectorCustomization.ts +104 -0
  101. package/src/customizations/measurementsCustomization.ts +124 -0
  102. package/src/customizations/miscCustomization.ts +22 -0
  103. package/src/customizations/modalityColorMapCustomization.ts +23 -0
  104. package/src/customizations/segmentationHydrationCustomization.ts +16 -0
  105. package/src/customizations/segmentationPanelCustomization.tsx +119 -0
  106. package/src/customizations/segmentationToolbarCustomization.ts +964 -0
  107. package/src/customizations/toolGroupToolsCustomization.ts +204 -0
  108. package/src/customizations/toolbarButtonsCustomization.ts +805 -0
  109. package/src/customizations/viewportClickCommandsCustomization.ts +15 -0
  110. package/src/customizations/viewportDownloadWarningCustomization.tsx +6 -0
  111. package/src/customizations/viewportOverlayCustomization.tsx +46 -0
  112. package/src/customizations/viewportScrollbarCustomization.tsx +27 -0
  113. package/src/customizations/viewportToolsCustomization.ts +33 -0
  114. package/src/customizations/volumeRenderingCustomization.ts +14 -0
  115. package/src/customizations/windowLevelPresetsCustomization.ts +5 -0
  116. package/src/enums.ts +9 -0
  117. package/src/getCustomizationModule.tsx +54 -0
  118. package/src/getHangingProtocolModule.ts +47 -0
  119. package/src/getPanelModule.tsx +128 -0
  120. package/src/getSopClassHandlerModule.js +284 -0
  121. package/src/getToolbarModule.tsx +622 -0
  122. package/src/hooks/index.ts +9 -0
  123. package/src/hooks/useActiveViewportSegmentationRepresentations.ts +14 -0
  124. package/src/hooks/useMeasurementTracking.ts +132 -0
  125. package/src/hooks/useMeasurements.ts +104 -0
  126. package/src/hooks/useSegmentations.ts +147 -0
  127. package/src/hooks/useViewportDisplaySets.ts +284 -0
  128. package/src/hooks/useViewportFidelity.ts +243 -0
  129. package/src/hooks/useViewportHover.ts +77 -0
  130. package/src/hooks/useViewportRendering.tsx +868 -0
  131. package/src/hooks/useViewportSegmentations.ts +245 -0
  132. package/src/hps/fourUp.ts +117 -0
  133. package/src/hps/frameView.ts +1581 -0
  134. package/src/hps/main3D.ts +142 -0
  135. package/src/hps/mpr.ts +197 -0
  136. package/src/hps/mprAnd3DVolumeViewport.ts +124 -0
  137. package/src/hps/only3D.ts +70 -0
  138. package/src/hps/primary3D.ts +142 -0
  139. package/src/hps/primaryAxial.ts +114 -0
  140. package/src/id.js +5 -0
  141. package/src/index.tsx +350 -0
  142. package/src/init.tsx +448 -0
  143. package/src/initCineService.ts +75 -0
  144. package/src/initContextMenu.ts +94 -0
  145. package/src/initCornerstoneTools.js +188 -0
  146. package/src/initDoubleClick.ts +82 -0
  147. package/src/initMeasurementService.ts +576 -0
  148. package/src/initStudyPrefetcherService.ts +33 -0
  149. package/src/initWADOImageLoader.js +56 -0
  150. package/src/panels/PanelMeasurement.tsx +84 -0
  151. package/src/panels/PanelSegmentation.tsx +338 -0
  152. package/src/services/ColorbarService/ColorbarService.ts +242 -0
  153. package/src/services/ColorbarService/index.ts +2 -0
  154. package/src/services/CornerstoneCacheService/CornerstoneCacheService.ts +326 -0
  155. package/src/services/CornerstoneCacheService/index.js +3 -0
  156. package/src/services/SegmentationService/RTSTRUCT/mapROIContoursToRTStructData.ts +36 -0
  157. package/src/services/SegmentationService/SegmentationService.test.ts +3698 -0
  158. package/src/services/SegmentationService/SegmentationService.ts +2376 -0
  159. package/src/services/SegmentationService/backends/ISegmentationBackend.ts +102 -0
  160. package/src/services/SegmentationService/backends/ISegmentationServiceInternals.ts +44 -0
  161. package/src/services/SegmentationService/backends/LegacySegmentationBackend.ts +139 -0
  162. package/src/services/SegmentationService/backends/NextSegmentationBackend.ts +159 -0
  163. package/src/services/SegmentationService/backends/index.ts +4 -0
  164. package/src/services/SegmentationService/index.ts +3 -0
  165. package/src/services/SyncGroupService/SyncGroupService.ts +264 -0
  166. package/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +118 -0
  167. package/src/services/SyncGroupService/index.js +3 -0
  168. package/src/services/ToolGroupService/ToolGroupService.test.ts +83 -0
  169. package/src/services/ToolGroupService/ToolGroupService.ts +541 -0
  170. package/src/services/ToolGroupService/index.js +3 -0
  171. package/src/services/ViewedDataService/ViewedDataService.ts +58 -0
  172. package/src/services/ViewedDataService/index.ts +3 -0
  173. package/src/services/ViewportService/CornerstoneViewportService.ts +1814 -0
  174. package/src/services/ViewportService/IViewportService.ts +64 -0
  175. package/src/services/ViewportService/Viewport.ts +372 -0
  176. package/src/services/ViewportService/adapter/IViewportAdapter.contract.test.ts +467 -0
  177. package/src/services/ViewportService/adapter/IViewportAdapter.ts +179 -0
  178. package/src/services/ViewportService/adapter/LegacyViewportAdapter.ts +240 -0
  179. package/src/services/ViewportService/adapter/NextViewportAdapter.ts +241 -0
  180. package/src/services/ViewportService/adapter/getViewportAdapter.ts +62 -0
  181. package/src/services/ViewportService/adapter/index.ts +16 -0
  182. package/src/services/ViewportService/backends/IViewportBackend.ts +195 -0
  183. package/src/services/ViewportService/backends/IViewportOperations.ts +98 -0
  184. package/src/services/ViewportService/backends/IViewportServiceInternals.ts +47 -0
  185. package/src/services/ViewportService/backends/LegacyViewportBackend.ts +264 -0
  186. package/src/services/ViewportService/backends/LegacyViewportOperations.ts +272 -0
  187. package/src/services/ViewportService/backends/NextViewportBackend.ts +671 -0
  188. package/src/services/ViewportService/backends/NextViewportOperations.ts +169 -0
  189. package/src/services/ViewportService/backends/README.md +62 -0
  190. package/src/services/ViewportService/backends/dataIdRegistry.ts +121 -0
  191. package/src/services/ViewportService/backends/viewportOperations.ts +71 -0
  192. package/src/services/ViewportService/constants.ts +3 -0
  193. package/src/state.ts +34 -0
  194. package/src/stores/index.ts +5 -0
  195. package/src/stores/presentationUtils.ts +42 -0
  196. package/src/stores/useLutPresentationStore.ts +166 -0
  197. package/src/stores/usePositionPresentationStore.ts +172 -0
  198. package/src/stores/useSegmentationPresentationStore.test.ts +146 -0
  199. package/src/stores/useSegmentationPresentationStore.ts +417 -0
  200. package/src/stores/useSelectedSegmentationsForViewportStore.ts +85 -0
  201. package/src/stores/useSynchronizersStore.ts +84 -0
  202. package/src/synchronizers/frameViewSynchronizer.ts +52 -0
  203. package/src/tools/CalibrationLineTool.ts +97 -0
  204. package/src/tools/ImageOverlayViewerTool.tsx +279 -0
  205. package/src/tools/OverlayPlaneModuleProvider.ts +40 -0
  206. package/src/tools/WindowLevelTool.test.ts +55 -0
  207. package/src/tools/WindowLevelTool.ts +22 -0
  208. package/src/types/AppTypes.ts +70 -0
  209. package/src/types/Colorbar.ts +114 -0
  210. package/src/types/Colormap.ts +16 -0
  211. package/src/types/CornerstoneCacheService.ts +40 -0
  212. package/src/types/CornerstoneServices.ts +18 -0
  213. package/src/types/Presentation.ts +83 -0
  214. package/src/types/SelectedSegmentationByTypeMap.ts +3 -0
  215. package/src/types/ViewportPresets.ts +53 -0
  216. package/src/types/VolumeLighting.ts +7 -0
  217. package/src/types/VolumeRenderingConfig.ts +8 -0
  218. package/src/types/WindowLevel.ts +5 -0
  219. package/src/types/index.ts +10 -0
  220. package/src/utils/ActiveViewportBehavior.tsx +80 -0
  221. package/src/utils/CornerstoneViewportDownloadForm.tsx +319 -0
  222. package/src/utils/DicomFileUploader.ts +204 -0
  223. package/src/utils/JumpPresets.ts +14 -0
  224. package/src/utils/autoHydrateViewportTypes.ts +69 -0
  225. package/src/utils/colormaps.js +1597 -0
  226. package/src/utils/createSegmentationForViewport.ts +83 -0
  227. package/src/utils/dicomLoaderService.js +225 -0
  228. package/src/utils/ecgMetadata.test.ts +137 -0
  229. package/src/utils/ecgMetadata.ts +109 -0
  230. package/src/utils/findNearbyToolData.test.ts +125 -0
  231. package/src/utils/findNearbyToolData.ts +21 -0
  232. package/src/utils/generateSegmentationCSVReport.test.ts +324 -0
  233. package/src/utils/generateSegmentationCSVReport.ts +131 -0
  234. package/src/utils/getActiveViewportEnabledElement.test.ts +70 -0
  235. package/src/utils/getActiveViewportEnabledElement.ts +8 -0
  236. package/src/utils/getCenterExtent.test.ts +313 -0
  237. package/src/utils/getCenterExtent.ts +46 -0
  238. package/src/utils/getCornerstoneBlendMode.test.ts +59 -0
  239. package/src/utils/getCornerstoneBlendMode.ts +25 -0
  240. package/src/utils/getCornerstoneOrientation.test.ts +78 -0
  241. package/src/utils/getCornerstoneOrientation.ts +31 -0
  242. package/src/utils/getCornerstoneViewportType.test.ts +169 -0
  243. package/src/utils/getCornerstoneViewportType.ts +88 -0
  244. package/src/utils/getInterleavedFrames.test.ts +85 -0
  245. package/src/utils/getInterleavedFrames.ts +73 -0
  246. package/src/utils/getLegacyViewportType.ts +64 -0
  247. package/src/utils/getNthFrames.test.ts +145 -0
  248. package/src/utils/getNthFrames.ts +31 -0
  249. package/src/utils/getViewportEnabledElement.test.ts +83 -0
  250. package/src/utils/getViewportEnabledElement.ts +8 -0
  251. package/src/utils/getViewportOrientationFromImageOrientationPatient.test.ts +50 -0
  252. package/src/utils/getViewportOrientationFromImageOrientationPatient.ts +56 -0
  253. package/src/utils/hydrationUtils.test.ts +572 -0
  254. package/src/utils/hydrationUtils.ts +197 -0
  255. package/src/utils/imageSliceSync/calculateViewportRegistrations.ts +28 -0
  256. package/src/utils/imageSliceSync/toggleImageSliceSync.ts +101 -0
  257. package/src/utils/index.ts +29 -0
  258. package/src/utils/initGpuSettingsPreset.ts +51 -0
  259. package/src/utils/initViewTiming.test.ts +342 -0
  260. package/src/utils/initViewTiming.ts +52 -0
  261. package/src/utils/initWebWorkerProgressHandler.test.ts +381 -0
  262. package/src/utils/initWebWorkerProgressHandler.ts +110 -0
  263. package/src/utils/interleave.test.ts +304 -0
  264. package/src/utils/interleave.ts +32 -0
  265. package/src/utils/interleaveCenterLoader.test.ts +547 -0
  266. package/src/utils/interleaveCenterLoader.ts +143 -0
  267. package/src/utils/interleaveTopToBottom.test.ts +487 -0
  268. package/src/utils/interleaveTopToBottom.ts +132 -0
  269. package/src/utils/isAnyDisplaySetCommon.ts +18 -0
  270. package/src/utils/isDisplaySetOverlayable.ts +96 -0
  271. package/src/utils/isMeasurementWithinViewport.test.ts +340 -0
  272. package/src/utils/isMeasurementWithinViewport.ts +33 -0
  273. package/src/utils/isReferenceViewable.test.ts +581 -0
  274. package/src/utils/isReferenceViewable.ts +95 -0
  275. package/src/utils/loadDisplaySetData.ts +49 -0
  276. package/src/utils/measurementServiceMappings/Angle.ts +200 -0
  277. package/src/utils/measurementServiceMappings/ArrowAnnotate.ts +176 -0
  278. package/src/utils/measurementServiceMappings/Bidirectional.ts +193 -0
  279. package/src/utils/measurementServiceMappings/CircleROI.ts +227 -0
  280. package/src/utils/measurementServiceMappings/CobbAngle.ts +206 -0
  281. package/src/utils/measurementServiceMappings/EllipticalROI.ts +221 -0
  282. package/src/utils/measurementServiceMappings/Length.ts +206 -0
  283. package/src/utils/measurementServiceMappings/LivewireContour.ts +175 -0
  284. package/src/utils/measurementServiceMappings/PlanarFreehandROI.ts +228 -0
  285. package/src/utils/measurementServiceMappings/Probe.ts +192 -0
  286. package/src/utils/measurementServiceMappings/RectangleROI.ts +225 -0
  287. package/src/utils/measurementServiceMappings/SegmentBidirectional.ts +184 -0
  288. package/src/utils/measurementServiceMappings/SplineROI.ts +227 -0
  289. package/src/utils/measurementServiceMappings/UltrasoundDirectional.ts +214 -0
  290. package/src/utils/measurementServiceMappings/UltrasoundPleuraBLine.ts +179 -0
  291. package/src/utils/measurementServiceMappings/constants/supportedTools.js +21 -0
  292. package/src/utils/measurementServiceMappings/index.ts +3 -0
  293. package/src/utils/measurementServiceMappings/measurementServiceMappingsFactory.ts +324 -0
  294. package/src/utils/measurementServiceMappings/utils/getDisplayUnit.js +3 -0
  295. package/src/utils/measurementServiceMappings/utils/getHandlesFromPoints.js +14 -0
  296. package/src/utils/measurementServiceMappings/utils/getIsLocked.ts +5 -0
  297. package/src/utils/measurementServiceMappings/utils/getIsVisible.ts +6 -0
  298. package/src/utils/measurementServiceMappings/utils/getSOPInstanceAttributes.js +66 -0
  299. package/src/utils/measurementServiceMappings/utils/getValueDisplayString.js +12 -0
  300. package/src/utils/measurementServiceMappings/utils/index.ts +17 -0
  301. package/src/utils/measurementServiceMappings/utils/selection.ts +33 -0
  302. package/src/utils/mpr/getProtocolViewportStructureFromGridViewports.ts +74 -0
  303. package/src/utils/nextViewportPolicies.ts +41 -0
  304. package/src/utils/nextViewports.ts +157 -0
  305. package/src/utils/nthLoader.test.ts +317 -0
  306. package/src/utils/nthLoader.ts +78 -0
  307. package/src/utils/presentations/getViewportPresentations.test.ts +280 -0
  308. package/src/utils/presentations/getViewportPresentations.ts +151 -0
  309. package/src/utils/promptHydrationDialog.test.ts +490 -0
  310. package/src/utils/promptHydrationDialog.ts +197 -0
  311. package/src/utils/removeViewportSegmentationRepresentations.test.ts +129 -0
  312. package/src/utils/removeViewportSegmentationRepresentations.ts +17 -0
  313. package/src/utils/segmentUtils.test.ts +515 -0
  314. package/src/utils/segmentUtils.ts +46 -0
  315. package/src/utils/segmentationExportUtils.test.ts +100 -0
  316. package/src/utils/segmentationExportUtils.ts +171 -0
  317. package/src/utils/segmentationHandlers.test.ts +614 -0
  318. package/src/utils/segmentationHandlers.ts +164 -0
  319. package/src/utils/setUpAnnotationEventHandlers.ts +26 -0
  320. package/src/utils/setUpSegmentationEventHandlers.test.ts +372 -0
  321. package/src/utils/setUpSegmentationEventHandlers.ts +122 -0
  322. package/src/utils/toggleVOISliceSync.test.ts +606 -0
  323. package/src/utils/toggleVOISliceSync.ts +103 -0
  324. package/src/utils/transitions.test.ts +351 -0
  325. package/src/utils/transitions.ts +300 -0
  326. package/src/utils/updateSegmentationStats.test.ts +942 -0
  327. package/src/utils/updateSegmentationStats.ts +192 -0
  328. package/src/utils/viewportDataShape.ts +85 -0
@@ -0,0 +1,942 @@
1
+ import { Types as cstTypes, utilities as cstUtilities } from '@cornerstonejs/tools';
2
+ import {
3
+ updateSegmentationStats,
4
+ updateSegmentBidirectionalStats,
5
+ } from './updateSegmentationStats';
6
+
7
+ jest.mock('@cornerstonejs/tools', () => ({
8
+ utilities: {
9
+ segmentation: {
10
+ getStatistics: jest.fn(),
11
+ },
12
+ },
13
+ }));
14
+
15
+ describe('updateSegmentationStats', () => {
16
+ const mockSegmentation = {
17
+ segments: {
18
+ '1': {
19
+ segmentIndex: 1,
20
+ label: 'Segment 1',
21
+ },
22
+ '2': {
23
+ segmentIndex: 2,
24
+ label: 'Segment 2',
25
+ },
26
+ },
27
+ };
28
+
29
+ const mockReadableText = {
30
+ mean: 'Mean',
31
+ stdDev: 'Standard Deviation',
32
+ volume: 'Volume',
33
+ max: 'Maximum',
34
+ };
35
+
36
+ const mockStats = {
37
+ '1': {
38
+ array: [
39
+ {
40
+ name: 'mean',
41
+ value: 100.5,
42
+ unit: 'HU',
43
+ },
44
+ ],
45
+ } as cstTypes.NamedStatistics,
46
+ };
47
+
48
+ beforeEach(() => {
49
+ jest.clearAllMocks();
50
+ });
51
+
52
+ it('should return null if no segmentation is provided', async () => {
53
+ const result = await updateSegmentationStats({
54
+ segmentation: null,
55
+ segmentationId: 'test-id',
56
+ readableText: mockReadableText,
57
+ });
58
+
59
+ expect(result).toBe(null);
60
+ expect(cstUtilities.segmentation.getStatistics).not.toHaveBeenCalled();
61
+ });
62
+
63
+ it('should return null if segmentation is undefined', async () => {
64
+ const result = await updateSegmentationStats({
65
+ segmentation: undefined,
66
+ segmentationId: 'test-id',
67
+ readableText: mockReadableText,
68
+ });
69
+
70
+ expect(result).toBe(null);
71
+ });
72
+
73
+ it('should return null if no segments found (empty segments)', async () => {
74
+ const segmentationWithEmptySegments = {
75
+ segments: {},
76
+ };
77
+
78
+ const result = await updateSegmentationStats({
79
+ segmentation: segmentationWithEmptySegments,
80
+ segmentationId: 'test-id',
81
+ readableText: mockReadableText,
82
+ });
83
+
84
+ expect(result).toBe(null);
85
+ expect(cstUtilities.segmentation.getStatistics).not.toHaveBeenCalled();
86
+ });
87
+
88
+ it('should return null if no segments found (only segment 0)', async () => {
89
+ const segmentationWithOnlyBackground = {
90
+ segments: {
91
+ '0': {
92
+ segmentIndex: 0,
93
+ label: 'Background',
94
+ },
95
+ },
96
+ };
97
+
98
+ const result = await updateSegmentationStats({
99
+ segmentation: segmentationWithOnlyBackground,
100
+ segmentationId: 'test-id',
101
+ readableText: mockReadableText,
102
+ });
103
+
104
+ expect(result).toBe(null);
105
+ expect(cstUtilities.segmentation.getStatistics).not.toHaveBeenCalled();
106
+ });
107
+
108
+ it('should return null if getStatistics returns null', async () => {
109
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(null);
110
+
111
+ const result = await updateSegmentationStats({
112
+ segmentation: mockSegmentation,
113
+ segmentationId: 'test-id',
114
+ readableText: mockReadableText,
115
+ });
116
+
117
+ expect(cstUtilities.segmentation.getStatistics).toHaveBeenCalledWith({
118
+ segmentationId: 'test-id',
119
+ segmentIndices: [1, 2],
120
+ mode: 'individual',
121
+ });
122
+ expect(result).toBe(null);
123
+ });
124
+
125
+ it('should return null if getStatistics returns undefined', async () => {
126
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(undefined);
127
+
128
+ const result = await updateSegmentationStats({
129
+ segmentation: mockSegmentation,
130
+ segmentationId: 'test-id',
131
+ readableText: mockReadableText,
132
+ });
133
+
134
+ expect(result).toBe(null);
135
+ });
136
+
137
+ it('should initialize cachedStats if not present', async () => {
138
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStats);
139
+
140
+ const segmentationWithoutCachedStats = {
141
+ segments: {
142
+ '1': {
143
+ segmentIndex: 1,
144
+ label: 'Segment 1',
145
+ },
146
+ },
147
+ };
148
+
149
+ const result = await updateSegmentationStats({
150
+ segmentation: segmentationWithoutCachedStats,
151
+ segmentationId: 'test-id',
152
+ readableText: mockReadableText,
153
+ });
154
+
155
+ expect(result.segments['1'].cachedStats).toBeDefined();
156
+ expect(result.segments['1'].cachedStats.namedStats).toBeDefined();
157
+ expect(result.segments['1'].cachedStats.namedStats.mean).toEqual({
158
+ name: mockStats['1'].array[0].name,
159
+ label: mockReadableText.mean,
160
+ value: mockStats['1'].array[0].value,
161
+ unit: mockStats['1'].array[0].unit,
162
+ order: 0,
163
+ });
164
+ });
165
+
166
+ it('should preserve existing cachedStats and add namedStats', async () => {
167
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStats);
168
+
169
+ const segmentationWithExistingCachedStats = {
170
+ segments: {
171
+ '1': {
172
+ segmentIndex: 1,
173
+ label: 'Segment 1',
174
+ cachedStats: {
175
+ existingData: 'test',
176
+ },
177
+ },
178
+ },
179
+ };
180
+
181
+ const result = await updateSegmentationStats({
182
+ segmentation: segmentationWithExistingCachedStats,
183
+ segmentationId: 'test-id',
184
+ readableText: mockReadableText,
185
+ });
186
+
187
+ expect(result.segments['1'].cachedStats.existingData).toBe('test');
188
+ expect(result.segments['1'].cachedStats.namedStats.mean).toEqual({
189
+ name: mockStats['1'].array[0].name,
190
+ label: mockReadableText.mean,
191
+ value: mockStats['1'].array[0].value,
192
+ unit: mockStats['1'].array[0].unit,
193
+ order: 0,
194
+ });
195
+ });
196
+
197
+ it('should preserve existing namedStats and merge with new stats', async () => {
198
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStats);
199
+
200
+ const segmentationWithExistingNamedStats = {
201
+ segments: {
202
+ '1': {
203
+ segmentIndex: 1,
204
+ label: 'Segment 1',
205
+ cachedStats: {
206
+ namedStats: {
207
+ existingStat: {
208
+ name: 'existingStat',
209
+ value: 'existing',
210
+ },
211
+ },
212
+ },
213
+ },
214
+ },
215
+ };
216
+
217
+ const result = await updateSegmentationStats({
218
+ segmentation: segmentationWithExistingNamedStats,
219
+ segmentationId: 'test-id',
220
+ readableText: mockReadableText,
221
+ });
222
+
223
+ expect(result.segments['1'].cachedStats.namedStats.existingStat).toEqual({
224
+ name: 'existingStat',
225
+ value: 'existing',
226
+ });
227
+ expect(result.segments['1'].cachedStats.namedStats.mean).toEqual({
228
+ name: mockStats['1'].array[0].name,
229
+ label: mockReadableText.mean,
230
+ value: mockStats['1'].array[0].value,
231
+ unit: mockStats['1'].array[0].unit,
232
+ order: 0,
233
+ });
234
+ });
235
+
236
+ it('should skip stats not in readableText', async () => {
237
+ const mockStatsWithUnknownStat = {
238
+ '1': {
239
+ array: [
240
+ ...mockStats['1'].array,
241
+ {
242
+ name: 'unknownStat',
243
+ value: 50,
244
+ unit: 'mm',
245
+ },
246
+ ],
247
+ } as cstTypes.NamedStatistics,
248
+ };
249
+
250
+ jest
251
+ .spyOn(cstUtilities.segmentation, 'getStatistics')
252
+ .mockResolvedValue(mockStatsWithUnknownStat);
253
+
254
+ const result = await updateSegmentationStats({
255
+ segmentation: mockSegmentation,
256
+ segmentationId: 'test-id',
257
+ readableText: mockReadableText,
258
+ });
259
+
260
+ expect(result.segments['1'].cachedStats.namedStats.mean).toBeDefined();
261
+ expect(result.segments['1'].cachedStats.namedStats.unknownStat).toBeUndefined();
262
+ });
263
+
264
+ it('should skip stats with invalid name', async () => {
265
+ const mockStatsWithInvalidName = {
266
+ '1': {
267
+ array: [
268
+ ...mockStats['1'].array,
269
+ {
270
+ name: null,
271
+ value: 50,
272
+ unit: 'mm',
273
+ },
274
+ {
275
+ value: 25,
276
+ unit: 'cm',
277
+ },
278
+ ],
279
+ } as cstTypes.NamedStatistics,
280
+ };
281
+
282
+ jest
283
+ .spyOn(cstUtilities.segmentation, 'getStatistics')
284
+ .mockResolvedValue(mockStatsWithInvalidName);
285
+
286
+ const result = await updateSegmentationStats({
287
+ segmentation: mockSegmentation,
288
+ segmentationId: 'test-id',
289
+ readableText: mockReadableText,
290
+ });
291
+
292
+ expect(result.segments['1'].cachedStats.namedStats.mean).toBeDefined();
293
+ expect(Object.keys(result.segments['1'].cachedStats.namedStats)).toHaveLength(1);
294
+ });
295
+
296
+ it('should add volume stat when volume exists in segmentStats and readableText', async () => {
297
+ console.log('mockSegmentation', mockSegmentation);
298
+
299
+ const mockStatsWithVolume = {
300
+ '1': {
301
+ array: [...mockStats['1'].array],
302
+ volume: {
303
+ value: 250.75,
304
+ unit: 'mm³',
305
+ },
306
+ } as cstTypes.NamedStatistics,
307
+ };
308
+
309
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStatsWithVolume);
310
+
311
+ const result = await updateSegmentationStats({
312
+ segmentation: mockSegmentation,
313
+ segmentationId: 'test-id',
314
+ readableText: mockReadableText,
315
+ });
316
+
317
+ expect(result.segments['1'].cachedStats.namedStats.volume).toEqual({
318
+ name: 'volume',
319
+ label: mockReadableText.volume,
320
+ value: mockStatsWithVolume['1'].volume.value,
321
+ unit: mockStatsWithVolume['1'].volume.unit,
322
+ order: 2,
323
+ });
324
+ });
325
+
326
+ it('should not add volume stat when volume not in readableText', async () => {
327
+ console.log('mockSegmentation', mockSegmentation);
328
+
329
+ const mockStatsWithVolume = {
330
+ '1': {
331
+ array: [...mockStats['1'].array],
332
+ volume: {
333
+ value: 250.75,
334
+ unit: 'mm³',
335
+ },
336
+ } as cstTypes.NamedStatistics,
337
+ };
338
+
339
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStatsWithVolume);
340
+
341
+ const readableTextWithoutVolume = {
342
+ mean: 'Mean',
343
+ stdDev: 'Standard Deviation',
344
+ };
345
+
346
+ const result = await updateSegmentationStats({
347
+ segmentation: mockSegmentation,
348
+ segmentationId: 'test-id',
349
+ readableText: readableTextWithoutVolume,
350
+ });
351
+
352
+ expect(result.segments['1'].cachedStats.namedStats.volume).toBeUndefined();
353
+ });
354
+
355
+ it('should not add volume stat when volume already exists in namedStats', async () => {
356
+ const mockStatsWithVolume = {
357
+ '1': {
358
+ array: [
359
+ {
360
+ name: 'volume',
361
+ value: 200.5,
362
+ unit: 'mm³',
363
+ },
364
+ ],
365
+ volume: {
366
+ value: 250.75,
367
+ unit: 'mm³',
368
+ },
369
+ } as cstTypes.NamedStatistics,
370
+ };
371
+
372
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStatsWithVolume);
373
+
374
+ const result = await updateSegmentationStats({
375
+ segmentation: mockSegmentation,
376
+ segmentationId: 'test-id',
377
+ readableText: mockReadableText,
378
+ });
379
+
380
+ expect(result.segments['1'].cachedStats.namedStats.volume).toEqual({
381
+ name: 'volume',
382
+ label: mockReadableText.volume,
383
+ value: mockStatsWithVolume['1'].array[0].value,
384
+ unit: mockStatsWithVolume['1'].volume.unit,
385
+ order: 2,
386
+ });
387
+ });
388
+
389
+ it('should not add volume stat when segmentStats.volume is missing', async () => {
390
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStats);
391
+
392
+ const result = await updateSegmentationStats({
393
+ segmentation: mockSegmentation,
394
+ segmentationId: 'test-id',
395
+ readableText: mockReadableText,
396
+ });
397
+
398
+ expect(result.segments['1'].cachedStats.namedStats.volume).toBeUndefined();
399
+ });
400
+
401
+ it('should handle multiple segments with different stats', async () => {
402
+ const mockStatsWithMax = {
403
+ '1': {
404
+ array: [
405
+ ...mockStats['1'].array,
406
+ {
407
+ name: 'max',
408
+ value: 200,
409
+ unit: 'HU',
410
+ },
411
+ ],
412
+ } as cstTypes.NamedStatistics,
413
+ '2': {
414
+ array: [
415
+ {
416
+ name: 'stdDev',
417
+ value: 15.2,
418
+ unit: 'HU',
419
+ },
420
+ ],
421
+ volume: {
422
+ value: 150.25,
423
+ unit: 'mm³',
424
+ },
425
+ } as cstTypes.NamedStatistics,
426
+ };
427
+
428
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStatsWithMax);
429
+
430
+ const result = await updateSegmentationStats({
431
+ segmentation: mockSegmentation,
432
+ segmentationId: 'test-id',
433
+ readableText: mockReadableText,
434
+ });
435
+
436
+ expect(result.segments['1'].cachedStats.namedStats.mean).toEqual({
437
+ name: mockStatsWithMax['1'].array[0].name,
438
+ label: mockReadableText.mean,
439
+ value: mockStatsWithMax['1'].array[0].value,
440
+ unit: mockStatsWithMax['1'].array[0].unit,
441
+ order: 0,
442
+ });
443
+ expect(result.segments['1'].cachedStats.namedStats.max).toEqual({
444
+ name: mockStatsWithMax['1'].array[1].name,
445
+ label: mockReadableText.max,
446
+ value: mockStatsWithMax['1'].array[1].value,
447
+ unit: mockStatsWithMax['1'].array[1].unit,
448
+ order: 3,
449
+ });
450
+ expect(result.segments['2'].cachedStats.namedStats.stdDev).toEqual({
451
+ name: mockStatsWithMax['2'].array[0].name,
452
+ label: mockReadableText.stdDev,
453
+ value: mockStatsWithMax['2'].array[0].value,
454
+ unit: mockStatsWithMax['2'].array[0].unit,
455
+ order: 1,
456
+ });
457
+ expect(result.segments['2'].cachedStats.namedStats.volume).toEqual({
458
+ name: 'volume',
459
+ label: mockReadableText.volume,
460
+ value: mockStatsWithMax['2'].volume.value,
461
+ unit: mockStatsWithMax['2'].volume.unit,
462
+ order: 2,
463
+ });
464
+ });
465
+
466
+ it('should add empty namedStats when no stats are returned(empty array)', async () => {
467
+ const mockStatsWithEmptyArray = {
468
+ '1': {
469
+ array: [],
470
+ } as cstTypes.NamedStatistics,
471
+ };
472
+
473
+ jest
474
+ .spyOn(cstUtilities.segmentation, 'getStatistics')
475
+ .mockResolvedValue(mockStatsWithEmptyArray);
476
+
477
+ const result = await updateSegmentationStats({
478
+ segmentation: mockSegmentation,
479
+ segmentationId: 'test-id',
480
+ readableText: mockReadableText,
481
+ });
482
+
483
+ expect(result.segments['1'].cachedStats.namedStats).toEqual({});
484
+ });
485
+
486
+ it('should only initialize namedStats when no matching stats are found', async () => {
487
+ const mockStatsWithUnknownStat = {
488
+ '1': {
489
+ array: [
490
+ {
491
+ name: 'unknownStat',
492
+ value: 100,
493
+ unit: 'unit',
494
+ },
495
+ ],
496
+ } as cstTypes.NamedStatistics,
497
+ };
498
+
499
+ jest
500
+ .spyOn(cstUtilities.segmentation, 'getStatistics')
501
+ .mockResolvedValue(mockStatsWithUnknownStat);
502
+
503
+ const result = await updateSegmentationStats({
504
+ segmentation: mockSegmentation,
505
+ segmentationId: 'test-id',
506
+ readableText: mockReadableText,
507
+ });
508
+
509
+ expect(result.segments['1'].cachedStats.namedStats).toEqual({});
510
+ });
511
+
512
+ it('should handle segments without array property by initializing cachedStats', async () => {
513
+ const mockStatsWithNoArray = {
514
+ '1': {} as cstTypes.NamedStatistics,
515
+ };
516
+
517
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStatsWithNoArray);
518
+
519
+ const result = await updateSegmentationStats({
520
+ segmentation: mockSegmentation,
521
+ segmentationId: 'test-id',
522
+ readableText: mockReadableText,
523
+ });
524
+
525
+ expect(result.segments['1'].cachedStats).toEqual({});
526
+ });
527
+
528
+ it('should not update segment if cachedStats is already initialized and no matching stats are found', async () => {
529
+ const mockSegmentationWithCachedStats = {
530
+ segments: {
531
+ '1': {
532
+ segmentIndex: 1,
533
+ label: 'Segment 1',
534
+ cachedStats: {
535
+ namedStats: {
536
+ existingStat: {
537
+ name: 'existing',
538
+ value: 'test',
539
+ },
540
+ },
541
+ },
542
+ },
543
+ },
544
+ };
545
+
546
+ const mockStatsWithNoArray = {
547
+ '1': {} as cstTypes.NamedStatistics,
548
+ };
549
+
550
+ jest.spyOn(cstUtilities.segmentation, 'getStatistics').mockResolvedValue(mockStatsWithNoArray);
551
+
552
+ const result = await updateSegmentationStats({
553
+ segmentation: mockSegmentationWithCachedStats,
554
+ segmentationId: 'test-id',
555
+ readableText: mockReadableText,
556
+ });
557
+
558
+ expect(result).toBe(null);
559
+ });
560
+ });
561
+
562
+ describe('updateSegmentBidirectionalStats', () => {
563
+ const mockSegmentationService = {
564
+ getSegmentation: jest.fn(),
565
+ };
566
+
567
+ const mockAnnotation = {
568
+ annotationUID: 'test-annotation-uid',
569
+ };
570
+
571
+ const mockBidirectionalData = {
572
+ majorAxis: { length: 20.5 },
573
+ minorAxis: { length: 15.3 },
574
+ maxMajor: 20.5,
575
+ maxMinor: 15.3,
576
+ };
577
+
578
+ const defaultParameters = {
579
+ segmentationId: 'test-id',
580
+ segmentIndex: 1,
581
+ bidirectionalData: mockBidirectionalData,
582
+ // @ts-expect-error - only part of the SegmentationService is needed
583
+ segmentationService: mockSegmentationService as AppTypes.SegmentationService,
584
+ annotation: mockAnnotation,
585
+ };
586
+
587
+ beforeEach(() => {
588
+ jest.clearAllMocks();
589
+ });
590
+
591
+ it('should return null when segmentationId is missing', () => {
592
+ const result = updateSegmentBidirectionalStats({
593
+ ...defaultParameters,
594
+ segmentationId: '',
595
+ });
596
+
597
+ expect(result).toBe(null);
598
+ expect(mockSegmentationService.getSegmentation).not.toHaveBeenCalled();
599
+ });
600
+
601
+ it('should return null when segmentationId is null', () => {
602
+ const result = updateSegmentBidirectionalStats({
603
+ ...defaultParameters,
604
+ segmentationId: null,
605
+ });
606
+
607
+ expect(result).toBe(null);
608
+ });
609
+
610
+ it('should return null when segmentIndex is undefined', () => {
611
+ const result = updateSegmentBidirectionalStats({
612
+ ...defaultParameters,
613
+ segmentIndex: undefined,
614
+ });
615
+
616
+ expect(result).toBe(null);
617
+ });
618
+
619
+ it('should return null when bidirectionalData is missing', () => {
620
+ const result = updateSegmentBidirectionalStats({
621
+ ...defaultParameters,
622
+ bidirectionalData: null,
623
+ });
624
+
625
+ expect(result).toBe(null);
626
+ });
627
+
628
+ it('should return null when segmentation is not found', () => {
629
+ mockSegmentationService.getSegmentation.mockReturnValue(null);
630
+
631
+ const result = updateSegmentBidirectionalStats({
632
+ ...defaultParameters,
633
+ });
634
+
635
+ expect(mockSegmentationService.getSegmentation).toHaveBeenCalledWith('test-id');
636
+ expect(result).toBe(null);
637
+ });
638
+
639
+ it('should return null when segment is not found', () => {
640
+ const mockSegmentation = {
641
+ segments: {},
642
+ };
643
+
644
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
645
+
646
+ const result = updateSegmentBidirectionalStats({
647
+ ...defaultParameters,
648
+ });
649
+
650
+ expect(result).toBe(null);
651
+ });
652
+
653
+ it('should return null when majorAxis is missing', () => {
654
+ const mockSegmentation = {
655
+ segments: {
656
+ 1: {
657
+ segmentIndex: 1,
658
+ label: 'Segment 1',
659
+ },
660
+ },
661
+ };
662
+
663
+ const bidirectionalDataWithoutMajorAxis = {
664
+ majorAxis: null,
665
+ minorAxis: { length: 15.3 },
666
+ maxMajor: 20.5,
667
+ maxMinor: 15.3,
668
+ };
669
+
670
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
671
+
672
+ const result = updateSegmentBidirectionalStats({
673
+ ...defaultParameters,
674
+ bidirectionalData: bidirectionalDataWithoutMajorAxis,
675
+ });
676
+
677
+ expect(result).toBe(null);
678
+ });
679
+
680
+ it('should return null when minorAxis is missing', () => {
681
+ const mockSegmentation = {
682
+ segments: {
683
+ 1: {
684
+ segmentIndex: 1,
685
+ label: 'Segment 1',
686
+ },
687
+ },
688
+ };
689
+
690
+ const bidirectionalDataWithoutMinorAxis = {
691
+ majorAxis: { length: 20.5 },
692
+ minorAxis: null,
693
+ maxMajor: 20.5,
694
+ maxMinor: 15.3,
695
+ };
696
+
697
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
698
+
699
+ const result = updateSegmentBidirectionalStats({
700
+ ...defaultParameters,
701
+ bidirectionalData: bidirectionalDataWithoutMinorAxis,
702
+ });
703
+
704
+ expect(result).toBe(null);
705
+ });
706
+
707
+ it('should return null when maxMajor is zero', () => {
708
+ const mockSegmentation = {
709
+ segments: {
710
+ 1: {
711
+ segmentIndex: 1,
712
+ label: 'Segment 1',
713
+ },
714
+ },
715
+ };
716
+
717
+ const bidirectionalDataWithZeroMajor = {
718
+ majorAxis: { length: 20.5 },
719
+ minorAxis: { length: 15.3 },
720
+ maxMajor: 0,
721
+ maxMinor: 15.3,
722
+ };
723
+
724
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
725
+
726
+ const result = updateSegmentBidirectionalStats({
727
+ ...defaultParameters,
728
+ bidirectionalData: bidirectionalDataWithZeroMajor,
729
+ });
730
+
731
+ expect(result).toBe(null);
732
+ });
733
+
734
+ it('should return null when maxMinor is zero', () => {
735
+ const mockSegmentation = {
736
+ segments: {
737
+ 1: {
738
+ segmentIndex: 1,
739
+ label: 'Segment 1',
740
+ },
741
+ },
742
+ };
743
+
744
+ const bidirectionalDataWithZeroMinor = {
745
+ majorAxis: { length: 20.5 },
746
+ minorAxis: { length: 15.3 },
747
+ maxMajor: 20.5,
748
+ maxMinor: 0,
749
+ };
750
+
751
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
752
+
753
+ const result = updateSegmentBidirectionalStats({
754
+ ...defaultParameters,
755
+ bidirectionalData: bidirectionalDataWithZeroMinor,
756
+ });
757
+
758
+ expect(result).toBe(null);
759
+ });
760
+
761
+ it('should return null when maxMajor is negative', () => {
762
+ const mockSegmentation = {
763
+ segments: {
764
+ 1: {
765
+ segmentIndex: 1,
766
+ label: 'Segment 1',
767
+ },
768
+ },
769
+ };
770
+
771
+ const bidirectionalDataWithNegativeMajor = {
772
+ majorAxis: { length: 20.5 },
773
+ minorAxis: { length: 15.3 },
774
+ maxMajor: -5,
775
+ maxMinor: 15.3,
776
+ };
777
+
778
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
779
+
780
+ const result = updateSegmentBidirectionalStats({
781
+ ...defaultParameters,
782
+ bidirectionalData: bidirectionalDataWithNegativeMajor,
783
+ });
784
+
785
+ expect(result).toBe(null);
786
+ });
787
+
788
+ it('should initialize cachedStats when segment has no cachedStats', () => {
789
+ const mockSegmentation = {
790
+ segments: {
791
+ 1: {
792
+ segmentIndex: 1,
793
+ label: 'Segment 1',
794
+ },
795
+ },
796
+ };
797
+
798
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
799
+
800
+ const result = updateSegmentBidirectionalStats({
801
+ ...defaultParameters,
802
+ });
803
+
804
+ expect(result.segments[1].cachedStats).toEqual({
805
+ namedStats: {
806
+ bidirectional: {
807
+ name: 'bidirectional',
808
+ label: 'Bidirectional',
809
+ annotationUID: 'test-annotation-uid',
810
+ value: {
811
+ ...mockBidirectionalData,
812
+ },
813
+ unit: 'mm',
814
+ },
815
+ },
816
+ });
817
+ });
818
+
819
+ it('should initialize namedStats when segment has cachedStats but no namedStats', () => {
820
+ const mockSegmentation = {
821
+ segments: {
822
+ 1: {
823
+ segmentIndex: 1,
824
+ label: 'Segment 1',
825
+ cachedStats: {
826
+ existingData: 'test',
827
+ },
828
+ },
829
+ },
830
+ };
831
+
832
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
833
+
834
+ const result = updateSegmentBidirectionalStats({
835
+ ...defaultParameters,
836
+ });
837
+
838
+ expect(result.segments[1].cachedStats.existingData).toBe('test');
839
+ expect(result.segments[1].cachedStats.namedStats).toEqual({
840
+ bidirectional: {
841
+ name: 'bidirectional',
842
+ label: 'Bidirectional',
843
+ annotationUID: 'test-annotation-uid',
844
+ value: {
845
+ ...mockBidirectionalData,
846
+ },
847
+ unit: 'mm',
848
+ },
849
+ });
850
+ });
851
+
852
+ it('should add bidirectional stats to existing namedStats', () => {
853
+ const mockSegmentation = {
854
+ segments: {
855
+ 1: {
856
+ segmentIndex: 1,
857
+ label: 'Segment 1',
858
+ cachedStats: {
859
+ namedStats: {
860
+ existingStat: {
861
+ name: 'existing',
862
+ value: 'test',
863
+ },
864
+ },
865
+ },
866
+ },
867
+ },
868
+ };
869
+
870
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
871
+
872
+ const result = updateSegmentBidirectionalStats({
873
+ ...defaultParameters,
874
+ });
875
+
876
+ expect(
877
+ (result.segments[1].cachedStats.namedStats as { existingStat: cstTypes.NamedStatistics })
878
+ .existingStat
879
+ ).toEqual({
880
+ name: 'existing',
881
+ value: 'test',
882
+ });
883
+ expect(
884
+ (result.segments[1].cachedStats.namedStats as { bidirectional: cstTypes.NamedStatistics })
885
+ .bidirectional
886
+ ).toEqual({
887
+ name: 'bidirectional',
888
+ label: 'Bidirectional',
889
+ annotationUID: 'test-annotation-uid',
890
+ value: {
891
+ ...mockBidirectionalData,
892
+ },
893
+ unit: 'mm',
894
+ });
895
+ });
896
+
897
+ it('should update bidirectional stats with correct data structure', () => {
898
+ const mockSegmentation = {
899
+ segments: {
900
+ 1: {
901
+ segmentIndex: 1,
902
+ label: 'Segment 1',
903
+ cachedStats: {
904
+ namedStats: {},
905
+ },
906
+ },
907
+ },
908
+ };
909
+
910
+ const customBidirectionalData = {
911
+ majorAxis: { length: 25.7 },
912
+ minorAxis: { length: 18.9 },
913
+ maxMajor: 25.7,
914
+ maxMinor: 18.9,
915
+ };
916
+
917
+ const customAnnotation = {
918
+ annotationUID: 'custom-annotation-uid',
919
+ };
920
+
921
+ mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
922
+
923
+ const result = updateSegmentBidirectionalStats({
924
+ ...defaultParameters,
925
+ bidirectionalData: customBidirectionalData,
926
+ annotation: customAnnotation,
927
+ });
928
+
929
+ expect(
930
+ (result.segments[1].cachedStats.namedStats as { bidirectional: cstTypes.NamedStatistics })
931
+ .bidirectional
932
+ ).toEqual({
933
+ name: 'bidirectional',
934
+ label: 'Bidirectional',
935
+ annotationUID: 'custom-annotation-uid',
936
+ value: {
937
+ ...customBidirectionalData,
938
+ },
939
+ unit: 'mm',
940
+ });
941
+ });
942
+ });