@ohif/extension-default 3.14.0-beta.1 → 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,661 @@
1
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import {
4
+ cn,
5
+ FooterAction,
6
+ Icons,
7
+ Input,
8
+ Label,
9
+ Select,
10
+ SelectContent,
11
+ SelectItem,
12
+ SelectTrigger,
13
+ SelectValue,
14
+ Tabs,
15
+ TabsList,
16
+ TabsTrigger,
17
+ } from '@ohif/ui-next';
18
+ import { useSystem } from '@ohif/core';
19
+
20
+ import {
21
+ getSeriesDescriptionHistory,
22
+ rememberSeriesDescription,
23
+ } from '../utils/seriesDescriptionHistory';
24
+
25
+ /**
26
+ * The dialog that stores a segmentation, a contour set or a measurement report.
27
+ * See `platform/docs/docs/behaviours/report-dialog-save-destinations.md`.
28
+ */
29
+
30
+ type DataSource = {
31
+ value: string;
32
+ label: string;
33
+ placeHolder: string;
34
+ };
35
+
36
+ /** A series of the stored modality that this save could be written into. */
37
+ type ExistingSeries = {
38
+ /** Identifies the series to store into, as a predecessorImageId value. */
39
+ value: string;
40
+ /** Numeric series number, used to compute the next available series number. */
41
+ seriesNumber: number;
42
+ /** Series number as shown to the user, or a placeholder when there isn't one. */
43
+ seriesNumberLabel: string;
44
+ description: string | null;
45
+ /** What the series is called in the list of series to replace. */
46
+ label: string;
47
+ };
48
+
49
+ /**
50
+ * Which series the save goes into:
51
+ * - `current` the series the data was loaded from
52
+ * - `new` a series created for it
53
+ * - `replace` another loaded series of this modality
54
+ *
55
+ * All three store the same object, and the dialog merges nothing.
56
+ */
57
+ type Destination = 'current' | 'new' | 'replace';
58
+
59
+ const DESTINATIONS: {
60
+ value: Destination;
61
+ label: string;
62
+ help: string;
63
+ /** Why the destination is not available, shown on the disabled tab. */
64
+ unavailable: string;
65
+ }[] = [
66
+ {
67
+ value: 'current',
68
+ label: 'Save to current',
69
+ help: 'Adds a new version to this series as the new default. Earlier versions are kept.',
70
+ unavailable: 'This data has not been saved to a series yet',
71
+ },
72
+ {
73
+ value: 'new',
74
+ label: 'Save as new',
75
+ help: 'Creates a separate series.',
76
+ unavailable: '',
77
+ },
78
+ {
79
+ value: 'replace',
80
+ label: 'Replace existing',
81
+ help: 'Choose a series to replace. The current data becomes the default and earlier versions are kept.',
82
+ unavailable: 'No other series of this type is loaded',
83
+ },
84
+ ];
85
+
86
+ type ReportDialogProps = {
87
+ dataSources: DataSource[];
88
+ modality?: string;
89
+ /**
90
+ * The image id the data being saved was loaded from. When it belongs to a
91
+ * loaded series, that series is the one `Save to current` writes into.
92
+ */
93
+ predecessorImageId?: string;
94
+ /** Lowest series number to use for a newly created series of this modality. */
95
+ minSeriesNumber?: number;
96
+ /**
97
+ * The name that the user chose for the item - the segmentation name, for
98
+ * example. A new series offers this name first. A generated name is not such
99
+ * a name, and belongs in `defaultSeriesDescription`.
100
+ */
101
+ itemName?: string;
102
+ /**
103
+ * The name for an item that has no other name, such as 'Contours' or
104
+ * 'Measurements'. A new series offers this name last.
105
+ */
106
+ defaultSeriesDescription?: string;
107
+ /**
108
+ * The type of item being stored, used as the key the series descriptions used
109
+ * before are remembered under. Defaults to the modality.
110
+ */
111
+ itemType?: string;
112
+ /**
113
+ * How many previously used series descriptions to remember and offer for this
114
+ * type of item. 0 remembers nothing.
115
+ */
116
+ rememberedDescriptionCount?: number;
117
+ hide: () => void;
118
+ onSave: (data: {
119
+ reportName: string;
120
+ dataSource: string | null;
121
+ series: string | null;
122
+ seriesNumber: number;
123
+ priorSeriesNumber: number;
124
+ }) => void;
125
+ onCancel: () => void;
126
+ enableDownload?: boolean;
127
+ };
128
+
129
+ function ReportDialog({
130
+ dataSources,
131
+ modality = 'SR',
132
+ predecessorImageId,
133
+ minSeriesNumber = 3000,
134
+ itemName = '',
135
+ defaultSeriesDescription = '',
136
+ itemType,
137
+ rememberedDescriptionCount = 5,
138
+ hide,
139
+ onSave,
140
+ onCancel,
141
+ enableDownload = false,
142
+ }: ReportDialogProps) {
143
+ const { t } = useTranslation('Buttons');
144
+ const { servicesManager } = useSystem();
145
+ const actionTakenRef = useRef(false);
146
+ const descriptionInputRef = useRef<HTMLInputElement>(null);
147
+ const [selectedDataSource, setSelectedDataSource] = useState<string | null>(
148
+ dataSources?.[0]?.value ?? null
149
+ );
150
+ const { displaySetService } = servicesManager.services;
151
+
152
+ /** Every loaded display set of the stored modality. */
153
+ const modalityDisplaySets = useMemo(
154
+ () =>
155
+ Array.from(displaySetService.getDisplaySetCache().values()).filter(
156
+ ds => ds.Modality === modality
157
+ ),
158
+ [displaySetService, modality]
159
+ );
160
+
161
+ const existingSeries = useMemo((): ExistingSeries[] => {
162
+ const seen = new Set<string>();
163
+
164
+ return modalityDisplaySets
165
+ .map(ds => {
166
+ const hasSeriesNumber = isFinite(ds.SeriesNumber);
167
+ const seriesNumberLabel = hasSeriesNumber ? `${ds.SeriesNumber}` : 'Not specified';
168
+ return {
169
+ value: ds.predecessorImageId,
170
+ seriesNumber: hasSeriesNumber ? Number(ds.SeriesNumber) : minSeriesNumber,
171
+ seriesNumberLabel,
172
+ description: ds.SeriesDescription || null,
173
+ label: ds.SeriesDescription || `Series ${seriesNumberLabel}`,
174
+ };
175
+ })
176
+ .filter(series => {
177
+ // The value names the superseded instance, so a display set without one
178
+ // cannot be a target. Two display sets can share a series.
179
+ if (!series.value || seen.has(series.value)) {
180
+ return false;
181
+ }
182
+ seen.add(series.value);
183
+ return true;
184
+ });
185
+ }, [modalityDisplaySets, minSeriesNumber]);
186
+
187
+ /**
188
+ * The series the data was loaded from, which `Save to current` writes into.
189
+ * There isn't one for data that has never been stored.
190
+ */
191
+ const currentSeries = useMemo(
192
+ () => existingSeries.find(series => series.value === predecessorImageId) ?? null,
193
+ [existingSeries, predecessorImageId]
194
+ );
195
+
196
+ /** The other series of this modality, which `Replace existing` chooses from. */
197
+ const replaceableSeries = useMemo(
198
+ () => existingSeries.filter(series => series !== currentSeries),
199
+ [existingSeries, currentSeries]
200
+ );
201
+
202
+ /** One past every loaded series of the modality, not only the offered ones. */
203
+ const defaultNewSeriesNumber = useMemo(
204
+ () =>
205
+ 1 +
206
+ modalityDisplaySets.reduce(
207
+ (highest, ds) =>
208
+ isFinite(ds.SeriesNumber) ? Math.max(highest, Number(ds.SeriesNumber)) : highest,
209
+ minSeriesNumber
210
+ ),
211
+ [modalityDisplaySets, minSeriesNumber]
212
+ );
213
+
214
+ /**
215
+ * The series descriptions to offer for a new series: `itemName`, then the
216
+ * description of `currentSeries`, then the ones used before for this type of
217
+ * item, then `defaultSeriesDescription`.
218
+ */
219
+ const descriptionOptions = useMemo(() => {
220
+ // A count of 0 turns the history off, and the list then holds one name.
221
+ const remembered =
222
+ rememberedDescriptionCount > 0
223
+ ? getSeriesDescriptionHistory(itemType || modality, rememberedDescriptionCount)
224
+ : [];
225
+
226
+ // Trimmed here, so the stored, shown and remembered names all match.
227
+ const offered = [itemName, currentSeries?.description, ...remembered, defaultSeriesDescription]
228
+ .map(option => option?.trim())
229
+ .filter((option): option is string => !!option);
230
+
231
+ const options = offered.filter(
232
+ (option, index) =>
233
+ offered.findIndex(other => other.toLowerCase() === option.toLowerCase()) === index
234
+ );
235
+
236
+ return rememberedDescriptionCount > 0 ? options : options.slice(0, 1);
237
+ }, [
238
+ currentSeries,
239
+ itemName,
240
+ defaultSeriesDescription,
241
+ itemType,
242
+ modality,
243
+ rememberedDescriptionCount,
244
+ ]);
245
+
246
+ /** The name a new series starts from, and the fallback for an emptied field. */
247
+ const baseSeriesDescription = descriptionOptions[0] ?? '';
248
+
249
+ const [destination, setDestination] = useState<Destination>(currentSeries ? 'current' : 'new');
250
+ const [newSeriesNumber, setNewSeriesNumber] = useState(String(defaultNewSeriesNumber));
251
+ const [newSeriesDescription, setNewSeriesDescription] = useState(baseSeriesDescription);
252
+ const [replacedSeriesValue, setReplacedSeriesValue] = useState<string | null>(null);
253
+ const [descriptionsOpen, setDescriptionsOpen] = useState(false);
254
+ // Typing narrows the list to what it can complete; opening the list from its
255
+ // button shows everything on offer.
256
+ const [descriptionsFiltered, setDescriptionsFiltered] = useState(false);
257
+ const [highlightedDescription, setHighlightedDescription] = useState(-1);
258
+
259
+ const replacedSeries =
260
+ replaceableSeries.find(series => series.value === replacedSeriesValue) ?? null;
261
+
262
+ /** The series being written into - null when a series is being created. */
263
+ const targetSeries: ExistingSeries | null =
264
+ destination === 'current' ? currentSeries : destination === 'replace' ? replacedSeries : null;
265
+
266
+ /** Nothing can be produced until the series to replace has been chosen. */
267
+ const isIncomplete = destination === 'replace' && !replacedSeries;
268
+
269
+ const isAvailable = useCallback(
270
+ (value: Destination) =>
271
+ (value === 'current' && !!currentSeries) ||
272
+ value === 'new' ||
273
+ (value === 'replace' && replaceableSeries.length > 0),
274
+ [currentSeries, replaceableSeries]
275
+ );
276
+
277
+ // An emptied or otherwise unusable series number falls back to the offered one
278
+ // rather than storing something invalid.
279
+ const parsedSeriesNumber = Number.parseInt(newSeriesNumber, 10);
280
+ const seriesNumber = Number.isFinite(parsedSeriesNumber)
281
+ ? parsedSeriesNumber
282
+ : defaultNewSeriesNumber;
283
+
284
+ /** The options completing what has been typed so far, in offered order. */
285
+ const descriptionCompletions = useMemo(() => {
286
+ const typed = newSeriesDescription.trim().toLowerCase();
287
+ return descriptionOptions.filter(option => option.toLowerCase().startsWith(typed));
288
+ }, [descriptionOptions, newSeriesDescription]);
289
+
290
+ const shownDescriptions = descriptionsFiltered ? descriptionCompletions : descriptionOptions;
291
+
292
+ const acceptDescription = useCallback((description: string) => {
293
+ setNewSeriesDescription(description);
294
+ setDescriptionsOpen(false);
295
+ setHighlightedDescription(-1);
296
+ }, []);
297
+
298
+ const handleDescriptionChange = useCallback((description: string) => {
299
+ setNewSeriesDescription(description);
300
+ setHighlightedDescription(-1);
301
+ setDescriptionsFiltered(true);
302
+ setDescriptionsOpen(true);
303
+ }, []);
304
+
305
+ const submit = useCallback(
306
+ (dataSource: string | null) => {
307
+ if (isIncomplete) {
308
+ return;
309
+ }
310
+
311
+ actionTakenRef.current = true;
312
+ const storedSeriesNumber = targetSeries ? targetSeries.seriesNumber : seriesNumber;
313
+ // An existing series keeps its own description, so there is nothing for
314
+ // the user to have changed there.
315
+ const storedDescription = targetSeries
316
+ ? (targetSeries.description ?? '')
317
+ : newSeriesDescription.trim() || baseSeriesDescription;
318
+
319
+ // The history keeps only a name the user chose, so the offered default
320
+ // does not consume a slot.
321
+ const isProvidedName =
322
+ storedDescription.toLowerCase() === defaultSeriesDescription?.trim().toLowerCase();
323
+
324
+ if (!targetSeries && !isProvidedName) {
325
+ rememberSeriesDescription(
326
+ itemType || modality,
327
+ storedDescription,
328
+ rememberedDescriptionCount
329
+ );
330
+ }
331
+
332
+ onSave({
333
+ reportName: storedDescription,
334
+ dataSource,
335
+ series: targetSeries ? targetSeries.value : null,
336
+ seriesNumber: storedSeriesNumber,
337
+ // Kept for callers that compute the new series number as
338
+ // `1 + priorSeriesNumber`, including when it has been edited here.
339
+ priorSeriesNumber: storedSeriesNumber - 1,
340
+ });
341
+ hide();
342
+ },
343
+ [
344
+ isIncomplete,
345
+ targetSeries,
346
+ seriesNumber,
347
+ newSeriesDescription,
348
+ baseSeriesDescription,
349
+ defaultSeriesDescription,
350
+ itemType,
351
+ modality,
352
+ rememberedDescriptionCount,
353
+ hide,
354
+ onSave,
355
+ ]
356
+ );
357
+
358
+ const handleSave = useCallback(() => submit(selectedDataSource), [submit, selectedDataSource]);
359
+ const handleDownload = useCallback(() => submit('download'), [submit]);
360
+
361
+ const handleCancel = useCallback(() => {
362
+ actionTakenRef.current = true;
363
+ onCancel();
364
+ hide();
365
+ }, [onCancel, hide]);
366
+
367
+ const handleDescriptionKeyDown = useCallback(
368
+ (event: React.KeyboardEvent<HTMLInputElement>) => {
369
+ const highlighted =
370
+ highlightedDescription >= 0
371
+ ? shownDescriptions[highlightedDescription]
372
+ : descriptionCompletions[0];
373
+
374
+ switch (event.key) {
375
+ case 'Tab':
376
+ // Completes what has been typed, and only moves on when there is
377
+ // nothing left to complete.
378
+ if (!event.shiftKey && highlighted && highlighted !== newSeriesDescription) {
379
+ event.preventDefault();
380
+ acceptDescription(highlighted);
381
+ } else {
382
+ setDescriptionsOpen(false);
383
+ }
384
+ break;
385
+ case 'ArrowDown':
386
+ event.preventDefault();
387
+ setDescriptionsOpen(true);
388
+ setHighlightedDescription(index => Math.min(index + 1, shownDescriptions.length - 1));
389
+ break;
390
+ case 'ArrowUp':
391
+ event.preventDefault();
392
+ setHighlightedDescription(index => Math.max(index - 1, -1));
393
+ break;
394
+ case 'Escape':
395
+ if (descriptionsOpen) {
396
+ event.preventDefault();
397
+ setDescriptionsOpen(false);
398
+ setHighlightedDescription(-1);
399
+ }
400
+ break;
401
+ case 'Enter':
402
+ event.preventDefault();
403
+ if (descriptionsOpen && highlightedDescription >= 0 && highlighted) {
404
+ acceptDescription(highlighted);
405
+ } else {
406
+ handleSave();
407
+ }
408
+ break;
409
+ default:
410
+ break;
411
+ }
412
+ },
413
+ [
414
+ descriptionCompletions,
415
+ shownDescriptions,
416
+ descriptionsOpen,
417
+ highlightedDescription,
418
+ newSeriesDescription,
419
+ acceptDescription,
420
+ handleSave,
421
+ ]
422
+ );
423
+
424
+ // Handles the close dialog button/external close as a cancel
425
+ useEffect(() => {
426
+ return () => {
427
+ if (!actionTakenRef.current) {
428
+ onCancel();
429
+ }
430
+ };
431
+ }, [onCancel]);
432
+
433
+ // The dialog focuses the first control in its content when it opens, which is
434
+ // the destination tabs. Put the caret in the description instead, so that a
435
+ // new series can be named by typing straight away.
436
+ useEffect(() => {
437
+ if (destination !== 'new') {
438
+ return;
439
+ }
440
+ const focusDescription = window.setTimeout(() => descriptionInputRef.current?.focus(), 0);
441
+ return () => window.clearTimeout(focusDescription);
442
+ }, [destination]);
443
+
444
+ const selected = DESTINATIONS.find(option => option.value === destination);
445
+ const showDataSourceSelect = dataSources?.length > 1;
446
+
447
+ return (
448
+ <div className="text-foreground flex flex-col gap-4">
449
+ <div className="grid grid-cols-[7rem_minmax(0,1fr)] items-start gap-x-3 gap-y-4">
450
+ {showDataSourceSelect && (
451
+ <>
452
+ <Label className="whitespace-nowrap pt-1.5 text-base">Data source</Label>
453
+ <Select
454
+ value={selectedDataSource}
455
+ onValueChange={setSelectedDataSource}
456
+ >
457
+ <SelectTrigger data-cy="report-data-source-select">
458
+ <SelectValue placeholder="Select a data source" />
459
+ </SelectTrigger>
460
+ <SelectContent>
461
+ {dataSources.map(source => (
462
+ <SelectItem
463
+ key={source.value}
464
+ value={source.value}
465
+ >
466
+ {source.label}
467
+ </SelectItem>
468
+ ))}
469
+ </SelectContent>
470
+ </Select>
471
+ </>
472
+ )}
473
+
474
+ <Label className="whitespace-nowrap pt-1.5 text-base">Series</Label>
475
+ <div>
476
+ <Tabs
477
+ value={destination}
478
+ onValueChange={value => setDestination(value as Destination)}
479
+ >
480
+ <TabsList>
481
+ {DESTINATIONS.map(option => (
482
+ <TabsTrigger
483
+ key={option.value}
484
+ value={option.value}
485
+ data-cy={`report-destination-${option.value}`}
486
+ disabled={!isAvailable(option.value)}
487
+ title={isAvailable(option.value) ? undefined : option.unavailable}
488
+ >
489
+ {option.label}
490
+ </TabsTrigger>
491
+ ))}
492
+ </TabsList>
493
+ </Tabs>
494
+ <p
495
+ className="text-muted-foreground mt-1.5 text-sm"
496
+ data-cy="report-destination-help"
497
+ >
498
+ {selected?.help}
499
+ </p>
500
+ </div>
501
+
502
+ <Label
503
+ htmlFor={destination === 'new' ? 'dialog-input' : undefined}
504
+ className="whitespace-nowrap pt-1.5 text-base"
505
+ >
506
+ Series Description
507
+ </Label>
508
+ {destination === 'new' ? (
509
+ <div className="relative flex items-center gap-1">
510
+ <Input
511
+ ref={descriptionInputRef}
512
+ id="dialog-input"
513
+ data-cy="dialog-input"
514
+ autoComplete="off"
515
+ placeholder="Series description"
516
+ value={newSeriesDescription}
517
+ onChange={event => handleDescriptionChange(event.target.value)}
518
+ onKeyDown={handleDescriptionKeyDown}
519
+ onBlur={() => setDescriptionsOpen(false)}
520
+ />
521
+ {descriptionOptions.length > 1 && (
522
+ <button
523
+ type="button"
524
+ data-cy="report-series-description-options"
525
+ aria-label="Series descriptions used before"
526
+ className="text-primary hover:bg-primary/25 shrink-0 rounded p-0.5"
527
+ // Keeps the focus in the input, so that opening the list does
528
+ // not blur it shut again, and so that the arrow keys keep
529
+ // working afterwards.
530
+ onMouseDown={event => event.preventDefault()}
531
+ onClick={() => {
532
+ setHighlightedDescription(-1);
533
+ setDescriptionsFiltered(false);
534
+ setDescriptionsOpen(open => !open);
535
+ }}
536
+ >
537
+ <Icons.ChevronOpen className="h-5 w-5" />
538
+ </button>
539
+ )}
540
+ {descriptionsOpen && shownDescriptions.length > 0 && (
541
+ <ul
542
+ className="bg-popover text-popover-foreground border-input absolute left-0 right-0 top-full z-50 mt-1 max-h-40 overflow-auto rounded border p-1 shadow-md"
543
+ data-cy="report-series-description-list"
544
+ >
545
+ {shownDescriptions.map((description, index) => (
546
+ <li key={description}>
547
+ <button
548
+ type="button"
549
+ className={cn(
550
+ 'hover:bg-accent hover:text-accent-foreground w-full truncate rounded px-2 py-1 text-left text-base',
551
+ index === highlightedDescription && 'bg-accent text-accent-foreground'
552
+ )}
553
+ // Keeps the focus in the input, so that the list is not
554
+ // closed by the blur before the click lands.
555
+ onMouseDown={event => event.preventDefault()}
556
+ onClick={() => acceptDescription(description)}
557
+ >
558
+ {description}
559
+ </button>
560
+ </li>
561
+ ))}
562
+ </ul>
563
+ )}
564
+ </div>
565
+ ) : destination === 'replace' ? (
566
+ <Select
567
+ value={replacedSeriesValue ?? undefined}
568
+ onValueChange={setReplacedSeriesValue}
569
+ >
570
+ <SelectTrigger data-cy="report-replaced-series-select">
571
+ {/* The `Series Description` label is on the left of this row, so
572
+ the control itself asks for the choice it needs. */}
573
+ <SelectValue placeholder="Select a series" />
574
+ </SelectTrigger>
575
+ <SelectContent>
576
+ {replaceableSeries.map(series => (
577
+ <SelectItem
578
+ key={series.value}
579
+ value={series.value}
580
+ >
581
+ {series.label}
582
+ </SelectItem>
583
+ ))}
584
+ </SelectContent>
585
+ </Select>
586
+ ) : (
587
+ <span
588
+ className="break-words pt-1.5 text-base"
589
+ data-cy="report-series-description"
590
+ >
591
+ {currentSeries?.description ?? 'No description'}
592
+ </span>
593
+ )}
594
+
595
+ <Label
596
+ htmlFor={destination === 'new' ? 'report-series-number' : undefined}
597
+ className="whitespace-nowrap pt-1.5 text-base"
598
+ >
599
+ Series Number
600
+ </Label>
601
+ {destination === 'new' ? (
602
+ <Input
603
+ id="report-series-number"
604
+ data-cy="report-series-number"
605
+ type="number"
606
+ className="w-28"
607
+ value={newSeriesNumber}
608
+ onChange={event => setNewSeriesNumber(event.target.value)}
609
+ onKeyDown={event => {
610
+ if (event.key === 'Enter') {
611
+ event.preventDefault();
612
+ handleSave();
613
+ }
614
+ }}
615
+ />
616
+ ) : (
617
+ <span
618
+ className="pt-1.5 text-base"
619
+ data-cy="report-series-number"
620
+ >
621
+ {targetSeries ? targetSeries.seriesNumberLabel : ''}
622
+ </span>
623
+ )}
624
+ </div>
625
+
626
+ <FooterAction>
627
+ {enableDownload && (
628
+ <FooterAction.Left>
629
+ <FooterAction.Secondary
630
+ onClick={handleDownload}
631
+ dataCY="report-download-button"
632
+ disabled={isIncomplete}
633
+ >
634
+ {t('Download')}
635
+ </FooterAction.Secondary>
636
+ </FooterAction.Left>
637
+ )}
638
+ <FooterAction.Right>
639
+ <FooterAction.Secondary
640
+ onClick={handleCancel}
641
+ dataCY="input-dialog-cancel-button"
642
+ >
643
+ {t('Cancel')}
644
+ </FooterAction.Secondary>
645
+ <FooterAction.Primary
646
+ onClick={handleSave}
647
+ dataCY="input-dialog-save-button"
648
+ disabled={isIncomplete}
649
+ >
650
+ {selected?.label}
651
+ </FooterAction.Primary>
652
+ </FooterAction.Right>
653
+ </FooterAction>
654
+ </div>
655
+ );
656
+ }
657
+
658
+ export { ReportDialog };
659
+ export default {
660
+ 'ohif.createReportDialog': ReportDialog,
661
+ };
@@ -0,0 +1,14 @@
1
+ import { utils } from '@ohif/core';
2
+
3
+ const { sortingCriteria } = utils;
4
+ const { seriesSortCriteria } = sortingCriteria;
5
+
6
+ /** Stable series order for e2e (Playwright sets TEST_ENV=true via cross-env). */
7
+ const sortingCriteriaFn =
8
+ process.env.TEST_ENV === 'true'
9
+ ? seriesSortCriteria.compareSeriesUID
10
+ : seriesSortCriteria.seriesInfoSortingCriteria;
11
+
12
+ export default {
13
+ sortingCriteria: sortingCriteriaFn,
14
+ };