@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,75 @@
1
+ import {
2
+ deleteStudyMetadataPromise,
3
+ _getStudyMetadataPromiseCache,
4
+ } from './retrieveStudyMetadata.js';
5
+
6
+ const STUDY = '1.2.840.113619.2.55.3.1234';
7
+ const OTHER_STUDY = '9.9.9';
8
+
9
+ describe('deleteStudyMetadataPromise', () => {
10
+ beforeEach(() => {
11
+ _getStudyMetadataPromiseCache().clear();
12
+ });
13
+
14
+ // Promises are cached under `<data source name>:<StudyInstanceUID>`, but every
15
+ // caller holds only the study UID. Looking the bare UID up as a key matched
16
+ // nothing, so storing a derived artifact never invalidated anything and a
17
+ // re-retrieve returned the pre-save promise.
18
+ it('removes the promise cached under the data source qualified key', () => {
19
+ const cache = _getStudyMetadataPromiseCache();
20
+ cache.set(`dicomweb:${STUDY}`, 'stale');
21
+
22
+ deleteStudyMetadataPromise(STUDY);
23
+
24
+ expect(cache.has(`dicomweb:${STUDY}`)).toBe(false);
25
+ });
26
+
27
+ it('removes the study from every data source that cached it', () => {
28
+ const cache = _getStudyMetadataPromiseCache();
29
+ cache.set(`dicomweb:${STUDY}`, 'stale');
30
+ cache.set(`dicomwebproxy:${STUDY}`, 'stale');
31
+
32
+ deleteStudyMetadataPromise(STUDY);
33
+
34
+ expect(cache.size).toBe(0);
35
+ });
36
+
37
+ it('leaves other studies cached', () => {
38
+ const cache = _getStudyMetadataPromiseCache();
39
+ cache.set(`dicomweb:${STUDY}`, 'stale');
40
+ cache.set(`dicomweb:${OTHER_STUDY}`, 'keep');
41
+
42
+ deleteStudyMetadataPromise(STUDY);
43
+
44
+ expect(cache.has(`dicomweb:${OTHER_STUDY}`)).toBe(true);
45
+ });
46
+
47
+ // A study whose UID is a suffix of another must not be caught by the match.
48
+ it('does not remove a study whose UID merely ends with the same digits', () => {
49
+ const cache = _getStudyMetadataPromiseCache();
50
+ cache.set(`dicomweb:${STUDY}`, 'stale');
51
+ cache.set(`dicomweb:77${STUDY}`, 'keep');
52
+
53
+ deleteStudyMetadataPromise(STUDY);
54
+
55
+ expect(cache.has(`dicomweb:77${STUDY}`)).toBe(true);
56
+ });
57
+
58
+ it('still removes an unqualified key, for any caller that cached one', () => {
59
+ const cache = _getStudyMetadataPromiseCache();
60
+ cache.set(STUDY, 'stale');
61
+
62
+ deleteStudyMetadataPromise(STUDY);
63
+
64
+ expect(cache.has(STUDY)).toBe(false);
65
+ });
66
+
67
+ it('does nothing without a study', () => {
68
+ const cache = _getStudyMetadataPromiseCache();
69
+ cache.set(`dicomweb:${STUDY}`, 'keep');
70
+
71
+ deleteStudyMetadataPromise(undefined);
72
+
73
+ expect(cache.size).toBe(1);
74
+ });
75
+ });
@@ -0,0 +1,346 @@
1
+ import { HeadersInterface } from '@ohif/core/src/types/RequestHeaders';
2
+
3
+ export type ThumbnailContext = {
4
+ StudyInstanceUID?: string;
5
+ SeriesInstanceUID?: string;
6
+ SOPInstanceUID?: string;
7
+ };
8
+
9
+ type ThumbnailFetchRequestResult = {
10
+ url: string;
11
+ endpointPath: string;
12
+ headers: Record<string, string>;
13
+ };
14
+
15
+ type GetThumbnailSrcOptions = {
16
+ signal?: AbortSignal;
17
+ getImageSrc?: (imageId: unknown) => unknown;
18
+ };
19
+
20
+ type QidoClient = {
21
+ headers: HeadersInterface;
22
+ searchForInstances: (opts: unknown) => Promise<unknown[]>;
23
+ };
24
+
25
+ /**
26
+ * The subset of the data source's `retrieve` object the thumbnail strategies
27
+ * call back into for the directURL and bulkData-backed renderings.
28
+ */
29
+ type RetrieveApi = {
30
+ directURL: (params: unknown) => unknown;
31
+ bulkDataURI: (params: unknown) => Promise<BlobPart>;
32
+ };
33
+
34
+ type ThumbnailConfig = {
35
+ thumbnailRendering?: string;
36
+ thumbnailRequestStrategy?: 'bulkDataRetrieve' | 'fetch';
37
+ wadoRoot?: string;
38
+ };
39
+
40
+ type GetGetThumbnailSrcDeps = {
41
+ thumbnailContext: ThumbnailContext;
42
+ imageId: unknown;
43
+ config: ThumbnailConfig;
44
+ getAuthorizationHeader: () => HeadersInterface;
45
+ qidoDicomWebClient: QidoClient;
46
+ retrieve: RetrieveApi;
47
+ };
48
+
49
+ /**
50
+ * Builds the `getThumbnailSrc` function for a given thumbnail context,
51
+ * selecting the strategy from `config.thumbnailRendering` /
52
+ * `config.thumbnailRequestStrategy`.
53
+ *
54
+ * Extracted from the DICOMweb data source so the thumbnail strategies live
55
+ * apart from the data source wiring. The `retrieve` dependency provides the
56
+ * `directURL` and `bulkDataURI` callbacks the data source used to reach via
57
+ * `this`.
58
+ */
59
+ export function getGetThumbnailSrc({
60
+ thumbnailContext,
61
+ imageId,
62
+ config,
63
+ getAuthorizationHeader,
64
+ qidoDicomWebClient,
65
+ retrieve,
66
+ }: GetGetThumbnailSrcDeps) {
67
+ const thumbnailRendering = config.thumbnailRendering;
68
+ if (!thumbnailRendering) {
69
+ return function getThumbnailSrc() {
70
+ console.warn('thumbnailRendering is not configured; returning null thumbnail src.');
71
+ return null;
72
+ };
73
+ }
74
+
75
+ if (thumbnailRendering === 'wadors') {
76
+ return function getThumbnailSrc(options?: GetThumbnailSrcOptions) {
77
+ if (!imageId) {
78
+ return null;
79
+ }
80
+ if (!options?.getImageSrc) {
81
+ return null;
82
+ }
83
+ // Note: options.signal (Cornerstone-backed loadImageToCanvas via getImageSrc) does
84
+ // not currently expose an AbortSignal hook, so abort is not propagated to the
85
+ // underlying image load. We short-circuit only if already aborted at call time.
86
+ if (options?.signal?.aborted) {
87
+ return null;
88
+ }
89
+ return options.getImageSrc(imageId);
90
+ };
91
+ }
92
+
93
+ // thumbnailDirect is for plain <img src> URLs without auth headers; never use fetch here.
94
+ // No network call happens at this layer (the <img> element loads the URL later), so
95
+ // options.signal is not applicable here.
96
+ if (thumbnailRendering === 'thumbnailDirect') {
97
+ return function getThumbnailSrc() {
98
+ return retrieve.directURL({
99
+ instance: thumbnailContext,
100
+ defaultPath: '/thumbnail',
101
+ defaultType: 'image/jpeg',
102
+ singlepart: true,
103
+ tag: 'Absent',
104
+ });
105
+ };
106
+ }
107
+
108
+ const thumbnailRequestStrategy = config.thumbnailRequestStrategy || 'bulkDataRetrieve';
109
+ if (thumbnailRequestStrategy === 'fetch') {
110
+ return async function getThumbnailSrc(options?: { signal?: AbortSignal }) {
111
+ return fetchThumbnailWithQidoFallbackForSeries(
112
+ thumbnailContext,
113
+ thumbnailRendering,
114
+ config.wadoRoot,
115
+ getAuthorizationHeader,
116
+ qidoDicomWebClient,
117
+ options?.signal
118
+ );
119
+ };
120
+ }
121
+
122
+ if (thumbnailRendering === 'thumbnail') {
123
+ return async function getThumbnailSrc(options?: { signal?: AbortSignal }) {
124
+ // Note: this path goes through bulkDataURI -> dicomweb-client retrieveBulkData,
125
+ // which is XHR-based and does NOT honor AbortSignal. The underlying request will
126
+ // run to completion server-side even if signal aborts; we only short-circuit
127
+ // before kicking it off if already aborted.
128
+ if (options?.signal?.aborted) {
129
+ return null;
130
+ }
131
+ const endpoint = buildThumbnailEndpointPath(
132
+ thumbnailContext,
133
+ thumbnailRendering,
134
+ new URLSearchParams({ accept: 'image/jpeg' })
135
+ );
136
+ const bulkDataURI = `${config.wadoRoot}${endpoint}`;
137
+ return URL.createObjectURL(
138
+ new Blob(
139
+ [
140
+ await retrieve.bulkDataURI({
141
+ BulkDataURI: bulkDataURI.replace('wadors:', ''),
142
+ defaultType: 'image/jpeg',
143
+ mediaTypes: ['image/jpeg'],
144
+ thumbnail: true,
145
+ }),
146
+ ],
147
+ { type: 'image/jpeg' }
148
+ )
149
+ );
150
+ };
151
+ }
152
+ if (thumbnailRendering === 'rendered') {
153
+ return async function getThumbnailSrc(options?: { signal?: AbortSignal }) {
154
+ // Note: this path goes through bulkDataURI -> dicomweb-client retrieveBulkData,
155
+ // which is XHR-based and does NOT honor AbortSignal. The underlying request will
156
+ // run to completion server-side even if signal aborts; we only short-circuit
157
+ // before kicking it off if already aborted.
158
+ if (options?.signal?.aborted) {
159
+ return null;
160
+ }
161
+ const endpoint = buildThumbnailEndpointPath(
162
+ thumbnailContext,
163
+ thumbnailRendering,
164
+ new URLSearchParams({ accept: 'image/jpeg' })
165
+ );
166
+ const bulkDataURI = `${config.wadoRoot}${endpoint}`;
167
+ return URL.createObjectURL(
168
+ new Blob(
169
+ [
170
+ await retrieve.bulkDataURI({
171
+ BulkDataURI: bulkDataURI.replace('wadors:', ''),
172
+ defaultType: 'image/jpeg',
173
+ mediaTypes: ['image/jpeg'],
174
+ thumbnail: true,
175
+ }),
176
+ ],
177
+ { type: 'image/jpeg' }
178
+ )
179
+ );
180
+ };
181
+ }
182
+
183
+ return function getThumbnailSrc() {
184
+ console.warn(
185
+ `Unsupported thumbnailRendering "${thumbnailRendering}"; returning null thumbnail src.`
186
+ );
187
+ return null;
188
+ };
189
+ }
190
+
191
+ function buildThumbnailEndpointPath(
192
+ thumbnailContext: ThumbnailContext,
193
+ thumbnailRendering: string,
194
+ queryParams?: URLSearchParams
195
+ ): string {
196
+ const { StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID } = thumbnailContext;
197
+
198
+ const basePath =
199
+ SeriesInstanceUID && SOPInstanceUID
200
+ ? `/studies/${StudyInstanceUID}/series/${SeriesInstanceUID}/instances/${SOPInstanceUID}/${thumbnailRendering}`
201
+ : SeriesInstanceUID
202
+ ? `/studies/${StudyInstanceUID}/series/${SeriesInstanceUID}/${thumbnailRendering}`
203
+ : `/studies/${StudyInstanceUID}/${thumbnailRendering}`;
204
+
205
+ if (!queryParams) {
206
+ return basePath;
207
+ }
208
+
209
+ const queryString = queryParams.toString();
210
+
211
+ return queryString ? `${basePath}?${queryString}` : basePath;
212
+ }
213
+
214
+ function getThumbnailFetchRequest(
215
+ thumbnailContext: ThumbnailContext,
216
+ thumbnailRendering: string,
217
+ wadoRoot: string | undefined,
218
+ getAuthorizationHeader: () => HeadersInterface
219
+ ): ThumbnailFetchRequestResult {
220
+ const endpointPath = buildThumbnailEndpointPath(
221
+ thumbnailContext,
222
+ thumbnailRendering,
223
+ // Thumbnails for some data source (e.g. dcm4chee) are pixelated by default, so we need to set the viewport to 256,256 to get a better thumbnail.
224
+ new URLSearchParams({ viewport: '256,256' })
225
+ );
226
+
227
+ const headers: Record<string, string> = {
228
+ ...(getAuthorizationHeader() as Record<string, string>),
229
+ Accept: 'image/jpeg',
230
+ };
231
+
232
+ return {
233
+ url: `${wadoRoot}${endpointPath}`,
234
+ endpointPath,
235
+ headers,
236
+ };
237
+ }
238
+
239
+ async function fetchThumbnailObjectURL(
240
+ thumbnailContext: ThumbnailContext,
241
+ thumbnailRendering: string,
242
+ wadoRoot: string | undefined,
243
+ getAuthorizationHeader: () => HeadersInterface,
244
+ signal?: AbortSignal
245
+ ): Promise<string | null> {
246
+ const fetchRequest = getThumbnailFetchRequest(
247
+ thumbnailContext,
248
+ thumbnailRendering,
249
+ wadoRoot,
250
+ getAuthorizationHeader
251
+ );
252
+
253
+ try {
254
+ const response = await fetch(fetchRequest.url, {
255
+ method: 'GET',
256
+ headers: fetchRequest.headers,
257
+ signal,
258
+ });
259
+
260
+ if (!response.ok) {
261
+ console.warn(
262
+ `thumbnail fetch failed with status ${response.status} for ${fetchRequest.endpointPath}`
263
+ );
264
+ return null;
265
+ }
266
+
267
+ const blob = await response.blob();
268
+ return URL.createObjectURL(blob);
269
+ } catch (error) {
270
+ if ((error as { name?: string })?.name === 'AbortError') {
271
+ return null;
272
+ }
273
+ console.warn('thumbnail fetch failed', error);
274
+ return null;
275
+ }
276
+ }
277
+
278
+ /**
279
+ * When thumbnailRequestStrategy is fetch: try WADO GET for the given context; if it fails and the
280
+ * context is series-level (no SOPInstanceUID), QIDO one instance and retry fetch once.
281
+ */
282
+ async function fetchThumbnailWithQidoFallbackForSeries(
283
+ thumbnailContext: ThumbnailContext,
284
+ thumbnailRendering: string,
285
+ wadoRoot: string | undefined,
286
+ getAuthorizationHeader: () => HeadersInterface,
287
+ qidoClient: QidoClient,
288
+ signal?: AbortSignal
289
+ ): Promise<string | null> {
290
+ const sopInstanceUidTag = '00080018';
291
+
292
+ const initialThumbnailUrl = await fetchThumbnailObjectURL(
293
+ thumbnailContext,
294
+ thumbnailRendering,
295
+ wadoRoot,
296
+ getAuthorizationHeader,
297
+ signal
298
+ );
299
+ if (initialThumbnailUrl) {
300
+ return initialThumbnailUrl;
301
+ }
302
+ if (signal?.aborted) {
303
+ return null;
304
+ }
305
+ if (thumbnailContext.SOPInstanceUID) {
306
+ return null;
307
+ }
308
+ if (!thumbnailContext.StudyInstanceUID || !thumbnailContext.SeriesInstanceUID) {
309
+ return null;
310
+ }
311
+ try {
312
+ qidoClient.headers = getAuthorizationHeader();
313
+ // Note: qidoClient.searchForInstances is XHR-based (dicomweb-client) and does not honor
314
+ // AbortSignal. If signal aborts mid-request the network call still completes; we just
315
+ // short-circuit before issuing a follow-up fetch below.
316
+ const instances = await qidoClient.searchForInstances({
317
+ studyInstanceUID: thumbnailContext.StudyInstanceUID,
318
+ seriesInstanceUID: thumbnailContext.SeriesInstanceUID,
319
+ queryParams: {
320
+ limit: 1,
321
+ includefield: sopInstanceUidTag,
322
+ },
323
+ });
324
+ if (signal?.aborted) {
325
+ return null;
326
+ }
327
+ const firstInstance = instances?.[0] as Record<string, unknown> | undefined;
328
+ const sopAttr = firstInstance?.[sopInstanceUidTag] as { Value?: string[] } | undefined;
329
+ const sopValues = sopAttr?.Value;
330
+ const SOPInstanceUID =
331
+ Array.isArray(sopValues) && sopValues.length ? String(sopValues[0]) : undefined;
332
+ if (!SOPInstanceUID) {
333
+ return null;
334
+ }
335
+ return fetchThumbnailObjectURL(
336
+ { ...thumbnailContext, SOPInstanceUID },
337
+ thumbnailRendering,
338
+ wadoRoot,
339
+ getAuthorizationHeader,
340
+ signal
341
+ );
342
+ } catch (error) {
343
+ console.warn('thumbnail fetch QIDO fallback failed', error);
344
+ return null;
345
+ }
346
+ }
@@ -0,0 +1,143 @@
1
+ import { createDicomWebApi } from './index';
2
+
3
+ // The data source imports the image loader for its multiframe Part 10 prefetch
4
+ // path, and that module's codec wasm entrypoints are not resolvable under jest.
5
+ // These tests only assert URLs, so a bare stub is enough.
6
+ jest.mock('@cornerstonejs/dicom-image-loader', () => ({
7
+ __esModule: true,
8
+ default: { prefetchPart10Instance: jest.fn() },
9
+ }));
10
+
11
+ // Only the pieces the module graph destructures at import time, plus enough to
12
+ // let a QIDO search return an empty result set. These tests assert URLs, so no
13
+ // DICOM value parsing is exercised.
14
+ jest.mock('@ohif/core', () => ({
15
+ DicomMetadataStore: { addSeriesMetadata: jest.fn(), addInstances: jest.fn() },
16
+ // The data source wraps its implementation object; return it unchanged so the
17
+ // test can reach `retrieve.getWadoDicomWebClient()`.
18
+ IWebApiDataSource: { create: implementation => implementation },
19
+ DICOMWeb: {
20
+ getString: element => element?.Value?.[0],
21
+ getName: element => element?.Value?.[0],
22
+ getModalities: (...elements) => elements.find(Boolean),
23
+ },
24
+ utils: {
25
+ generateAcceptHeader: jest.fn(() => 'application/dicom+json'),
26
+ formatDate: date => date,
27
+ },
28
+ errorHandler: { getHTTPErrorHandler: jest.fn(() => jest.fn()) },
29
+ classes: { MetadataProvider: { addImageIdToUIDs: jest.fn() } },
30
+ }));
31
+
32
+ const servicesManager = {
33
+ services: {
34
+ userAuthenticationService: { getAuthorizationHeader: () => ({}) },
35
+ },
36
+ };
37
+
38
+ /**
39
+ * Builds an initialized data source and returns it alongside the single
40
+ * DICOMweb client it configured.
41
+ */
42
+ function initDataSource(config) {
43
+ const dataSource = createDicomWebApi(config, servicesManager);
44
+ dataSource.initialize({});
45
+ return { dataSource, client: dataSource.retrieve.getWadoDicomWebClient() };
46
+ }
47
+
48
+ describe('DicomWebDataSource service URLs', () => {
49
+ it('routes each service to its own root when qidoRoot and wadoRoot differ', () => {
50
+ const { client } = initDataSource({
51
+ qidoRoot: 'https://server.com/qidors/org1',
52
+ wadoRoot: 'https://server.com/wadors/org1',
53
+ });
54
+
55
+ expect(client.qidoURL).toBe('https://server.com/qidors/org1');
56
+ expect(client.wadoURL).toBe('https://server.com/wadors/org1');
57
+ // No stowRoot configured, so STOW keeps the pre-existing wadoRoot behaviour.
58
+ expect(client.stowURL).toBe('https://server.com/wadors/org1');
59
+ });
60
+
61
+ it('uses an explicit stowRoot for STOW only', () => {
62
+ const { client } = initDataSource({
63
+ qidoRoot: 'https://server.com/qidors/org1',
64
+ wadoRoot: 'https://server.com/wadors/org1',
65
+ stowRoot: 'https://server.com/stowrs/org1',
66
+ });
67
+
68
+ expect(client.qidoURL).toBe('https://server.com/qidors/org1');
69
+ expect(client.wadoURL).toBe('https://server.com/wadors/org1');
70
+ expect(client.stowURL).toBe('https://server.com/stowrs/org1');
71
+ });
72
+
73
+ it('points every service at the shared root when the roots are the same', () => {
74
+ const { client } = initDataSource({
75
+ qidoRoot: 'https://server.com/dicomweb',
76
+ wadoRoot: 'https://server.com/dicomweb',
77
+ });
78
+
79
+ expect(client.qidoURL).toBe('https://server.com/dicomweb');
80
+ expect(client.wadoURL).toBe('https://server.com/dicomweb');
81
+ expect(client.stowURL).toBe('https://server.com/dicomweb');
82
+ });
83
+
84
+ it('leaves no service URL undefined when only one root is configured', () => {
85
+ const { client: qidoOnly } = initDataSource({ qidoRoot: 'https://server.com/qidors' });
86
+ expect(qidoOnly.qidoURL).toBe('https://server.com/qidors');
87
+ expect(qidoOnly.wadoURL).toBe('https://server.com/qidors');
88
+ expect(qidoOnly.stowURL).toBe('https://server.com/qidors');
89
+
90
+ const { client: wadoOnly } = initDataSource({ wadoRoot: 'https://server.com/wadors' });
91
+ expect(wadoOnly.qidoURL).toBe('https://server.com/wadors');
92
+ expect(wadoOnly.wadoURL).toBe('https://server.com/wadors');
93
+ expect(wadoOnly.stowURL).toBe('https://server.com/wadors');
94
+ });
95
+
96
+ /**
97
+ * Regression test for the reported failure: the series search issued while
98
+ * loading study metadata resolves against `qidoURL`, and previously ran on a
99
+ * client whose qidoURL was wadoRoot, producing
100
+ * `https://server.com/wadors/org1/studies/{uid}/series?...` -> 400.
101
+ */
102
+ it('issues QIDO series searches against qidoRoot', async () => {
103
+ const { dataSource, client } = initDataSource({
104
+ qidoRoot: 'https://server.com/qidors/org1',
105
+ wadoRoot: 'https://server.com/wadors/org1',
106
+ });
107
+
108
+ const requestedUrls: string[] = [];
109
+ client._httpGetApplicationJson = url => {
110
+ requestedUrls.push(url);
111
+ return Promise.resolve([]);
112
+ };
113
+
114
+ await dataSource.query.series.search('1.2.3');
115
+
116
+ expect(requestedUrls).toHaveLength(1);
117
+ // The loader appends `includefield` query params; only the endpoint matters here.
118
+ const [requestedPath] = requestedUrls[0].split('?');
119
+ expect(requestedPath).toBe('https://server.com/qidors/org1/studies/1.2.3/series');
120
+ });
121
+
122
+ it('retrieves WADO series metadata against wadoRoot', async () => {
123
+ const { client } = initDataSource({
124
+ qidoRoot: 'https://server.com/qidors/org1',
125
+ wadoRoot: 'https://server.com/wadors/org1',
126
+ });
127
+
128
+ const requestedUrls: string[] = [];
129
+ client._httpGetApplicationJson = url => {
130
+ requestedUrls.push(url);
131
+ return Promise.resolve([]);
132
+ };
133
+
134
+ await client.retrieveSeriesMetadata({
135
+ studyInstanceUID: '1.2.3',
136
+ seriesInstanceUID: '4.5.6',
137
+ });
138
+
139
+ expect(requestedUrls[0]).toBe(
140
+ 'https://server.com/wadors/org1/studies/1.2.3/series/4.5.6/metadata'
141
+ );
142
+ });
143
+ });