@ohif/extension-default 3.14.0-beta.98 → 3.14.0-beta.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/dist/ohif-extension-default.umd.js +1 -1
  2. package/package.json +9 -6
  3. package/src/Actions/createReportAsync.tsx +45 -0
  4. package/src/Components/DataSourceConfigurationComponent.tsx +142 -0
  5. package/src/Components/DataSourceConfigurationModalComponent.tsx +200 -0
  6. package/src/Components/ItemListComponent.tsx +95 -0
  7. package/src/Components/LineChartViewport/LineChartViewport.tsx +31 -0
  8. package/src/Components/LineChartViewport/index.ts +1 -0
  9. package/src/Components/MoreDropdownMenu.tsx +112 -0
  10. package/src/Components/ProgressDropdownWithService.tsx +101 -0
  11. package/src/Components/SidePanelWithServices.tsx +122 -0
  12. package/src/CustomizableContextMenu/ContextMenuController.tsx +216 -0
  13. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.test.js +29 -0
  14. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.ts +176 -0
  15. package/src/CustomizableContextMenu/index.ts +5 -0
  16. package/src/CustomizableContextMenu/types.ts +126 -0
  17. package/src/DataSourceConfigurationAPI/GoogleCloudDataSourceConfigurationAPI.ts +236 -0
  18. package/src/DicomJSONDataSource/index.js +326 -0
  19. package/src/DicomLocalDataSource/index.js +273 -0
  20. package/src/DicomTagBrowser/DicomTagBrowser.css +49 -0
  21. package/src/DicomTagBrowser/DicomTagBrowser.tsx +454 -0
  22. package/src/DicomTagBrowser/DicomTagTable.tsx +311 -0
  23. package/src/DicomWebDataSource/dcm4cheeReject.js +45 -0
  24. package/src/DicomWebDataSource/exampleInstances.js +280 -0
  25. package/src/DicomWebDataSource/index.ts +808 -0
  26. package/src/DicomWebDataSource/qido.js +215 -0
  27. package/src/DicomWebDataSource/retrieveBulkData.test.ts +35 -0
  28. package/src/DicomWebDataSource/retrieveBulkData.ts +31 -0
  29. package/src/DicomWebDataSource/retrieveRendered.test.ts +147 -0
  30. package/src/DicomWebDataSource/retrieveRendered.ts +141 -0
  31. package/src/DicomWebDataSource/retrieveStudyMetadata.js +108 -0
  32. package/src/DicomWebDataSource/retrieveStudyMetadata.test.js +75 -0
  33. package/src/DicomWebDataSource/retrieveThumbnail.ts +346 -0
  34. package/src/DicomWebDataSource/serviceUrls.test.ts +143 -0
  35. package/src/DicomWebDataSource/utils/StaticWadoClient.ts +272 -0
  36. package/src/DicomWebDataSource/utils/cleanDenaturalizedDataset.ts +78 -0
  37. package/src/DicomWebDataSource/utils/findIndexOfString.ts +47 -0
  38. package/src/DicomWebDataSource/utils/fixBulkDataURI.test.ts +68 -0
  39. package/src/DicomWebDataSource/utils/fixBulkDataURI.ts +78 -0
  40. package/src/DicomWebDataSource/utils/fixMultiValueKeys.ts +12 -0
  41. package/src/DicomWebDataSource/utils/fixMultipart.ts +70 -0
  42. package/src/DicomWebDataSource/utils/getImageId.js +54 -0
  43. package/src/DicomWebDataSource/utils/getWADORSImageId.js +51 -0
  44. package/src/DicomWebDataSource/utils/index.ts +9 -0
  45. package/src/DicomWebDataSource/utils/retrieveMetadataFiltered.js +61 -0
  46. package/src/DicomWebDataSource/wado/retrieveMetadata.js +41 -0
  47. package/src/DicomWebDataSource/wado/retrieveMetadataLoader.js +64 -0
  48. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderAsync.js +159 -0
  49. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderSync.js +58 -0
  50. package/src/DicomWebProxyDataSource/index.ts +90 -0
  51. package/src/MergeDataSource/index.test.ts +212 -0
  52. package/src/MergeDataSource/index.ts +319 -0
  53. package/src/MergeDataSource/types.ts +46 -0
  54. package/src/Panels/DataSourceSelector.tsx +55 -0
  55. package/src/Panels/StudyBrowser/PanelStudyBrowser.tsx +612 -0
  56. package/src/Panels/StudyBrowser/PanelStudyBrowserHeader.tsx +88 -0
  57. package/src/Panels/StudyBrowser/constants/actionIcons.ts +12 -0
  58. package/src/Panels/StudyBrowser/constants/index.ts +4 -0
  59. package/src/Panels/StudyBrowser/constants/viewPresets.ts +16 -0
  60. package/src/Panels/StudyBrowser/resolveThumbnailDetails.test.ts +197 -0
  61. package/src/Panels/StudyBrowser/resolveThumbnailDetails.ts +132 -0
  62. package/src/Panels/StudyBrowser/types/actionIcon.ts +9 -0
  63. package/src/Panels/StudyBrowser/types/index.ts +4 -0
  64. package/src/Panels/StudyBrowser/types/viewPreset.ts +7 -0
  65. package/src/Panels/WrappedPanelStudyBrowser.tsx +61 -0
  66. package/src/Panels/createReportDialogPrompt.tsx +128 -0
  67. package/src/Panels/debounce.js +25 -0
  68. package/src/Panels/getImageSrcFromImageId.js +16 -0
  69. package/src/Panels/getStudiesForPatientByMRN.js +19 -0
  70. package/src/Panels/index.js +5 -0
  71. package/src/Panels/requestDisplaySetCreationForStudy.js +19 -0
  72. package/src/SOPClassHandlers/chartSOPClassHandler.test.ts +81 -0
  73. package/src/SOPClassHandlers/chartSOPClassHandler.ts +127 -0
  74. package/src/Toolbar/ToolBoxWrapper.tsx +64 -0
  75. package/src/Toolbar/ToolButtonListWrapper.tsx +77 -0
  76. package/src/Toolbar/ToolButtonWrapper.tsx +32 -0
  77. package/src/Toolbar/ToolRowWrapper.tsx +41 -0
  78. package/src/Toolbar/Toolbar.tsx +98 -0
  79. package/src/Toolbar/ToolbarDivider.tsx +5 -0
  80. package/src/Toolbar/ToolbarLayoutSelector.tsx +195 -0
  81. package/src/Toolbar/index.ts +7 -0
  82. package/src/ViewerLayout/HeaderPatientInfo/HeaderPatientInfo.tsx +96 -0
  83. package/src/ViewerLayout/HeaderPatientInfo/index.js +3 -0
  84. package/src/ViewerLayout/HeaderUndoRedo.tsx +47 -0
  85. package/src/ViewerLayout/ResizablePanelsHook.tsx +334 -0
  86. package/src/ViewerLayout/ViewerHeader.tsx +124 -0
  87. package/src/ViewerLayout/constants/panels.ts +42 -0
  88. package/src/ViewerLayout/index.tsx +227 -0
  89. package/src/ViewerLayout/useUndoRedoState.ts +75 -0
  90. package/src/__tests__/commandsModuleToggleOneUp.test.ts +147 -0
  91. package/src/commandsModule.ts +970 -0
  92. package/src/customizations/aboutModalCustomization.tsx +42 -0
  93. package/src/customizations/appearanceModalCustomization.tsx +143 -0
  94. package/src/customizations/contextMenuCustomization.ts +25 -0
  95. package/src/customizations/contextMenuUICustomization.ts +5 -0
  96. package/src/customizations/customRoutesCustomization.ts +6 -0
  97. package/src/customizations/dataSourceConfigurationCustomization.ts +19 -0
  98. package/src/customizations/datasourcesCustomization.tsx +14 -0
  99. package/src/customizations/defaultContextMenuCustomization.ts +22 -0
  100. package/src/customizations/hangingProtocolsCustomization.ts +15 -0
  101. package/src/customizations/headerRightSideCustomization.ts +19 -0
  102. package/src/customizations/helloPageCustomization.tsx +14 -0
  103. package/src/customizations/hideHeaderUndoRedoCustomization.ts +22 -0
  104. package/src/customizations/hotkeyBindingsCustomization.ts +5 -0
  105. package/src/customizations/instanceSortingCriteriaCustomization.ts +6 -0
  106. package/src/customizations/labellingFlowCustomization.tsx +5 -0
  107. package/src/customizations/loadingIndicatorProgressCustomization.tsx +5 -0
  108. package/src/customizations/loadingIndicatorTotalPercentCustomization.tsx +5 -0
  109. package/src/customizations/menuContentCustomization.tsx +67 -0
  110. package/src/customizations/metadataContextCustomization.test.ts +22 -0
  111. package/src/customizations/metadataContextCustomization.ts +28 -0
  112. package/src/customizations/metadataDisplaySetCustomization.ts +55 -0
  113. package/src/customizations/missingReferenceDisplaySetHandler.ts +5 -0
  114. package/src/customizations/multimonitorCustomization.ts +63 -0
  115. package/src/customizations/notificationCustomization.ts +29 -0
  116. package/src/customizations/onDropHandlerCustomization.ts +5 -0
  117. package/src/customizations/onboardingCustomization.ts +200 -0
  118. package/src/customizations/overlayItemCustomization.tsx +33 -0
  119. package/src/customizations/progressDropdownCustomization.ts +5 -0
  120. package/src/customizations/progressLoadingBarCustomization.tsx +5 -0
  121. package/src/customizations/reportDialogCustomization.test.ts +701 -0
  122. package/src/customizations/reportDialogCustomization.tsx +661 -0
  123. package/src/customizations/sortingCriteriaCustomization.ts +14 -0
  124. package/src/customizations/studyBrowserCustomization.test.ts +69 -0
  125. package/src/customizations/studyBrowserCustomization.ts +95 -0
  126. package/src/customizations/thumbnailDetailsCustomization.ts +91 -0
  127. package/src/customizations/userPreferencesCustomization.tsx +342 -0
  128. package/src/customizations/workListCustomization.ts +107 -0
  129. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.test.ts +181 -0
  130. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.ts +240 -0
  131. package/src/displaySetSplitting/makeImageSetDisplaySet.ts +276 -0
  132. package/src/displaySetSplitting/stackSopClassUids.ts +60 -0
  133. package/src/displaySetSplitting/urlSplitModules.test.ts +333 -0
  134. package/src/findViewportsByPosition.ts +102 -0
  135. package/src/getCustomizationModule.tsx +109 -0
  136. package/src/getDataSourcesModule.js +44 -0
  137. package/src/getDisplaySetMessages.ts +54 -0
  138. package/src/getDisplaySetsFromUnsupportedSeries.js +63 -0
  139. package/src/getDisplaySetsFromUnsupportedSeries.test.js +14 -0
  140. package/src/getHangingProtocolModule.js +155 -0
  141. package/src/getLayoutTemplateModule.js +28 -0
  142. package/src/getPTImageIdInstanceMetadata.test.ts +102 -0
  143. package/src/getPTImageIdInstanceMetadata.ts +124 -0
  144. package/src/getPanelModule.tsx +29 -0
  145. package/src/getSopClassHandlerModule.js +152 -0
  146. package/src/getSopClassHandlerModule.test.js +78 -0
  147. package/src/getToolbarModule.tsx +63 -0
  148. package/src/getViewportModule.tsx +12 -0
  149. package/src/hangingprotocols/hpCompare.ts +189 -0
  150. package/src/hangingprotocols/hpEcgCustomization.test.ts +104 -0
  151. package/src/hangingprotocols/hpMNGrid.test.ts +120 -0
  152. package/src/hangingprotocols/hpMNGrid.ts +419 -0
  153. package/src/hangingprotocols/hpMammo.ts +202 -0
  154. package/src/hangingprotocols/hpScale.ts +132 -0
  155. package/src/hangingprotocols/index.ts +16 -0
  156. package/src/hangingprotocols/protocolMatchChanges.test.ts +73 -0
  157. package/src/hangingprotocols/utils/isNewestOfModality.ts +19 -0
  158. package/src/hangingprotocols/utils/laterality.ts +9 -0
  159. package/src/hangingprotocols/utils/mammoDisplaySetSelector.ts +214 -0
  160. package/src/hangingprotocols/utils/registerHangingProtocolAttributes.ts +14 -0
  161. package/src/hangingprotocols/utils/seriesSelectors.ts +62 -0
  162. package/src/hangingprotocols/utils/studySelectors.ts +14 -0
  163. package/src/hangingprotocols/utils/viewCode.test.js +25 -0
  164. package/src/hangingprotocols/utils/viewCode.ts +17 -0
  165. package/src/hangingprotocols/utils/viewportOptions.ts +18 -0
  166. package/src/hooks/usePatientInfo.tsx +63 -0
  167. package/src/id.js +5 -0
  168. package/src/index.ts +113 -0
  169. package/src/init.ts +169 -0
  170. package/src/stores/index.ts +7 -0
  171. package/src/stores/useDisplaySetSelectorStore.ts +83 -0
  172. package/src/stores/useHangingProtocolStageIndexStore.ts +76 -0
  173. package/src/stores/useToggleHangingProtocolStore.ts +76 -0
  174. package/src/stores/useToggleOneUpViewportGridStore.ts +19 -0
  175. package/src/stores/useUIStateStore.ts +87 -0
  176. package/src/stores/useViewportGridStore.ts +89 -0
  177. package/src/stores/useViewportsByPositionStore.ts +100 -0
  178. package/src/types/AppTypes.ts +20 -0
  179. package/src/types/commandModuleTypes.tsx +6 -0
  180. package/src/utils/Toolbox.tsx +123 -0
  181. package/src/utils/_shared/PROMPT_RESPONSES.ts +10 -0
  182. package/src/utils/addIcon.ts +6 -0
  183. package/src/utils/appendFrameQueryToImageId.js +9 -0
  184. package/src/utils/callInputDialog.tsx +126 -0
  185. package/src/utils/colorPickerDialog.css +4 -0
  186. package/src/utils/colorPickerDialog.tsx +45 -0
  187. package/src/utils/createRenderedRetrieve.js +32 -0
  188. package/src/utils/createRenderedRetrieve.test.js +46 -0
  189. package/src/utils/dicomWriter.test.ts +228 -0
  190. package/src/utils/dicomWriter.ts +110 -0
  191. package/src/utils/getBulkdataValue.js +45 -0
  192. package/src/utils/getBulkdataValue.test.js +105 -0
  193. package/src/utils/getDirectURL.test.ts +207 -0
  194. package/src/utils/getDirectURL.ts +65 -0
  195. package/src/utils/getSRSeriesAndInstanceNumber.js +48 -0
  196. package/src/utils/index.ts +2 -0
  197. package/src/utils/layerConfigurationUtils.ts +202 -0
  198. package/src/utils/promptLabelAnnotation.js +47 -0
  199. package/src/utils/promptSaveReport.test.ts +106 -0
  200. package/src/utils/promptSaveReport.tsx +117 -0
  201. package/src/utils/registerNaturalizedDatasetForLocalWadouri.js +146 -0
  202. package/src/utils/registerNaturalizedDatasetForLocalWadouri.test.js +177 -0
  203. package/src/utils/registerStoredInstanceImageId.test.ts +73 -0
  204. package/src/utils/registerStoredInstanceImageId.ts +66 -0
  205. package/src/utils/reuseCachedLayouts.ts +92 -0
  206. package/src/utils/secureConfigFetch.js +115 -0
  207. package/src/utils/secureConfigFetch.test.js +163 -0
  208. package/src/utils/seriesDescriptionHistory.ts +83 -0
  209. package/src/utils/validations/areAllImageComponentsEqual.ts +24 -0
  210. package/src/utils/validations/areAllImageDimensionsEqual.test.ts +41 -0
  211. package/src/utils/validations/areAllImageDimensionsEqual.ts +27 -0
  212. package/src/utils/validations/areAllImagePositionsEqual.ts +75 -0
  213. package/src/utils/validations/areAllImageSpacingEqual.ts +66 -0
  214. package/src/utils/validations/checkMultiframe.ts +25 -0
  215. package/src/utils/validations/checkSingleFrames.ts +36 -0
