@ohif/extension-default 3.14.0-beta.10 → 3.14.0-beta.100

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 (216) hide show
  1. package/dist/ohif-extension-default.css +1 -1
  2. package/dist/ohif-extension-default.umd.js +1 -1
  3. package/package.json +14 -10
  4. package/src/Actions/createReportAsync.tsx +45 -0
  5. package/src/Components/DataSourceConfigurationComponent.tsx +142 -0
  6. package/src/Components/DataSourceConfigurationModalComponent.tsx +200 -0
  7. package/src/Components/ItemListComponent.tsx +95 -0
  8. package/src/Components/LineChartViewport/LineChartViewport.tsx +31 -0
  9. package/src/Components/LineChartViewport/index.ts +1 -0
  10. package/src/Components/MoreDropdownMenu.tsx +112 -0
  11. package/src/Components/ProgressDropdownWithService.tsx +101 -0
  12. package/src/Components/SidePanelWithServices.tsx +122 -0
  13. package/src/CustomizableContextMenu/ContextMenuController.tsx +216 -0
  14. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.test.js +29 -0
  15. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.ts +176 -0
  16. package/src/CustomizableContextMenu/index.ts +5 -0
  17. package/src/CustomizableContextMenu/types.ts +126 -0
  18. package/src/DataSourceConfigurationAPI/GoogleCloudDataSourceConfigurationAPI.ts +236 -0
  19. package/src/DicomJSONDataSource/index.js +326 -0
  20. package/src/DicomLocalDataSource/index.js +273 -0
  21. package/src/DicomTagBrowser/DicomTagBrowser.css +49 -0
  22. package/src/DicomTagBrowser/DicomTagBrowser.tsx +454 -0
  23. package/src/DicomTagBrowser/DicomTagTable.tsx +311 -0
  24. package/src/DicomWebDataSource/dcm4cheeReject.js +45 -0
  25. package/src/DicomWebDataSource/exampleInstances.js +280 -0
  26. package/src/DicomWebDataSource/index.ts +808 -0
  27. package/src/DicomWebDataSource/qido.js +215 -0
  28. package/src/DicomWebDataSource/retrieveBulkData.test.ts +35 -0
  29. package/src/DicomWebDataSource/retrieveBulkData.ts +31 -0
  30. package/src/DicomWebDataSource/retrieveRendered.test.ts +147 -0
  31. package/src/DicomWebDataSource/retrieveRendered.ts +141 -0
  32. package/src/DicomWebDataSource/retrieveStudyMetadata.js +108 -0
  33. package/src/DicomWebDataSource/retrieveStudyMetadata.test.js +75 -0
  34. package/src/DicomWebDataSource/retrieveThumbnail.ts +346 -0
  35. package/src/DicomWebDataSource/serviceUrls.test.ts +143 -0
  36. package/src/DicomWebDataSource/utils/StaticWadoClient.ts +272 -0
  37. package/src/DicomWebDataSource/utils/cleanDenaturalizedDataset.ts +78 -0
  38. package/src/DicomWebDataSource/utils/findIndexOfString.ts +47 -0
  39. package/src/DicomWebDataSource/utils/fixBulkDataURI.test.ts +68 -0
  40. package/src/DicomWebDataSource/utils/fixBulkDataURI.ts +78 -0
  41. package/src/DicomWebDataSource/utils/fixMultiValueKeys.ts +12 -0
  42. package/src/DicomWebDataSource/utils/fixMultipart.ts +70 -0
  43. package/src/DicomWebDataSource/utils/getImageId.js +54 -0
  44. package/src/DicomWebDataSource/utils/getWADORSImageId.js +51 -0
  45. package/src/DicomWebDataSource/utils/index.ts +9 -0
  46. package/src/DicomWebDataSource/utils/retrieveMetadataFiltered.js +61 -0
  47. package/src/DicomWebDataSource/wado/retrieveMetadata.js +41 -0
  48. package/src/DicomWebDataSource/wado/retrieveMetadataLoader.js +64 -0
  49. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderAsync.js +159 -0
  50. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderSync.js +58 -0
  51. package/src/DicomWebProxyDataSource/index.ts +90 -0
  52. package/src/MergeDataSource/index.test.ts +212 -0
  53. package/src/MergeDataSource/index.ts +319 -0
  54. package/src/MergeDataSource/types.ts +46 -0
  55. package/src/Panels/DataSourceSelector.tsx +55 -0
  56. package/src/Panels/StudyBrowser/PanelStudyBrowser.tsx +612 -0
  57. package/src/Panels/StudyBrowser/PanelStudyBrowserHeader.tsx +88 -0
  58. package/src/Panels/StudyBrowser/constants/actionIcons.ts +12 -0
  59. package/src/Panels/StudyBrowser/constants/index.ts +4 -0
  60. package/src/Panels/StudyBrowser/constants/viewPresets.ts +16 -0
  61. package/src/Panels/StudyBrowser/resolveThumbnailDetails.test.ts +197 -0
  62. package/src/Panels/StudyBrowser/resolveThumbnailDetails.ts +132 -0
  63. package/src/Panels/StudyBrowser/types/actionIcon.ts +9 -0
  64. package/src/Panels/StudyBrowser/types/index.ts +4 -0
  65. package/src/Panels/StudyBrowser/types/viewPreset.ts +7 -0
  66. package/src/Panels/WrappedPanelStudyBrowser.tsx +61 -0
  67. package/src/Panels/createReportDialogPrompt.tsx +128 -0
  68. package/src/Panels/debounce.js +25 -0
  69. package/src/Panels/getImageSrcFromImageId.js +16 -0
  70. package/src/Panels/getStudiesForPatientByMRN.js +19 -0
  71. package/src/Panels/index.js +5 -0
  72. package/src/Panels/requestDisplaySetCreationForStudy.js +19 -0
  73. package/src/SOPClassHandlers/chartSOPClassHandler.test.ts +81 -0
  74. package/src/SOPClassHandlers/chartSOPClassHandler.ts +127 -0
  75. package/src/Toolbar/ToolBoxWrapper.tsx +64 -0
  76. package/src/Toolbar/ToolButtonListWrapper.tsx +77 -0
  77. package/src/Toolbar/ToolButtonWrapper.tsx +32 -0
  78. package/src/Toolbar/ToolRowWrapper.tsx +41 -0
  79. package/src/Toolbar/Toolbar.tsx +98 -0
  80. package/src/Toolbar/ToolbarDivider.tsx +5 -0
  81. package/src/Toolbar/ToolbarLayoutSelector.tsx +195 -0
  82. package/src/Toolbar/index.ts +7 -0
  83. package/src/ViewerLayout/HeaderPatientInfo/HeaderPatientInfo.tsx +96 -0
  84. package/src/ViewerLayout/HeaderPatientInfo/index.js +3 -0
  85. package/src/ViewerLayout/HeaderUndoRedo.tsx +47 -0
  86. package/src/ViewerLayout/ResizablePanelsHook.tsx +334 -0
  87. package/src/ViewerLayout/ViewerHeader.tsx +124 -0
  88. package/src/ViewerLayout/constants/panels.ts +42 -0
  89. package/src/ViewerLayout/index.tsx +227 -0
  90. package/src/ViewerLayout/useUndoRedoState.ts +75 -0
  91. package/src/__tests__/commandsModuleToggleOneUp.test.ts +147 -0
  92. package/src/commandsModule.ts +970 -0
  93. package/src/customizations/aboutModalCustomization.tsx +42 -0
  94. package/src/customizations/appearanceModalCustomization.tsx +143 -0
  95. package/src/customizations/contextMenuCustomization.ts +25 -0
  96. package/src/customizations/contextMenuUICustomization.ts +5 -0
  97. package/src/customizations/customRoutesCustomization.ts +6 -0
  98. package/src/customizations/dataSourceConfigurationCustomization.ts +19 -0
  99. package/src/customizations/datasourcesCustomization.tsx +14 -0
  100. package/src/customizations/defaultContextMenuCustomization.ts +22 -0
  101. package/src/customizations/hangingProtocolsCustomization.ts +15 -0
  102. package/src/customizations/headerRightSideCustomization.ts +19 -0
  103. package/src/customizations/helloPageCustomization.tsx +14 -0
  104. package/src/customizations/hideHeaderUndoRedoCustomization.ts +22 -0
  105. package/src/customizations/hotkeyBindingsCustomization.ts +5 -0
  106. package/src/customizations/instanceSortingCriteriaCustomization.ts +6 -0
  107. package/src/customizations/labellingFlowCustomization.tsx +5 -0
  108. package/src/customizations/loadingIndicatorProgressCustomization.tsx +5 -0
  109. package/src/customizations/loadingIndicatorTotalPercentCustomization.tsx +5 -0
  110. package/src/customizations/menuContentCustomization.tsx +67 -0
  111. package/src/customizations/metadataContextCustomization.test.ts +22 -0
  112. package/src/customizations/metadataContextCustomization.ts +28 -0
  113. package/src/customizations/metadataDisplaySetCustomization.ts +55 -0
  114. package/src/customizations/missingReferenceDisplaySetHandler.ts +5 -0
  115. package/src/customizations/multimonitorCustomization.ts +63 -0
  116. package/src/customizations/notificationCustomization.ts +29 -0
  117. package/src/customizations/onDropHandlerCustomization.ts +5 -0
  118. package/src/customizations/onboardingCustomization.ts +200 -0
  119. package/src/customizations/overlayItemCustomization.tsx +33 -0
  120. package/src/customizations/progressDropdownCustomization.ts +5 -0
  121. package/src/customizations/progressLoadingBarCustomization.tsx +5 -0
  122. package/src/customizations/reportDialogCustomization.test.ts +701 -0
  123. package/src/customizations/reportDialogCustomization.tsx +661 -0
  124. package/src/customizations/sortingCriteriaCustomization.ts +14 -0
  125. package/src/customizations/studyBrowserCustomization.test.ts +69 -0
  126. package/src/customizations/studyBrowserCustomization.ts +95 -0
  127. package/src/customizations/thumbnailDetailsCustomization.ts +91 -0
  128. package/src/customizations/userPreferencesCustomization.tsx +342 -0
  129. package/src/customizations/workListCustomization.ts +107 -0
  130. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.test.ts +181 -0
  131. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.ts +240 -0
  132. package/src/displaySetSplitting/makeImageSetDisplaySet.ts +276 -0
  133. package/src/displaySetSplitting/stackSopClassUids.ts +60 -0
  134. package/src/displaySetSplitting/urlSplitModules.test.ts +333 -0
  135. package/src/findViewportsByPosition.ts +102 -0
  136. package/src/getCustomizationModule.tsx +109 -0
  137. package/src/getDataSourcesModule.js +44 -0
  138. package/src/getDisplaySetMessages.ts +54 -0
  139. package/src/getDisplaySetsFromUnsupportedSeries.js +63 -0
  140. package/src/getDisplaySetsFromUnsupportedSeries.test.js +14 -0
  141. package/src/getHangingProtocolModule.js +155 -0
  142. package/src/getLayoutTemplateModule.js +28 -0
  143. package/src/getPTImageIdInstanceMetadata.test.ts +102 -0
  144. package/src/getPTImageIdInstanceMetadata.ts +124 -0
  145. package/src/getPanelModule.tsx +29 -0
  146. package/src/getSopClassHandlerModule.js +152 -0
  147. package/src/getSopClassHandlerModule.test.js +78 -0
  148. package/src/getToolbarModule.tsx +63 -0
  149. package/src/getViewportModule.tsx +12 -0
  150. package/src/hangingprotocols/hpCompare.ts +189 -0
  151. package/src/hangingprotocols/hpEcgCustomization.test.ts +104 -0
  152. package/src/hangingprotocols/hpMNGrid.test.ts +120 -0
  153. package/src/hangingprotocols/hpMNGrid.ts +419 -0
  154. package/src/hangingprotocols/hpMammo.ts +202 -0
  155. package/src/hangingprotocols/hpScale.ts +132 -0
  156. package/src/hangingprotocols/index.ts +16 -0
  157. package/src/hangingprotocols/protocolMatchChanges.test.ts +73 -0
  158. package/src/hangingprotocols/utils/isNewestOfModality.ts +19 -0
  159. package/src/hangingprotocols/utils/laterality.ts +9 -0
  160. package/src/hangingprotocols/utils/mammoDisplaySetSelector.ts +214 -0
  161. package/src/hangingprotocols/utils/registerHangingProtocolAttributes.ts +14 -0
  162. package/src/hangingprotocols/utils/seriesSelectors.ts +62 -0
  163. package/src/hangingprotocols/utils/studySelectors.ts +14 -0
  164. package/src/hangingprotocols/utils/viewCode.test.js +25 -0
  165. package/src/hangingprotocols/utils/viewCode.ts +17 -0
  166. package/src/hangingprotocols/utils/viewportOptions.ts +18 -0
  167. package/src/hooks/usePatientInfo.tsx +63 -0
  168. package/src/id.js +5 -0
  169. package/src/index.ts +113 -0
  170. package/src/init.ts +169 -0
  171. package/src/stores/index.ts +7 -0
  172. package/src/stores/useDisplaySetSelectorStore.ts +83 -0
  173. package/src/stores/useHangingProtocolStageIndexStore.ts +76 -0
  174. package/src/stores/useToggleHangingProtocolStore.ts +76 -0
  175. package/src/stores/useToggleOneUpViewportGridStore.ts +19 -0
  176. package/src/stores/useUIStateStore.ts +87 -0
  177. package/src/stores/useViewportGridStore.ts +89 -0
  178. package/src/stores/useViewportsByPositionStore.ts +100 -0
  179. package/src/types/AppTypes.ts +20 -0
  180. package/src/types/commandModuleTypes.tsx +6 -0
  181. package/src/utils/Toolbox.tsx +123 -0
  182. package/src/utils/_shared/PROMPT_RESPONSES.ts +10 -0
  183. package/src/utils/addIcon.ts +6 -0
  184. package/src/utils/appendFrameQueryToImageId.js +9 -0
  185. package/src/utils/callInputDialog.tsx +126 -0
  186. package/src/utils/colorPickerDialog.css +4 -0
  187. package/src/utils/colorPickerDialog.tsx +45 -0
  188. package/src/utils/createRenderedRetrieve.js +32 -0
  189. package/src/utils/createRenderedRetrieve.test.js +46 -0
  190. package/src/utils/dicomWriter.test.ts +228 -0
  191. package/src/utils/dicomWriter.ts +110 -0
  192. package/src/utils/getBulkdataValue.js +45 -0
  193. package/src/utils/getBulkdataValue.test.js +105 -0
  194. package/src/utils/getDirectURL.test.ts +207 -0
  195. package/src/utils/getDirectURL.ts +65 -0
  196. package/src/utils/getSRSeriesAndInstanceNumber.js +48 -0
  197. package/src/utils/index.ts +2 -0
  198. package/src/utils/layerConfigurationUtils.ts +202 -0
  199. package/src/utils/promptLabelAnnotation.js +47 -0
  200. package/src/utils/promptSaveReport.test.ts +106 -0
  201. package/src/utils/promptSaveReport.tsx +117 -0
  202. package/src/utils/registerNaturalizedDatasetForLocalWadouri.js +146 -0
  203. package/src/utils/registerNaturalizedDatasetForLocalWadouri.test.js +177 -0
  204. package/src/utils/registerStoredInstanceImageId.test.ts +73 -0
  205. package/src/utils/registerStoredInstanceImageId.ts +66 -0
  206. package/src/utils/reuseCachedLayouts.ts +92 -0
  207. package/src/utils/secureConfigFetch.js +115 -0
  208. package/src/utils/secureConfigFetch.test.js +163 -0
  209. package/src/utils/seriesDescriptionHistory.ts +83 -0
  210. package/src/utils/validations/areAllImageComponentsEqual.ts +24 -0
  211. package/src/utils/validations/areAllImageDimensionsEqual.test.ts +41 -0
  212. package/src/utils/validations/areAllImageDimensionsEqual.ts +27 -0
  213. package/src/utils/validations/areAllImagePositionsEqual.ts +75 -0
  214. package/src/utils/validations/areAllImageSpacingEqual.ts +66 -0
  215. package/src/utils/validations/checkMultiframe.ts +25 -0
  216. package/src/utils/validations/checkSingleFrames.ts +36 -0
@@ -0,0 +1,69 @@
1
+ import studyBrowserCustomization from './studyBrowserCustomization';
2
+
3
+ const sortFunction = label =>
4
+ studyBrowserCustomization['studyBrowser.sortFunctions'].find(sort => sort.label === label)
5
+ .sortFunction;
6
+
7
+ describe('studyBrowser.sortFunctions', () => {
8
+ it('sorts by series number lowest first, so that ascending means lowest first', () => {
9
+ const series = [{ SeriesNumber: 3 }, { SeriesNumber: 1 }, { SeriesNumber: 2 }];
10
+ expect(series.sort(sortFunction('Series Number')).map(ds => ds.SeriesNumber)).toEqual([
11
+ 1, 2, 3,
12
+ ]);
13
+ });
14
+
15
+ it('sorts by series date oldest first, so that ascending means oldest first', () => {
16
+ const series = [
17
+ { SeriesDate: '20260103' },
18
+ { SeriesDate: '20260101' },
19
+ { SeriesDate: '20260102' },
20
+ ];
21
+ expect(series.sort(sortFunction('Series Date')).map(ds => ds.SeriesDate)).toEqual([
22
+ '20260101',
23
+ '20260102',
24
+ '20260103',
25
+ ]);
26
+ });
27
+
28
+ it('sorts a series with no number before the numbered ones, whatever order they come in', () => {
29
+ const one = { SeriesNumber: 1 };
30
+ const two = { SeriesNumber: 2 };
31
+ const none = { SeriesNumber: '' };
32
+ for (const input of [
33
+ [two, none, one],
34
+ [one, two, none],
35
+ [none, one, two],
36
+ ]) {
37
+ expect([...input].sort(sortFunction('Series Number'))).toEqual([none, one, two]);
38
+ }
39
+ });
40
+
41
+ it('sorts a series with no date before the dated ones, whatever order they come in', () => {
42
+ const dated = { SeriesDate: '20260102' };
43
+ const undated = {};
44
+ const older = { SeriesDate: '20260101' };
45
+ for (const input of [
46
+ [dated, undated, older],
47
+ [older, dated, undated],
48
+ [undated, older, dated],
49
+ ]) {
50
+ expect([...input].sort(sortFunction('Series Date'))).toEqual([undated, older, dated]);
51
+ }
52
+ });
53
+
54
+ it('orders series of the same date by series time', () => {
55
+ const morning = { SeriesDate: '20260101', SeriesTime: '090000' };
56
+ const noon = { SeriesDate: '20260101', SeriesTime: '120000' };
57
+ expect(sortFunction('Series Date')(noon, morning)).toBeGreaterThan(0);
58
+ });
59
+
60
+ it('reports a tie for the same series number or date and time, so the default order breaks it', () => {
61
+ expect(sortFunction('Series Number')({ SeriesNumber: 4 }, { SeriesNumber: '4' })).toBe(0);
62
+ expect(
63
+ sortFunction('Series Date')(
64
+ { SeriesDate: '20260101', SeriesTime: '090000' },
65
+ { SeriesDate: '20260101', SeriesTime: '090000' }
66
+ )
67
+ ).toBe(0);
68
+ });
69
+ });
@@ -0,0 +1,95 @@
1
+ import { utils } from '@ohif/core';
2
+ import i18n from '@ohif/i18n';
3
+ const { getDateTimeSortKey } = utils;
4
+
5
+ /**
6
+ * Orders by the given key, lowest first, and returns 0 when the keys are
7
+ * equal, so that the study browser breaks the tie with its default order.
8
+ */
9
+ const byKey = keyOf => (a, b) => {
10
+ const keyA = keyOf(a);
11
+ const keyB = keyOf(b);
12
+ return keyA === keyB ? 0 : keyA < keyB ? -1 : 1;
13
+ };
14
+
15
+ // A series with no number or no date sorts first.
16
+ const seriesNumberKey = displaySet => {
17
+ const value = displaySet?.SeriesNumber;
18
+ const seriesNumber = value === '' || value === null ? NaN : Number(value);
19
+ return Number.isFinite(seriesNumber) ? seriesNumber : -Infinity;
20
+ };
21
+ const seriesDateTimeKey = displaySet =>
22
+ getDateTimeSortKey(displaySet?.SeriesDate, displaySet?.SeriesTime);
23
+
24
+ export default {
25
+ 'studyBrowser.studyMenuItems': [],
26
+ 'studyBrowser.thumbnailMenuItems': [
27
+ {
28
+ id: 'tagBrowser',
29
+ label: i18n.t('StudyBrowser:Tag Browser'),
30
+ iconName: 'DicomTagBrowser',
31
+ commands: 'openDICOMTagViewer',
32
+ },
33
+ {
34
+ id: 'addAsLayer',
35
+ label: i18n.t('StudyBrowser:Add as Layer'),
36
+ iconName: 'ViewportViews',
37
+ commands: 'addDisplaySetAsLayer',
38
+ },
39
+ ],
40
+ 'studyBrowser.sortFunctions': [
41
+ {
42
+ label: i18n.t('StudyBrowser:Series Number'),
43
+ sortFunction: byKey(seriesNumberKey),
44
+ },
45
+ {
46
+ label: i18n.t('StudyBrowser:Series Date'),
47
+ sortFunction: byKey(seriesDateTimeKey),
48
+ },
49
+ ],
50
+ 'studyBrowser.viewPresets': [
51
+ {
52
+ id: 'list',
53
+ iconName: 'ListView',
54
+ selected: false,
55
+ },
56
+ {
57
+ id: 'thumbnails',
58
+ iconName: 'ThumbnailView',
59
+ selected: true,
60
+ },
61
+ ],
62
+ 'studyBrowser.studyMode': 'all',
63
+ 'studyBrowser.thumbnailDoubleClickCallback': {
64
+ callbacks: [
65
+ ({ activeViewportId, servicesManager, commandsManager, isHangingProtocolLayout }) =>
66
+ async displaySetInstanceUID => {
67
+ const { hangingProtocolService, uiNotificationService } = servicesManager.services;
68
+ let updatedViewports = [];
69
+ const viewportId = activeViewportId;
70
+
71
+ try {
72
+ updatedViewports = hangingProtocolService.getViewportsRequireUpdate(
73
+ viewportId,
74
+ displaySetInstanceUID,
75
+ isHangingProtocolLayout
76
+ );
77
+ } catch (error) {
78
+ console.warn(error);
79
+ uiNotificationService.show({
80
+ title: i18n.t('StudyBrowser:Thumbnail Double Click'),
81
+ message: i18n.t(
82
+ 'StudyBrowser:The selected display sets could not be added to the viewport.'
83
+ ),
84
+ type: 'error',
85
+ duration: 3000,
86
+ });
87
+ }
88
+
89
+ commandsManager.run('setDisplaySetsForViewports', {
90
+ viewportsToUpdate: updatedViewports,
91
+ });
92
+ },
93
+ ],
94
+ },
95
+ };
@@ -0,0 +1,91 @@
1
+ import { utils } from '@ohif/core';
2
+
3
+ const { getLatestInstanceDateTime } = utils;
4
+
5
+ /**
6
+ * Named sources for the study browser thumbnail detail items, so an item can
7
+ * say where to get its value from without supplying a function - which is what
8
+ * lets the whole thing be declared as data in a `?customization=` JSONC file.
9
+ *
10
+ * An item may name one of these as `source`, or supply its own `contentF`.
11
+ *
12
+ * Add to this with `$merge`: a `$set` replaces the registry, which takes away
13
+ * the sources the default items name.
14
+ */
15
+ export const thumbnailDetailSources = {
16
+ seriesNumber: ({ displaySet }) => displaySet?.SeriesNumber,
17
+
18
+ numInstances: ({ displaySet }) =>
19
+ (displaySet?.numImageFrames ?? displaySet?.instances?.length) || 1,
20
+
21
+ seriesDate: ({ displaySet, formatters }) => formatters.formatDate(displaySet?.SeriesDate),
22
+
23
+ /**
24
+ * When the display set was created, which is the date/time the series list is
25
+ * sorted by - see `getLatestInstanceDateTime`. Without this on the thumbnail, several
26
+ * reports or segmentations saved on the same day all read as the same date and
27
+ * their order looks arbitrary.
28
+ *
29
+ * Nothing below minutes is shown: the second a report was written says nothing
30
+ * a reader can use, and it is not reliably recorded either.
31
+ */
32
+ instanceDateTime: ({ displaySet, instance, formatters }) => {
33
+ const { SeriesDate, SeriesTime } = getLatestInstanceDateTime(instance ?? displaySet);
34
+ if (!SeriesDate) {
35
+ return '';
36
+ }
37
+ const date = formatters.formatDate(SeriesDate);
38
+ return SeriesTime ? `${date} ${formatters.formatTime(SeriesTime, 'HH:mm')}` : date;
39
+ },
40
+ };
41
+
42
+ /**
43
+ * Named tests for the study browser thumbnail detail items, so an item can say
44
+ * whether to include itself without supplying a function.
45
+ *
46
+ * An item may name one of these as `condition`, or supply its own function.
47
+ */
48
+ export const thumbnailDetailTests = {
49
+ /** SR, SEG, RTSTRUCT, PMAP and the other derived display sets. */
50
+ isDerivedDisplaySet: ({ displaySet }) => !!displaySet?.isDerivedDisplaySet,
51
+ };
52
+
53
+ export default {
54
+ 'studyBrowser.thumbnailDetailSources': thumbnailDetailSources,
55
+ 'studyBrowser.thumbnailDetailTests': thumbnailDetailTests,
56
+
57
+ /**
58
+ * The items shown on the detail line of a study browser thumbnail, under the
59
+ * modality and series description. Declared the same way as the viewport
60
+ * overlay items (`viewportOverlay.topLeft` and friends):
61
+ *
62
+ * - `id` names the item, and is what an override replaces or removes.
63
+ * - `condition` decides whether to include it, either as a function of
64
+ * `{ displaySet, instance, formatters }` or the name of a
65
+ * `studyBrowser.thumbnailDetailTests` entry. Omitted means always.
66
+ * - the value comes from `contentF` (a function of the same properties),
67
+ * `source` (the name of a `studyBrowser.thumbnailDetailSources` entry) or
68
+ * `attribute` (an attribute of the instance the display set shows). An item
69
+ * with no value, or naming a source or test that is not registered, is left
70
+ * out; if that leaves no items at all the thumbnail keeps its default detail
71
+ * line rather than showing an empty one.
72
+ * - `label` prefixes the value, `title` is its tooltip, and `iconName` puts an
73
+ * icon before it - a name, or a function returning one.
74
+ *
75
+ * The default is the series number and the instance count, as the thumbnails
76
+ * have always shown. `platform/app/public/customizations/studyBrowser/
77
+ * derivedDateTime.jsonc` is an example of adding to it.
78
+ */
79
+ 'studyBrowser.thumbnailDetails': [
80
+ {
81
+ id: 'SeriesNumber',
82
+ label: 'S:',
83
+ source: 'seriesNumber',
84
+ },
85
+ {
86
+ id: 'InstanceCount',
87
+ source: 'numInstances',
88
+ iconName: ({ displaySet }) => displaySet?.countIcon || 'InfoSeries',
89
+ },
90
+ ],
91
+ };
@@ -0,0 +1,342 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { useSystem, hotkeys as hotkeysModule } from '@ohif/core';
3
+ import { UserPreferencesModal, FooterAction } from '@ohif/ui-next';
4
+ import { useTranslation } from 'react-i18next';
5
+ import i18n from '@ohif/i18n';
6
+
7
+ import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@ohif/ui-next';
8
+
9
+ const { availableLanguages, defaultLanguage, currentLanguage: currentLanguageFn } = i18n;
10
+
11
+ interface HotkeyDefinition {
12
+ keys: string;
13
+ label: string;
14
+ }
15
+
16
+ interface HotkeyDefinitions {
17
+ [key: string]: HotkeyDefinition;
18
+ }
19
+
20
+ const MODIFIER_OPTIONS = [
21
+ { value: '16', label: 'Shift' },
22
+ { value: '17', label: 'Ctrl' },
23
+ { value: '18', label: 'Alt' },
24
+ { value: '91', label: 'Meta' },
25
+ ];
26
+
27
+ const DEFAULT_TOOL_BINDINGS_STORAGE_KEY = 'user-preferred-tool-bindings';
28
+
29
+ function getToolModifier(
30
+ toolGroupService: any,
31
+ toolGroupId: string,
32
+ toolName: string,
33
+ mouseButton: number
34
+ ): string | null {
35
+ if (!toolGroupService) {
36
+ return null;
37
+ }
38
+ const bindings = toolGroupService.getToolBindings(toolGroupId, toolName);
39
+ if (!bindings?.length) {
40
+ return null;
41
+ }
42
+ const modifierBinding = bindings.find(
43
+ binding =>
44
+ binding.mouseButton === mouseButton &&
45
+ binding.modifierKey != null &&
46
+ binding.numTouchPoints == null
47
+ );
48
+
49
+ return modifierBinding?.modifierKey != null ? String(modifierBinding.modifierKey) : null;
50
+ }
51
+
52
+ function getModifierFromBindings(
53
+ bindings: Array<Record<string, unknown>> | undefined,
54
+ mouseButton: number
55
+ ): string | null {
56
+ if (!bindings?.length) {
57
+ return null;
58
+ }
59
+
60
+ const modifierBinding = bindings.find(
61
+ binding =>
62
+ binding.mouseButton === mouseButton &&
63
+ binding.modifierKey != null &&
64
+ binding.numTouchPoints == null
65
+ );
66
+
67
+ return modifierBinding?.modifierKey != null ? String(modifierBinding.modifierKey) : null;
68
+ }
69
+
70
+ /**
71
+ * Resolves a localized language name, or null when Intl cannot produce one that
72
+ * differs from the raw locale code.
73
+ *
74
+ * Module scope on purpose: the conditional inside this try/catch is a React
75
+ * Compiler limitation ("value blocks within a try/catch") that bails the whole
76
+ * component when inlined. Plain functions are never compiled.
77
+ */
78
+ function resolveLocalizedLanguageName(
79
+ displayNames: Intl.DisplayNames,
80
+ languageValue: string
81
+ ): string | null {
82
+ try {
83
+ const localized = displayNames.of(languageValue);
84
+ if (localized && localized.toLowerCase() !== languageValue.toLowerCase()) {
85
+ return localized.charAt(0).toUpperCase() + localized.slice(1);
86
+ }
87
+ } catch (error) {
88
+ console.debug(`Unable to resolve display name for ${languageValue}`, error);
89
+ }
90
+
91
+ return null;
92
+ }
93
+
94
+ function UserPreferencesModalDefault({ hide }: { hide: () => void }) {
95
+ const { hotkeysManager, servicesManager } = useSystem();
96
+ const { t, i18n: i18nextInstance } = useTranslation('UserPreferencesModal');
97
+ const toolGroupService = (servicesManager as any)?.services?.toolGroupService;
98
+
99
+ const { hotkeyDefinitions = {}, hotkeyDefaults = {} } = hotkeysManager;
100
+
101
+ const fallbackHotkeyDefinitions = hotkeysManager.getValidHotkeyDefinitions(
102
+ hotkeysModule.defaults.hotkeyBindings
103
+ ) as HotkeyDefinitions;
104
+
105
+ useEffect(() => {
106
+ if (!Object.keys(hotkeyDefaults).length) {
107
+ hotkeysManager.setDefaultHotKeys(hotkeysModule.defaults.hotkeyBindings);
108
+ }
109
+
110
+ if (!Object.keys(hotkeyDefinitions).length) {
111
+ hotkeysManager.setHotkeys(fallbackHotkeyDefinitions);
112
+ }
113
+ }, [hotkeysManager, hotkeyDefaults, hotkeyDefinitions, fallbackHotkeyDefinitions]);
114
+
115
+ const resolvedHotkeyDefaults = Object.keys(hotkeyDefaults).length
116
+ ? (hotkeyDefaults as HotkeyDefinitions)
117
+ : fallbackHotkeyDefinitions;
118
+
119
+ const initialHotkeyDefinitions = Object.keys(hotkeyDefinitions).length
120
+ ? (hotkeyDefinitions as HotkeyDefinitions)
121
+ : resolvedHotkeyDefaults;
122
+
123
+ const currentLanguage = currentLanguageFn();
124
+
125
+ const initialCrosshairModifier = getToolModifier(toolGroupService, 'mpr', 'Crosshairs', 1);
126
+ const defaultCrosshairBindings = toolGroupService?.getDefaultToolBindings?.(
127
+ 'mpr',
128
+ 'Crosshairs'
129
+ );
130
+
131
+ const [state, setState] = useState({
132
+ hotkeyDefinitions: initialHotkeyDefinitions,
133
+ languageValue: currentLanguage.value,
134
+ crosshairModifier: initialCrosshairModifier,
135
+ });
136
+
137
+ const onLanguageChangeHandler = (value: string) => {
138
+ setState(state => ({ ...state, languageValue: value }));
139
+ };
140
+
141
+ const onHotkeyChangeHandler = (id: string, newKeys: string) => {
142
+ setState(state => ({
143
+ ...state,
144
+ hotkeyDefinitions: {
145
+ ...state.hotkeyDefinitions,
146
+ [id]: {
147
+ ...state.hotkeyDefinitions[id],
148
+ keys: newKeys,
149
+ },
150
+ },
151
+ }));
152
+ };
153
+
154
+ const onResetHandler = () => {
155
+ setState(state => ({
156
+ ...state,
157
+ languageValue: defaultLanguage.value,
158
+ hotkeyDefinitions: resolvedHotkeyDefaults,
159
+ crosshairModifier: getModifierFromBindings(defaultCrosshairBindings, 1),
160
+ }));
161
+
162
+ hotkeysManager.restoreDefaultBindings();
163
+ if (toolGroupService && defaultCrosshairBindings?.length) {
164
+ toolGroupService.setToolBindings('mpr', 'Crosshairs', defaultCrosshairBindings);
165
+ toolGroupService.applyToolBindings('mpr', 'Crosshairs', {
166
+ replaceExisting: true,
167
+ });
168
+ }
169
+ toolGroupService?.removePersistedToolBindings('mpr', 'Crosshairs');
170
+ };
171
+
172
+ const displayNames = React.useMemo(() => {
173
+ if (typeof Intl === 'undefined' || typeof Intl.DisplayNames !== 'function') {
174
+ return null;
175
+ }
176
+
177
+ const locales = [state.languageValue, currentLanguage.value, i18nextInstance.language, 'en'];
178
+ const uniqueLocales = Array.from(new Set(locales.filter(Boolean)));
179
+
180
+ try {
181
+ return new Intl.DisplayNames(uniqueLocales, { type: 'language', fallback: 'none' });
182
+ } catch (error) {
183
+ console.warn('Intl.DisplayNames not supported for locales', uniqueLocales, error);
184
+ }
185
+
186
+ return null;
187
+ }, [state.languageValue, currentLanguage.value, i18nextInstance.language]);
188
+
189
+ const getLanguageLabel = React.useCallback(
190
+ (languageValue: string, fallbackLabel: string) => {
191
+ const translationKey = `LanguageName.${languageValue}`;
192
+ if (i18nextInstance.exists(translationKey, { ns: 'UserPreferencesModal' })) {
193
+ return t(translationKey);
194
+ }
195
+
196
+ if (displayNames) {
197
+ const localized = resolveLocalizedLanguageName(displayNames, languageValue);
198
+ if (localized) {
199
+ return localized;
200
+ }
201
+ }
202
+
203
+ return fallbackLabel;
204
+ },
205
+ [displayNames, i18nextInstance, t]
206
+ );
207
+
208
+ return (
209
+ <UserPreferencesModal>
210
+ <UserPreferencesModal.Body>
211
+ {/* Language Section */}
212
+ <div className="mb-3 flex items-center space-x-14">
213
+ <UserPreferencesModal.SubHeading>{t('Language')}</UserPreferencesModal.SubHeading>
214
+ <Select
215
+ defaultValue={state.languageValue}
216
+ onValueChange={onLanguageChangeHandler}
217
+ >
218
+ <SelectTrigger
219
+ className="w-60"
220
+ aria-label="Language"
221
+ >
222
+ <SelectValue placeholder={t('Select language')} />
223
+ </SelectTrigger>
224
+ <SelectContent>
225
+ {availableLanguages.map(lang => (
226
+ <SelectItem
227
+ key={lang.value}
228
+ value={lang.value}
229
+ >
230
+ {getLanguageLabel(lang.value, lang.label)}
231
+ </SelectItem>
232
+ ))}
233
+ </SelectContent>
234
+ </Select>
235
+ </div>
236
+
237
+ <UserPreferencesModal.SubHeading>{t('Hotkeys')}</UserPreferencesModal.SubHeading>
238
+ <UserPreferencesModal.HotkeysGrid>
239
+ {Object.entries(state.hotkeyDefinitions).map(([id, definition]) => (
240
+ <UserPreferencesModal.Hotkey
241
+ key={id}
242
+ label={t(definition.label)}
243
+ value={definition.keys}
244
+ onChange={newKeys => onHotkeyChangeHandler(id, newKeys)}
245
+ placeholder={definition.keys}
246
+ hotkeys={hotkeysModule}
247
+ />
248
+ ))}
249
+ </UserPreferencesModal.HotkeysGrid>
250
+
251
+ {state.crosshairModifier != null && (
252
+ <>
253
+ <UserPreferencesModal.SubHeading>
254
+ {t('ModifierKeys', { defaultValue: 'Modifier Keys' })}
255
+ </UserPreferencesModal.SubHeading>
256
+ <UserPreferencesModal.HotkeysGrid>
257
+ <div className="flex items-center justify-between gap-2">
258
+ <span className="text-foreground text-base">
259
+ {t('CrosshairsModifier', { defaultValue: 'Crosshairs' })}
260
+ </span>
261
+ <div className="flex items-center gap-1.5">
262
+ <span className="text-muted-foreground text-sm">
263
+ {t('PlusLeftClick', { defaultValue: 'Left Click +' })}
264
+ </span>
265
+ <Select
266
+ value={state.crosshairModifier}
267
+ onValueChange={val => setState(s => ({ ...s, crosshairModifier: val }))}
268
+ >
269
+ <SelectTrigger className="w-16">
270
+ <SelectValue />
271
+ </SelectTrigger>
272
+ <SelectContent>
273
+ {MODIFIER_OPTIONS.map(opt => (
274
+ <SelectItem
275
+ key={opt.value}
276
+ value={opt.value}
277
+ >
278
+ {opt.label}
279
+ </SelectItem>
280
+ ))}
281
+ </SelectContent>
282
+ </Select>
283
+ </div>
284
+ </div>
285
+ </UserPreferencesModal.HotkeysGrid>
286
+ </>
287
+ )}
288
+ </UserPreferencesModal.Body>
289
+ <FooterAction>
290
+ <FooterAction.Left>
291
+ <FooterAction.Auxiliary onClick={onResetHandler}>
292
+ {t('Reset to defaults')}
293
+ </FooterAction.Auxiliary>
294
+ </FooterAction.Left>
295
+ <FooterAction.Right>
296
+ <FooterAction.Secondary
297
+ onClick={() => {
298
+ hotkeysModule.stopRecord();
299
+ hotkeysModule.unpause();
300
+ hide();
301
+ }}
302
+ >
303
+ {t('Cancel')}
304
+ </FooterAction.Secondary>
305
+ <FooterAction.Primary
306
+ onClick={() => {
307
+ if (state.languageValue !== currentLanguage.value) {
308
+ i18n.changeLanguage(state.languageValue);
309
+ // Force page reload after language change to ensure all translations are applied
310
+ window.location.reload();
311
+ return; // Exit early since we're reloading
312
+ }
313
+ hotkeysManager.setHotkeys(state.hotkeyDefinitions);
314
+
315
+ if (toolGroupService && state.crosshairModifier != null) {
316
+ const bindings = [
317
+ { mouseButton: 1, modifierKey: Number(state.crosshairModifier) },
318
+ ];
319
+ toolGroupService.setToolBindings('mpr', 'Crosshairs', bindings);
320
+ toolGroupService.applyToolBindings('mpr', 'Crosshairs', {
321
+ replaceExisting: true,
322
+ });
323
+ toolGroupService.persistToolBindings('mpr', 'Crosshairs', bindings);
324
+ }
325
+
326
+ hotkeysModule.stopRecord();
327
+ hotkeysModule.unpause();
328
+ hide();
329
+ }}
330
+ >
331
+ {t('Save')}
332
+ </FooterAction.Primary>
333
+ </FooterAction.Right>
334
+ </FooterAction>
335
+ </UserPreferencesModal>
336
+ );
337
+ }
338
+
339
+ export default {
340
+ 'ohif.userPreferencesModal': UserPreferencesModalDefault,
341
+ 'ohif.userPreferences.toolBindingsStorageKey': DEFAULT_TOOL_BINDINGS_STORAGE_KEY,
342
+ };