@@ -0,0 +1,107 @@
1
+ import { StudyList } from '@ohif/ui-next';
2
+
3
+ /**
4
+ * Default customization values for the WorkList study-list route.
5
+ *
6
+ * - `workList.variant`: `'default' | 'legacy'` (default: `'default'`)
7
+ * Selects which study-list route is mounted at `/`.
8
+ * - `'default'`: the new ui-next WorkList.
9
+ * - `'legacy'`: the pre-3.13 WorkList (now `LegacyWorkList`). Useful as an
10
+ * opt-out while integrators migrate to the new study list. Deprecated; a
11
+ * future release removes it along with this id.
12
+ *
13
+ * - `workList.previewSeriesView`: `'all' | 'thumbnails' | 'list'` (default: `'all'`)
14
+ * Controls which series views are available in the preview panel.
15
+ * - `'all'`: thumbnails/list toggle is visible; defaults to thumbnails.
16
+ * - `'thumbnails'`: toggle hidden; locked to thumbnails view.
17
+ * - `'list'`: toggle hidden; locked to list view.
18
+ * Note: the preview is forced to `'list'` when the active data source either:
19
+ * - declares `thumbnailRendering` as `'wadors'` or `'thumbnailDirect'`, or
20
+ * - declares `thumbnailRequestStrategy` as `'bulkDataRetrieve'` (default value).
21
+ *
22
+ * - `workList.columns`: `ColumnDef[]` (default: `StudyList.defaultColumns`)
23
+ * The column set for the WorkList table, as a value (not a function). Because
24
+ * it is a plain array, override it with immutability-helper commands:
25
+ * - reorder / insert / remove: `$splice`
26
+ * - relabel / resize / reprioritize (all plain data in `meta`): `$set` / `$merge`
27
+ * - replace a renderer: `$set` a new `cell` / `header` function
28
+ * - `$apply: (cols) => ColumnDef[]`: receive the current columns and return the
29
+ * new array. Use it for anything the other commands don't express cleanly —
30
+ * moves, conditional inserts, or any edit keyed off a column's `id` rather
31
+ * than its position (e.g. `cols.find(c => c.id === 'modalities')`).
32
+ * Use `StudyList.textColumn(id, label, meta?)` to build a simple display-only
33
+ * column without writing the accessor/header/cell wiring.
34
+ *
35
+ * Gotchas / limitations:
36
+ * - A `ColumnDef`'s `accessorFn` / `cell` / `header` / `filterFn` / `sortFn`
37
+ * are functions: `$set`/`$push` accept them, but they are not serializable,
38
+ * so columns that render anything beyond plain text still need code.
39
+ * - The trailing `actions` column should stay last for correct layout (its
40
+ * hover menu is right-aligned to sit at the row end) — this is cosmetic,
41
+ * not a hard requirement. Insert new columns *before* it with `$splice`
42
+ * (a `$push` lands after it, leaving the actions menu mid-row).
43
+ * - Index-based commands (e.g. `{ 2: { meta: { label: { $set: '…' } } } }`)
44
+ * are position-fragile; prefer `$apply` for id-based edits.
45
+ * If the merged value is not an array, WorkList falls back to the defaults.
46
+ *
47
+ * - `workList.renderPreviewContent`: `(React, props) => ReactNode` (default: undefined)
48
+ * Render function for the preview panel content. Receives the host React and
49
+ * `{ study, series, seriesView, onThumbnailImageError }`:
50
+ * - `study`: the selected `StudyRow` (`null` when nothing is selected).
51
+ * - `series`: the study's series; each item has the raw data-source fields
52
+ * (`seriesInstanceUid`, `modality`, `description`, `seriesDate`,
53
+ * `seriesNumber`, `numSeriesInstances`, etc.) plus `thumbnailStatus` added
54
+ * by the shell, which is one of `{ status: 'loading' }`,
55
+ * `{ status: 'ready', src }`, `{ status: 'notAvailable' }`, or
56
+ * `{ status: 'notApplicable' }`. The `src` in the `'ready'` form is the
57
+ * URL to render in an `<img>`.
58
+ * - `seriesView`: `'all' | 'thumbnails' | 'list'`, resolved from
59
+ * `workList.previewSeriesView` with `'list'` forced for data sources that
60
+ * can't produce thumbnails. Honor it if your layout has both views.
61
+ * - `onThumbnailImageError(seriesUID)`: call when an `<img>` you render fails
62
+ * to load. The shell marks that series as `notAvailable` and revokes its
63
+ * blob URL if needed.
64
+ * Use this to change the preview layout while keeping the fetch/abort/thumbnail
65
+ * logic intact. When unset (or not a function), the built-in
66
+ * `<StudyList.PreviewContainer>` layout is used.
67
+ *
68
+ * - `workList.onStudyDoubleClick`: command run input (default:
69
+ * `{ commandName: 'launchDefaultMode' }`)
70
+ * The command(s) run when a study row is double-clicked (the row is selected
71
+ * first). Accepts anything `commandsManager.run` does: a command name string,
72
+ * `{ commandName, commandOptions, context }`, an array of those, or a plain
73
+ * function. At call time these are merged into the command options (a plain
74
+ * function receives them as its single argument):
75
+ * - `study`: the double-clicked `StudyRow`.
76
+ * - `workflows`: the workflows applicable to the study, in the same order as
77
+ * the row's Launch Workflow menu. Each has `id`, `displayName`,
78
+ * `isDefault`, and `launchWithStudy(study)`.
79
+ * - `defaultWorkflow`: the user's default workflow when it applies to the
80
+ * study, else `undefined`.
81
+ * The default `launchDefaultMode` command launches `defaultWorkflow`,
82
+ * falling back to the first applicable workflow. Override the options to
83
+ * always launch a specific mode:
84
+ * `{ commandName: 'launchDefaultMode', commandOptions: { workflowId: 'segmentation' } }`.
85
+ * Modes can contribute their own commands for this via a `getCommandsModule`
86
+ * export on the mode definition, registered at app init in the 'WORKLIST'
87
+ * context — before any mode route is entered. When set to a falsy value the
88
+ * built-in StudyList.Table double-click behavior applies.
89
+ *
90
+ * - `workList.settingsMenuItems`: `(defaults) => SettingsMenuItem[]` (default: identity)
91
+ * Builds the items in the WorkList settings popover. Receives the default
92
+ * items (`about`, `userPreferences`, and `logout` when OIDC is configured)
93
+ * and must return a
94
+ * `SettingsMenuItem[]`. Each item is `{ id, label, onClick }`. Use this to
95
+ * reorder, remove, or insert items without rebuilding the popover shell. If
96
+ * the returned value is not an array, WorkList falls back to the defaults.
97
+ */
98
+ export default function getWorkListCustomization() {
99
+ return {
100
+ 'workList.variant': 'default',
101
+ 'workList.previewSeriesView': 'all',
102
+ 'workList.columns': StudyList.defaultColumns,
103
+ 'workList.renderPreviewContent': undefined,
104
+ 'workList.onStudyDoubleClick': { commandName: 'launchDefaultMode' },
105
+ 'workList.settingsMenuItems': (defaults: unknown) => defaults,
106
+ };
107
+ }
@@ -0,0 +1,181 @@
1
+ import { makeDisplaySetFromInstanceGroup } from './makeDisplaySetFromInstanceGroup';
2
+
3
+ /**
4
+ * A small stand-in for the OHIF ImageSet: the factory under test only sets
5
+ * attributes on it and sorts its images.
6
+ */
7
+ jest.mock('./makeImageSetDisplaySet', () => {
8
+ // More than one slice is reconstructable; the `instance` is the first image.
9
+ const applyImageListAttributes = (imageSet, _context, ruleIsReconstructable?: boolean) => {
10
+ imageSet.isReconstructable = ruleIsReconstructable ?? imageSet.images.length > 1;
11
+ imageSet.instance = imageSet.images[0];
12
+ return {};
13
+ };
14
+ return {
15
+ makeSeriesDisplaySet: instances => {
16
+ const imageSet: Record<string, unknown> = { images: instances, instances };
17
+ imageSet.setAttributes = (attributes: Record<string, unknown>) =>
18
+ Object.assign(imageSet, attributes);
19
+ imageSet.setAttribute = (key: string, value: unknown) => {
20
+ imageSet[key] = value;
21
+ };
22
+ // Records what OHIF's default sort reads, the way `ImageSet.sortInstances`
23
+ // reads `isReconstructable` to choose its order.
24
+ imageSet.sortCalls = [];
25
+ imageSet.sortInstances = list => {
26
+ (imageSet.sortCalls as unknown[]).push(imageSet.isReconstructable);
27
+ return list;
28
+ };
29
+ return imageSet;
30
+ },
31
+ // The real image part applies the image-list attributes.
32
+ applyImageAttributes: (imageSet, _context, options) => {
33
+ imageSet.hasImagePart = true;
34
+ applyImageListAttributes(imageSet, _context, options.isReconstructable);
35
+ },
36
+ applyImageListAttributes,
37
+ applyThumbnailSrc: imageSet => {
38
+ imageSet.thumbnailInstance = imageSet.images[0];
39
+ },
40
+ };
41
+ });
42
+
43
+ const context = {
44
+ servicesManager: { services: { customizationService: {} } },
45
+ extensionManager: {},
46
+ } as never;
47
+
48
+ const instance = { SOPInstanceUID: 'sop-1', SeriesInstanceUID: 'series-1', Modality: 'MG' };
49
+
50
+ const build = (matchedRule: Record<string, unknown>) =>
51
+ makeDisplaySetFromInstanceGroup(
52
+ { instances: [instance], matchedRule, splitKey: '["r","series-1"]' } as never,
53
+ { splitNumber: 0 },
54
+ context
55
+ ) as unknown as Record<string, unknown>;
56
+
57
+ describe('makeDisplaySetFromInstanceGroup', () => {
58
+ describe('splitRuleId and splitGroupId', () => {
59
+ it('records the rule id, and the rule id as the group when the rule names no group', () => {
60
+ const displaySet = build({ id: 'volume3d' });
61
+ expect(displaySet.splitRuleId).toBe('volume3d');
62
+ expect(displaySet.splitGroupId).toBe('volume3d');
63
+ });
64
+
65
+ it('records the group id of the rule, so several rules can share one group', () => {
66
+ const tomo = build({ id: 'mgTomo', groupId: 'mammo' });
67
+ const legacy = build({ id: 'mgLegacy', groupId: 'mammo' });
68
+ expect([tomo.splitRuleId, legacy.splitRuleId]).toEqual(['mgTomo', 'mgLegacy']);
69
+ expect([tomo.splitGroupId, legacy.splitGroupId]).toEqual(['mammo', 'mammo']);
70
+ });
71
+
72
+ it('does not let customAttributes overwrite splitRuleId, splitGroupId or splitKey', () => {
73
+ const displaySet = build({
74
+ id: 'mgTomo',
75
+ groupId: 'mammo',
76
+ customAttributes: () => ({
77
+ splitRuleId: 'other',
78
+ splitGroupId: 'other',
79
+ splitKey: 'other',
80
+ label: 'MG',
81
+ }),
82
+ });
83
+ expect(displaySet.splitRuleId).toBe('mgTomo');
84
+ expect(displaySet.splitGroupId).toBe('mammo');
85
+ expect(displaySet.splitKey).toBe('["r","series-1"]');
86
+ // The other attributes still apply.
87
+ expect(displaySet.label).toBe('MG');
88
+ });
89
+
90
+ it('does not let a __proto__ custom attribute replace the prototype', () => {
91
+ const displaySet = build({
92
+ id: 'proto',
93
+ // JSON.parse makes `__proto__` a real own key.
94
+ customAttributes: () => JSON.parse('{"__proto__": {"x": 1}, "label": "MG"}'),
95
+ });
96
+ expect(Object.getPrototypeOf(displaySet)).toBe(Object.prototype);
97
+ expect(displaySet.x).toBeUndefined();
98
+ expect(displaySet.label).toBe('MG');
99
+ });
100
+ });
101
+
102
+ // SP-PIPE-17: the image part runs for no handler, or the `image` handler.
103
+ it.each([
104
+ [undefined, true],
105
+ ['image', true],
106
+ ['segmentation', false],
107
+ ])('with the handler %s, runs the image part: %s', (handler, hasImagePart) => {
108
+ const displaySet = build({ id: 'r', handler });
109
+ expect(displaySet.handler).toBe(handler);
110
+ expect(!!displaySet.hasImagePart).toBe(hasImagePart);
111
+ });
112
+
113
+ // OHIF refines the CS3D isReconstructable for display; a rule attribute wins.
114
+ it.each([
115
+ ['the OHIF check', undefined, true],
116
+ ['the rule attribute', () => ({ isReconstructable: false }), false],
117
+ ])(
118
+ 'gives an image display set the isReconstructable of %s',
119
+ (_label, customAttributes, expected) => {
120
+ // Two slices with no geometry: CS3D says false, the OHIF check (mocked) says true.
121
+ const displaySet = makeDisplaySetFromInstanceGroup(
122
+ {
123
+ instances: [instance, { ...instance, SOPInstanceUID: 'sop-2' }],
124
+ matchedRule: { id: 'r', customAttributes },
125
+ splitKey: 'k',
126
+ } as never,
127
+ { splitNumber: 0 },
128
+ context
129
+ ) as unknown as Record<string, unknown>;
130
+ expect(displaySet.isReconstructable).toBe(expected);
131
+ }
132
+ );
133
+
134
+ describe('extendInstances', () => {
135
+ const slice = (sop: string, instanceNumber: number) => ({
136
+ ...instance,
137
+ SOPInstanceUID: sop,
138
+ InstanceNumber: instanceNumber,
139
+ });
140
+ // The rule orders by InstanceNumber descending, so the order is visible.
141
+ const descending = {
142
+ id: 'volume3d',
143
+ compareInstances: (a, b) => b.InstanceNumber - a.InstanceNumber,
144
+ };
145
+
146
+ it('sorts a grown display set with the reconstructability of the grown list', () => {
147
+ const displaySet = makeDisplaySetFromInstanceGroup(
148
+ { instances: [slice('sop-1', 1)], matchedRule: descending, splitKey: 'k' } as never,
149
+ { splitNumber: 0 },
150
+ context
151
+ ) as unknown as Record<string, unknown>;
152
+ expect(displaySet.sortCalls).toEqual([false]);
153
+
154
+ (displaySet.extendInstances as (list: unknown[]) => unknown)([
155
+ slice('sop-2', 2),
156
+ slice('sop-3', 3),
157
+ ]);
158
+ // The sort saw a reconstructable display set, the same as a fresh load
159
+ // of all three slices.
160
+ expect(displaySet.sortCalls).toEqual([false, true]);
161
+ });
162
+
163
+ it('applies the order-dependent attributes from the final order', () => {
164
+ const displaySet = makeDisplaySetFromInstanceGroup(
165
+ {
166
+ instances: [slice('sop-1', 1), slice('sop-2', 2)],
167
+ matchedRule: descending,
168
+ splitKey: 'k',
169
+ } as never,
170
+ { splitNumber: 0 },
171
+ context
172
+ ) as unknown as Record<string, { SOPInstanceUID: string }>;
173
+ expect(displaySet.instance.SOPInstanceUID).toBe('sop-2');
174
+ expect(displaySet.thumbnailInstance.SOPInstanceUID).toBe('sop-2');
175
+
176
+ (displaySet.extendInstances as unknown as (list: unknown[]) => unknown)([slice('sop-3', 3)]);
177
+ expect(displaySet.instance.SOPInstanceUID).toBe('sop-3');
178
+ expect(displaySet.thumbnailInstance.SOPInstanceUID).toBe('sop-3');
179
+ });
180
+ });
181
+ });
@@ -0,0 +1,240 @@
1
+ import { createDisplaySetFromGroup, orderInstancesForRule } from '@cornerstonejs/metadata';
2
+ import type {
3
+ GroupInstancesOptions,
4
+ InstanceGroup,
5
+ SeriesFacts,
6
+ SplitRule,
7
+ } from '@cornerstonejs/metadata';
8
+ import {
9
+ applyImageAttributes,
10
+ applyImageListAttributes,
11
+ applyThumbnailSrc,
12
+ makeSeriesDisplaySet,
13
+ type ImageSetFactoryContext,
14
+ } from './makeImageSetDisplaySet';
15
+
16
+ /**
17
+ * The fields of the `@cornerstonejs/metadata` display set that the OHIF
18
+ * display set does not take: the CS3D identity and image id lists, and the
19
+ * fields that define the identity or the content of the OHIF display set.
20
+ * The rule's custom attributes cannot set these either.
21
+ */
22
+ const NOT_COPIED = new Set([
23
+ 'displaySetId',
24
+ 'imageIds',
25
+ 'underlyingImageIds',
26
+ 'instances',
27
+ 'instance',
28
+ 'images',
29
+ 'uid',
30
+ 'displaySetInstanceUID',
31
+ // The growth hook DisplaySetService calls on a re-split.
32
+ 'extendInstances',
33
+ // `imageSet['__proto__'] = value` replaces the prototype of the ImageSet.
34
+ '__proto__',
35
+ ]);
36
+
37
+ /** The ordering inputs every sort of one split-rule display set uses. */
38
+ type InstanceOrder = {
39
+ series?: SeriesFacts;
40
+ compareInstances?: GroupInstancesOptions['compareInstances'];
41
+ };
42
+
43
+ /**
44
+ * Puts a split-rule display set's images in the order the rule asks for.
45
+ *
46
+ * `orderInstancesForRule` composes OHIF's default order (`ImageSet.sortInstances`)
47
+ * with the rule's comparator and the host comparator, with the precedence the
48
+ * split engine uses, so the result is the order the engine computed. The host
49
+ * comparator and the group's series facts must be passed again, or the re-sort
50
+ * discards that order.
51
+ *
52
+ * Sorted in place, because `imageSet.images` is a non-writable property whose
53
+ * contents are mutable.
54
+ */
55
+ function applyInstanceOrder(
56
+ imageSet,
57
+ matchedRule: SplitRule,
58
+ { series, compareInstances }: InstanceOrder,
59
+ context: ImageSetFactoryContext
60
+ ) {
61
+ const { customizationService } = context.servicesManager.services;
62
+ const ordered = orderInstancesForRule(imageSet.images, matchedRule, {
63
+ sortInstances: list => imageSet.sortInstances(list, customizationService),
64
+ compareInstances,
65
+ series,
66
+ });
67
+ imageSet.images.splice(0, imageSet.images.length, ...ordered);
68
+ }
69
+
70
+ /**
71
+ * Orders the images, then refreshes the attributes that depend on the order.
72
+ *
73
+ * OHIF's default sort reads `isReconstructable`, so the image-list attributes
74
+ * must already describe the current images. `instance`, `messages` and the
75
+ * thumbnail depend on the order, so they are applied again from the final
76
+ * order. The initial build and the growth hook both end here, so a display
77
+ * set that grew is the same as one built from all of its instances.
78
+ */
79
+ function orderAndRefreshAttributes(
80
+ imageSet,
81
+ matchedRule: SplitRule,
82
+ order: InstanceOrder,
83
+ context: ImageSetFactoryContext,
84
+ ruleIsReconstructable?: boolean
85
+ ) {
86
+ applyInstanceOrder(imageSet, matchedRule, order, context);
87
+ const derived = applyImageListAttributes(imageSet, context, ruleIsReconstructable);
88
+ applyThumbnailSrc(imageSet, context, derived);
89
+ }
90
+
91
+ /**
92
+ * Step 1: the `@cornerstonejs/metadata` display set of the group, and the
93
+ * `isReconstructable` that the rule's own attributes set, if any. The rule's
94
+ * `customAttributes` runs once, inside `createDisplaySetFromGroup`; the
95
+ * wrapper only reads its result.
96
+ */
97
+ function buildRuleDisplaySet(group: InstanceGroup, splitNumber: number) {
98
+ let ruleIsReconstructable: boolean | undefined;
99
+ const { customAttributes } = group.matchedRule;
100
+ const matchedRule = customAttributes
101
+ ? {
102
+ ...group.matchedRule,
103
+ customAttributes: (attributes, options) => {
104
+ const result = customAttributes(attributes, options);
105
+ if (typeof result?.isReconstructable === 'boolean') {
106
+ ruleIsReconstructable = result.isReconstructable;
107
+ }
108
+ return result;
109
+ },
110
+ }
111
+ : group.matchedRule;
112
+ const ruleDisplaySet = createDisplaySetFromGroup({ ...group, matchedRule }, { splitNumber });
113
+ return { ruleDisplaySet, ruleIsReconstructable };
114
+ }
115
+
116
+ /**
117
+ * Copies the fields of the `@cornerstonejs/metadata` display set onto the OHIF
118
+ * display set: `splitKey`, `splitRuleId`, `splitGroupId`, `sopClassUids`,
119
+ * `handler` and the rule's attributes. Applied after the OHIF
120
+ * defaults, so the rule's attributes win over them.
121
+ *
122
+ * An image display set keeps the OHIF `isReconstructable`: the image part
123
+ * refines the CS3D value for display, and already applied a rule attribute.
124
+ */
125
+ function copyRuleDisplaySet(displaySet, ruleDisplaySet: object, isImage: boolean) {
126
+ for (const [key, value] of Object.entries(ruleDisplaySet)) {
127
+ if (!NOT_COPIED.has(key) && !(isImage && key === 'isReconstructable')) {
128
+ displaySet.setAttribute(key, value);
129
+ }
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Converts a `@cornerstonejs/metadata` split-rule instance group into an OHIF
135
+ * display set. This is the default `createDisplaySetFromGroup` of the
136
+ * `useMetadataDisplaySet` customization.
137
+ *
138
+ * The build has three steps (SP-PIPE-17); this function runs the first two:
139
+ *
140
+ * 1. CS3D `createDisplaySetFromGroup` builds the display set of the group,
141
+ * the same one that a server builds.
142
+ * 2. The OHIF generic step builds an ImageSet with the series identity, and
143
+ * copies the fields of step 1. Its image part (the stack handler id, the
144
+ * image-list attributes, the thumbnail and the instance order) runs only
145
+ * for a rule with no `handler`, or with the `image` handler.
146
+ * 3. DisplaySetService calls the `extendDisplaySet` of the SOP class handler
147
+ * that declares the rule's `handler` name.
148
+ *
149
+ * The `extendInstances` hook repeats steps 1 and 2 for the instances that
150
+ * arrive later. It only adds: a split-rule display set never loses an
151
+ * instance. It is not named `addInstances` (the SOP class handler merge
152
+ * hook), so the legacy handler loop never feeds instances into it.
153
+ */
154
+ export function makeDisplaySetFromInstanceGroup(
155
+ group: InstanceGroup,
156
+ {
157
+ splitNumber,
158
+ compareInstances,
159
+ }: { splitNumber: number; compareInstances?: GroupInstancesOptions['compareInstances'] },
160
+ context: ImageSetFactoryContext
161
+ ) {
162
+ const { matchedRule } = group;
163
+ // What every re-sort of this display set orders with.
164
+ const order: InstanceOrder = { series: group.series, compareInstances };
165
+
166
+ // Step 1. `compileSplitRules` wraps `customAttributes`, so an error here
167
+ // names the rule and the field; DisplaySetService catches it and stops the
168
+ // study.
169
+ const { ruleDisplaySet, ruleIsReconstructable } = buildRuleDisplaySet(group, splitNumber);
170
+ const { handler } = ruleDisplaySet as { handler?: string };
171
+ const isImage = !handler || handler === 'image';
172
+
173
+ // Step 2.
174
+ const displaySet = makeSeriesDisplaySet([...group.instances]);
175
+ if (isImage) {
176
+ // The order is applied below, once, with the matched rule folded in.
177
+ applyImageAttributes(displaySet, context, {
178
+ skipSort: true,
179
+ isReconstructable: ruleIsReconstructable,
180
+ });
181
+ orderAndRefreshAttributes(displaySet, matchedRule, order, context, ruleIsReconstructable);
182
+ }
183
+ copyRuleDisplaySet(displaySet, ruleDisplaySet, isImage);
184
+
185
+ displaySet.setAttribute(
186
+ 'extendInstances',
187
+ (
188
+ newInstances,
189
+ options: {
190
+ series?: SeriesFacts;
191
+ compareInstances?: GroupInstancesOptions['compareInstances'];
192
+ } = {}
193
+ ) => {
194
+ const known = new Set(displaySet.images.map(instance => instance.SOPInstanceUID));
195
+ const instancesToAdd = newInstances.filter(instance => {
196
+ if (known.has(instance.SOPInstanceUID)) {
197
+ return false;
198
+ }
199
+ known.add(instance.SOPInstanceUID);
200
+ return true;
201
+ });
202
+ if (!instancesToAdd.length) {
203
+ return undefined;
204
+ }
205
+ // The series context of the re-split, which saw the whole series
206
+ // including the new instances.
207
+ if (options.series) {
208
+ order.series = options.series;
209
+ }
210
+ if (options.compareInstances) {
211
+ order.compareInstances = options.compareInstances;
212
+ }
213
+
214
+ // `images` is a non-writable property, but the array contents are
215
+ // mutable. A non-image display set keeps the new instances at the end.
216
+ displaySet.images.push(...instancesToAdd);
217
+ // The display set keeps the `splitKey` of the group that created it.
218
+ const grown = buildRuleDisplaySet(
219
+ { ...group, series: order.series, instances: [...displaySet.images] },
220
+ splitNumber
221
+ );
222
+ if (isImage) {
223
+ // The sort reads `isReconstructable`: one slice is not reconstructable,
224
+ // but more slices can be. So the attributes come first for the grown
225
+ // list, then again from the final order.
226
+ applyImageListAttributes(displaySet, context, grown.ruleIsReconstructable);
227
+ orderAndRefreshAttributes(
228
+ displaySet,
229
+ matchedRule,
230
+ order,
231
+ context,
232
+ grown.ruleIsReconstructable
233
+ );
234
+ }
235
+ copyRuleDisplaySet(displaySet, grown.ruleDisplaySet, isImage);
236
+ return displaySet;
237
+ }
238
+ );
239
+ return displaySet;
240
+ }