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

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,115 @@
1
+ // @ts-nocheck
2
+
3
+ function normalizeAllowedOrigins(allowedOrigins = []) {
4
+ if (!Array.isArray(allowedOrigins)) {
5
+ return [];
6
+ }
7
+
8
+ const configuredOrigins = allowedOrigins
9
+ .filter(origin => typeof origin === 'string')
10
+ .map(origin => origin.trim())
11
+ .filter(Boolean);
12
+
13
+ return configuredOrigins
14
+ .map(origin => {
15
+ try {
16
+ const parsedOrigin = new URL(origin);
17
+ if (!['http:', 'https:'].includes(parsedOrigin.protocol)) {
18
+ console.error(
19
+ `[secureConfigFetch] Ignoring misconfigured allowed origin "${origin}". ` +
20
+ 'Entries must use http:// or https://.'
21
+ );
22
+ return null;
23
+ }
24
+ if (
25
+ parsedOrigin.username ||
26
+ parsedOrigin.password ||
27
+ parsedOrigin.pathname !== '/' ||
28
+ parsedOrigin.search ||
29
+ parsedOrigin.hash
30
+ ) {
31
+ console.error(
32
+ `[secureConfigFetch] Ignoring misconfigured allowed origin "${origin}". ` +
33
+ 'Entries must be bare origins only (scheme + host + optional port), with no username/password, path, query, or hash.'
34
+ );
35
+ return null;
36
+ }
37
+ return parsedOrigin.origin;
38
+ } catch {
39
+ console.error(
40
+ `[secureConfigFetch] Ignoring misconfigured allowed origin "${origin}". Entry is not a valid URL.`
41
+ );
42
+ return null;
43
+ }
44
+ })
45
+ .filter(Boolean);
46
+ }
47
+
48
+ function resolveConfigUrl(rawUrl) {
49
+ if (!rawUrl || typeof rawUrl !== 'string') {
50
+ throw new Error('Missing required "url" query parameter');
51
+ }
52
+
53
+ try {
54
+ return new URL(rawUrl, window.location.href);
55
+ } catch {
56
+ throw new Error('Invalid URL in "url" query parameter');
57
+ }
58
+ }
59
+
60
+ function resolveConfigFetchPolicy(rawUrl, policy = {}) {
61
+ const { allowedOrigins = [], userAuthenticationService } = policy;
62
+ const parsedUrl = resolveConfigUrl(rawUrl);
63
+ const protocol = parsedUrl.protocol.toLowerCase();
64
+ const isSameOrigin = parsedUrl.origin === window.location.origin;
65
+
66
+ if (!['http:', 'https:'].includes(protocol)) {
67
+ throw new Error('Only HTTP(S) URLs are allowed for dynamic datasource configuration');
68
+ }
69
+
70
+ if (parsedUrl.hash) {
71
+ throw new Error('URL fragments are not allowed for dynamic datasource configuration');
72
+ }
73
+
74
+ if (parsedUrl.username || parsedUrl.password) {
75
+ throw new Error('URL userinfo is not allowed for dynamic datasource configuration');
76
+ }
77
+
78
+ const isAuthenticated = Boolean(
79
+ userAuthenticationService?.getAuthorizationHeader?.()?.Authorization
80
+ );
81
+
82
+ if (isAuthenticated && !isSameOrigin) {
83
+ const normalizedAllowedOrigins = normalizeAllowedOrigins(allowedOrigins);
84
+ if (!normalizedAllowedOrigins.length || !normalizedAllowedOrigins.includes(parsedUrl.origin)) {
85
+ throw new Error(
86
+ `Blocked remote configuration origin "${parsedUrl.origin}" in authenticated environment`
87
+ );
88
+ }
89
+ }
90
+
91
+ return {
92
+ parsedUrl,
93
+ normalizedUrl: parsedUrl.toString(),
94
+ isAuthenticated,
95
+ isSameOrigin,
96
+ };
97
+ }
98
+
99
+ async function fetchConfigJson(normalizedPolicy) {
100
+ const { normalizedUrl } = normalizedPolicy;
101
+ const response = await fetch(normalizedUrl, {
102
+ method: 'GET',
103
+ mode: 'cors',
104
+ credentials: 'same-origin',
105
+ redirect: 'error',
106
+ referrerPolicy: 'no-referrer',
107
+ });
108
+
109
+ if (!response.ok) {
110
+ throw new Error(`Failed to fetch dynamic datasource configuration (${response.status})`);
111
+ }
112
+
113
+ return response.json();
114
+ }
115
+ export { resolveConfigFetchPolicy, fetchConfigJson };
@@ -0,0 +1,163 @@
1
+ // @ts-nocheck
2
+ import { resolveConfigFetchPolicy, fetchConfigJson } from './secureConfigFetch';
3
+
4
+ describe('secureConfigFetch', () => {
5
+ describe('resolveConfigFetchPolicy', () => {
6
+ it('allows arbitrary origin in unauthenticated environments', () => {
7
+ const result = resolveConfigFetchPolicy('https://untrusted.example.com/config.json', {
8
+ userAuthenticationService: {
9
+ getAuthorizationHeader: () => ({}),
10
+ },
11
+ });
12
+
13
+ expect(result.normalizedUrl).toBe('https://untrusted.example.com/config.json');
14
+ expect(result.isAuthenticated).toBe(false);
15
+ expect(result.isSameOrigin).toBe(false);
16
+ });
17
+
18
+ it('blocks non-allowlisted origins in authenticated environments', () => {
19
+ expect(() =>
20
+ resolveConfigFetchPolicy('https://untrusted.example.com/config.json', {
21
+ allowedOrigins: ['https://trusted.example.com'],
22
+ userAuthenticationService: {
23
+ getAuthorizationHeader: () => ({ Authorization: 'Bearer token123' }),
24
+ },
25
+ })
26
+ ).toThrow('Blocked remote configuration origin');
27
+ });
28
+
29
+ it('allows allowlisted origin in authenticated environments', () => {
30
+ const result = resolveConfigFetchPolicy('http://localhost:5000/config.json', {
31
+ allowedOrigins: ['http://localhost:5000', 'https://trusted.example.com'],
32
+ userAuthenticationService: {
33
+ getAuthorizationHeader: () => ({ Authorization: 'Bearer token123' }),
34
+ },
35
+ });
36
+
37
+ expect(result.normalizedUrl).toBe('http://localhost:5000/config.json');
38
+ expect(result.isAuthenticated).toBe(true);
39
+ expect(result.isSameOrigin).toBe(false);
40
+ });
41
+
42
+ it('blocks authenticated fetch when allowlist is missing', () => {
43
+ expect(() =>
44
+ resolveConfigFetchPolicy('https://noTrustList.example.com/config.json', {
45
+ userAuthenticationService: {
46
+ getAuthorizationHeader: () => ({ Authorization: 'Bearer token123' }),
47
+ },
48
+ })
49
+ ).toThrow('Blocked remote configuration origin');
50
+ });
51
+
52
+ it('allows same-origin in authenticated environments without allowlist', () => {
53
+ const result = resolveConfigFetchPolicy('/protected/config.json', {
54
+ userAuthenticationService: {
55
+ getAuthorizationHeader: () => ({ Authorization: 'Bearer token123' }),
56
+ },
57
+ });
58
+
59
+ expect(result.normalizedUrl).toBe(`${window.location.origin}/protected/config.json`);
60
+ expect(result.isAuthenticated).toBe(true);
61
+ expect(result.isSameOrigin).toBe(true);
62
+ });
63
+
64
+ it('rejects embedded userinfo in config URLs', () => {
65
+ expect(() =>
66
+ resolveConfigFetchPolicy('https://user:pass@trusted.example.com/config.json', {
67
+ allowedOrigins: ['https://trusted.example.com'],
68
+ userAuthenticationService: {
69
+ getAuthorizationHeader: () => ({ Authorization: 'Bearer token123' }),
70
+ },
71
+ })
72
+ ).toThrow('URL userinfo is not allowed for dynamic datasource configuration');
73
+ });
74
+ });
75
+
76
+ describe('fetchConfigJson', () => {
77
+ const originalFetch = global.fetch;
78
+
79
+ beforeEach(() => {
80
+ global.fetch = jest.fn();
81
+ });
82
+
83
+ afterEach(() => {
84
+ jest.restoreAllMocks();
85
+ global.fetch = originalFetch;
86
+ });
87
+
88
+ it('uses hardened fetch options for unauthenticated cross-origin requests', async () => {
89
+ global.fetch.mockResolvedValue({
90
+ status: 200,
91
+ ok: true,
92
+ json: async () => ({ ok: true }),
93
+ });
94
+
95
+ await fetchConfigJson({
96
+ normalizedUrl: 'https://example.com/config.json',
97
+ isAuthenticated: false,
98
+ isSameOrigin: false,
99
+ });
100
+
101
+ expect(global.fetch).toHaveBeenCalledWith(
102
+ 'https://example.com/config.json',
103
+ expect.objectContaining({
104
+ method: 'GET',
105
+ mode: 'cors',
106
+ credentials: 'same-origin',
107
+ redirect: 'error',
108
+ referrerPolicy: 'no-referrer',
109
+ })
110
+ );
111
+ });
112
+
113
+ it('uses hardened fetch options for unauthenticated same-origin requests', async () => {
114
+ global.fetch.mockResolvedValue({
115
+ status: 200,
116
+ ok: true,
117
+ json: async () => ({ ok: true }),
118
+ });
119
+
120
+ await fetchConfigJson({
121
+ normalizedUrl: `${window.location.origin}/protected/config.json`,
122
+ isAuthenticated: false,
123
+ isSameOrigin: true,
124
+ });
125
+
126
+ expect(global.fetch).toHaveBeenCalledWith(
127
+ `${window.location.origin}/protected/config.json`,
128
+ expect.objectContaining({
129
+ method: 'GET',
130
+ mode: 'cors',
131
+ credentials: 'same-origin',
132
+ redirect: 'error',
133
+ referrerPolicy: 'no-referrer',
134
+ })
135
+ );
136
+ });
137
+
138
+ it('uses hardened fetch options in authenticated environments', async () => {
139
+ global.fetch.mockResolvedValue({
140
+ status: 200,
141
+ ok: true,
142
+ json: async () => ({ ok: true }),
143
+ });
144
+
145
+ await fetchConfigJson({
146
+ normalizedUrl: 'https://trusted.example.com/config.json',
147
+ isAuthenticated: true,
148
+ isSameOrigin: false,
149
+ });
150
+
151
+ expect(global.fetch).toHaveBeenCalledWith(
152
+ 'https://trusted.example.com/config.json',
153
+ expect.objectContaining({
154
+ method: 'GET',
155
+ mode: 'cors',
156
+ credentials: 'same-origin',
157
+ redirect: 'error',
158
+ referrerPolicy: 'no-referrer',
159
+ })
160
+ );
161
+ });
162
+ });
163
+ });
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Remembers the series descriptions that were last used to store something, so
3
+ * that storing the next one can offer them again. The descriptions are kept per
4
+ * type of item being stored (`SEG`, `RTSTRUCT`, `SR`, ...), most recently used
5
+ * first, in local storage so that they survive a reload.
6
+ *
7
+ * A `maxCount` of 0 disables this entirely - nothing is remembered and nothing
8
+ * is offered.
9
+ */
10
+
11
+ const STORAGE_KEY = 'ohif.seriesDescriptionHistory';
12
+
13
+ type History = Record<string, string[]>;
14
+
15
+ /**
16
+ * Local storage is unavailable in some browser configurations, and can contain
17
+ * anything at all, so every read is defensive and a failure just means there is
18
+ * no history.
19
+ */
20
+ function readHistory(): History {
21
+ try {
22
+ const stored = window.localStorage.getItem(STORAGE_KEY);
23
+ const parsed = stored ? JSON.parse(stored) : null;
24
+ return parsed && typeof parsed === 'object' ? parsed : {};
25
+ } catch (error) {
26
+ console.debug('Unable to read the series description history', error);
27
+ return {};
28
+ }
29
+ }
30
+
31
+ function isSameDescription(a: string, b: string) {
32
+ return a.toLowerCase() === b.toLowerCase();
33
+ }
34
+
35
+ /**
36
+ * The descriptions last used for `itemType`, most recent first, at most
37
+ * `maxCount` of them.
38
+ */
39
+ export function getSeriesDescriptionHistory(itemType: string, maxCount: number): string[] {
40
+ if (!itemType || !(maxCount > 0)) {
41
+ return [];
42
+ }
43
+
44
+ const descriptions = readHistory()[itemType];
45
+ if (!Array.isArray(descriptions)) {
46
+ return [];
47
+ }
48
+
49
+ return descriptions
50
+ .filter(description => typeof description === 'string' && !!description.trim())
51
+ .slice(0, maxCount);
52
+ }
53
+
54
+ /**
55
+ * Records `description` as the most recently used one for `itemType`, dropping
56
+ * any earlier use of it and any entry past `maxCount`.
57
+ */
58
+ export function rememberSeriesDescription(
59
+ itemType: string,
60
+ description: string,
61
+ maxCount: number
62
+ ): void {
63
+ const trimmed = description?.trim();
64
+ if (!itemType || !trimmed || !(maxCount > 0)) {
65
+ return;
66
+ }
67
+
68
+ const history = readHistory();
69
+ const previous = Array.isArray(history[itemType]) ? history[itemType] : [];
70
+
71
+ history[itemType] = [
72
+ trimmed,
73
+ ...previous.filter(
74
+ entry => typeof entry === 'string' && !!entry.trim() && !isSameDescription(entry, trimmed)
75
+ ),
76
+ ].slice(0, maxCount);
77
+
78
+ try {
79
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(history));
80
+ } catch (error) {
81
+ console.debug('Unable to store the series description history', error);
82
+ }
83
+ }
@@ -0,0 +1,24 @@
1
+ import toNumber from '@ohif/core/src/utils/toNumber';
2
+
3
+ /**
4
+ * Check if all voxels in series images has same number of components (samplesPerPixel)
5
+ * @param {*} instances
6
+ * @returns
7
+ */
8
+ export default function areAllImageComponentsEqual(instances: Array<any>): boolean {
9
+ if (!instances?.length) {
10
+ return false;
11
+ }
12
+ const firstImage = instances[0];
13
+ const firstImageSamplesPerPixel = toNumber(firstImage.SamplesPerPixel);
14
+
15
+ for (let i = 1; i < instances.length; i++) {
16
+ const instance = instances[i];
17
+ const { SamplesPerPixel } = instance;
18
+
19
+ if (SamplesPerPixel !== firstImageSamplesPerPixel) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ }
@@ -0,0 +1,41 @@
1
+ import areAllImageDimensionsEqual from './areAllImageDimensionsEqual';
2
+
3
+ describe('areAllImageDimensionsEqual', () => {
4
+ it('should return false when no instances are provided', () => {
5
+ expect(areAllImageDimensionsEqual([])).toBe(false);
6
+ expect(areAllImageDimensionsEqual([] as any)).toBe(false);
7
+ });
8
+
9
+ it('should return true when all instances have the same dimensions', () => {
10
+ const instances = [
11
+ { Rows: '512', Columns: '512' },
12
+ { Rows: '512', Columns: '512' },
13
+ { Rows: '512', Columns: '512' }
14
+ ];
15
+ expect(areAllImageDimensionsEqual(instances)).toBe(true);
16
+ });
17
+
18
+ it('should return true when comparing string and number dimensions of same value', () => {
19
+ const instances = [
20
+ { Rows: 512, Columns: 512 },
21
+ { Rows: '512', Columns: '512' }
22
+ ];
23
+ expect(areAllImageDimensionsEqual(instances)).toBe(true);
24
+ });
25
+
26
+ it('should return false when instances have different dimensions', () => {
27
+ const instances = [
28
+ { Rows: '512', Columns: '512' },
29
+ { Rows: '256', Columns: '512' }
30
+ ];
31
+ expect(areAllImageDimensionsEqual(instances)).toBe(false);
32
+ });
33
+
34
+ it('should return false when dimensions are invalid strings', () => {
35
+ const instances = [
36
+ { Rows: '512', Columns: '512' },
37
+ { Rows: 'invalid', Columns: '512' }
38
+ ];
39
+ expect(areAllImageDimensionsEqual(instances)).toBe(false);
40
+ });
41
+ });
@@ -0,0 +1,27 @@
1
+ import { utils } from '@ohif/core';
2
+
3
+ const { toNumber } = utils;
4
+
5
+ /**
6
+ * Check if the frames in a series has different dimensions
7
+ * @param {*} instances
8
+ * @returns
9
+ */
10
+ export default function areAllImageDimensionsEqual(instances: Array<any>): boolean {
11
+ if (!instances?.length) {
12
+ return false;
13
+ }
14
+ const firstImage = instances[0];
15
+ const firstImageRows = toNumber(firstImage.Rows);
16
+ const firstImageColumns = toNumber(firstImage.Columns);
17
+
18
+ for (let i = 1; i < instances.length; i++) {
19
+ const instance = instances[i];
20
+ const { Rows, Columns } = instance;
21
+
22
+ if (toNumber(Rows) !== firstImageRows || toNumber(Columns) !== firstImageColumns) {
23
+ return false;
24
+ }
25
+ }
26
+ return true;
27
+ }
@@ -0,0 +1,75 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import toNumber from '@ohif/core/src/utils/toNumber';
3
+ import { _getPerpendicularDistance } from '@ohif/core/src/utils/isDisplaySetReconstructable';
4
+ import { utils } from '@ohif/core';
5
+
6
+ const { calculateScanAxisNormal } = utils;
7
+
8
+ /**
9
+ * Checks if there is a position shift between consecutive frames
10
+ * @param {*} previousPosition
11
+ * @param {*} actualPosition
12
+ * @param {*} scanAxisNormal
13
+ * @param {*} averageSpacingBetweenFrames
14
+ * @returns
15
+ */
16
+ function _checkSeriesPositionShift(
17
+ previousPosition,
18
+ actualPosition,
19
+ scanAxisNormal,
20
+ averageSpacingBetweenFrames
21
+ ) {
22
+ // predicted position should be the previous position added by the multiplication
23
+ // of the scanAxisNormal and the average spacing between frames
24
+ const predictedPosition = vec3.scaleAndAdd(
25
+ vec3.create(),
26
+ previousPosition,
27
+ scanAxisNormal,
28
+ averageSpacingBetweenFrames
29
+ );
30
+ return vec3.distance(actualPosition, predictedPosition) > averageSpacingBetweenFrames;
31
+ }
32
+
33
+ /**
34
+ * Checks if a series has position shifts between consecutive frames
35
+ * @param {*} instances
36
+ * @returns
37
+ */
38
+ export default function areAllImagePositionsEqual(instances: Array<any>): boolean {
39
+ if (!instances?.length) {
40
+ return false;
41
+ }
42
+ const firstImageOrientationPatient = toNumber(instances[0].ImageOrientationPatient);
43
+ if (!firstImageOrientationPatient) {
44
+ return false;
45
+ }
46
+ const scanAxisNormal = calculateScanAxisNormal(firstImageOrientationPatient);
47
+ const firstImagePositionPatient = toNumber(instances[0].ImagePositionPatient);
48
+ const lastIpp = toNumber(instances[instances.length - 1].ImagePositionPatient);
49
+
50
+ if (!firstImagePositionPatient || !lastIpp) {
51
+ return false;
52
+ }
53
+
54
+ const averageSpacingBetweenFrames =
55
+ _getPerpendicularDistance(firstImagePositionPatient, lastIpp) / (instances.length - 1);
56
+
57
+ let previousImagePositionPatient = firstImagePositionPatient;
58
+ for (let i = 1; i < instances.length; i++) {
59
+ const instance = instances[i];
60
+ const imagePositionPatient = toNumber(instance.ImagePositionPatient);
61
+
62
+ if (
63
+ _checkSeriesPositionShift(
64
+ previousImagePositionPatient,
65
+ imagePositionPatient,
66
+ scanAxisNormal,
67
+ averageSpacingBetweenFrames
68
+ )
69
+ ) {
70
+ return false;
71
+ }
72
+ previousImagePositionPatient = imagePositionPatient;
73
+ }
74
+ return true;
75
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ _getPerpendicularDistance,
3
+ _getSpacingIssue,
4
+ reconstructionIssues,
5
+ } from '@ohif/core/src/utils/isDisplaySetReconstructable';
6
+ import { DisplaySetMessage } from '@ohif/core';
7
+ import toNumber from '@ohif/core/src/utils/toNumber';
8
+ import { DisplaySetMessageList } from '@ohif/core';
9
+
10
+ /**
11
+ * Checks if series has spacing issues
12
+ * @param {*} instances
13
+ * @param {*} warnings
14
+ */
15
+ export default function areAllImageSpacingEqual(
16
+ instances: Array<any>,
17
+ messages: DisplaySetMessageList
18
+ ): void {
19
+ if (!instances?.length) {
20
+ return;
21
+ }
22
+ const firstImagePositionPatient = toNumber(instances[0].ImagePositionPatient);
23
+ if (!firstImagePositionPatient) {
24
+ return;
25
+ }
26
+ const lastIpp = toNumber(instances[instances.length - 1].ImagePositionPatient);
27
+ if (!lastIpp) {
28
+ return;
29
+ }
30
+ const averageSpacingBetweenFrames =
31
+ _getPerpendicularDistance(firstImagePositionPatient, lastIpp) / (instances.length - 1);
32
+
33
+ let previousImagePositionPatient = firstImagePositionPatient;
34
+
35
+ const issuesFound = [];
36
+ for (let i = 1; i < instances.length; i++) {
37
+ const instance = instances[i];
38
+ const imagePositionPatient = toNumber(instance.ImagePositionPatient);
39
+
40
+ const spacingBetweenFrames = _getPerpendicularDistance(
41
+ imagePositionPatient,
42
+ previousImagePositionPatient
43
+ );
44
+
45
+ const spacingIssue = _getSpacingIssue(spacingBetweenFrames, averageSpacingBetweenFrames);
46
+
47
+ if (spacingIssue) {
48
+ const issue = spacingIssue.issue;
49
+
50
+ // avoid multiple warning of the same thing
51
+ if (!issuesFound.includes(issue)) {
52
+ issuesFound.push(issue);
53
+ if (issue === reconstructionIssues.MISSING_FRAMES) {
54
+ messages.addMessage(DisplaySetMessage.CODES.MISSING_FRAMES);
55
+ } else if (issue === reconstructionIssues.IRREGULAR_SPACING) {
56
+ messages.addMessage(DisplaySetMessage.CODES.IRREGULAR_SPACING);
57
+ }
58
+ }
59
+ // we just want to find issues not how many
60
+ if (issuesFound.length > 1) {
61
+ break;
62
+ }
63
+ }
64
+ previousImagePositionPatient = imagePositionPatient;
65
+ }
66
+ }
@@ -0,0 +1,25 @@
1
+ import {
2
+ hasPixelMeasurements,
3
+ hasOrientation,
4
+ hasPosition,
5
+ } from '@ohif/core/src/utils/isDisplaySetReconstructable';
6
+ import { DisplaySetMessage, DisplaySetMessageList } from '@ohif/core';
7
+
8
+ /**
9
+ * Check various multi frame issues. It calls OHIF core functions
10
+ * @param {*} multiFrameInstance
11
+ * @param {*} warnings
12
+ */
13
+ export default function checkMultiFrame(multiFrameInstance, messages: DisplaySetMessageList): void {
14
+ if (!hasPixelMeasurements(multiFrameInstance)) {
15
+ messages.addMessage(DisplaySetMessage.CODES.MULTIFRAME_NO_PIXEL_MEASUREMENTS);
16
+ }
17
+
18
+ if (!hasOrientation(multiFrameInstance)) {
19
+ messages.addMessage(DisplaySetMessage.CODES.MULTIFRAME_NO_ORIENTATION);
20
+ }
21
+
22
+ if (!hasPosition(multiFrameInstance)) {
23
+ messages.addMessage(DisplaySetMessage.CODES.MULTIFRAME_NO_POSITION_INFORMATION);
24
+ }
25
+ }
@@ -0,0 +1,36 @@
1
+ import areAllImageDimensionsEqual from './areAllImageDimensionsEqual';
2
+ import areAllImageComponentsEqual from './areAllImageComponentsEqual';
3
+ import areAllImagePositionsEqual from './areAllImagePositionsEqual';
4
+ import areAllImageSpacingEqual from './areAllImageSpacingEqual';
5
+ import { DisplaySetMessage, DisplaySetMessageList, utils } from '@ohif/core';
6
+
7
+ const { areAllImageOrientationsEqual } = utils;
8
+
9
+ /**
10
+ * Runs various checks in a single frame series
11
+ * @param {*} instances
12
+ * @param {*} warnings
13
+ */
14
+ export default function checkSingleFrames(
15
+ instances: Array<any>,
16
+ messages: DisplaySetMessageList
17
+ ): void {
18
+ if (instances.length > 2) {
19
+ if (!areAllImageDimensionsEqual(instances)) {
20
+ messages.addMessage(DisplaySetMessage.CODES.INCONSISTENT_DIMENSIONS);
21
+ }
22
+
23
+ if (!areAllImageComponentsEqual(instances)) {
24
+ messages.addMessage(DisplaySetMessage.CODES.INCONSISTENT_COMPONENTS);
25
+ }
26
+
27
+ if (!areAllImageOrientationsEqual(instances)) {
28
+ messages.addMessage(DisplaySetMessage.CODES.INCONSISTENT_ORIENTATIONS);
29
+ }
30
+
31
+ if (!areAllImagePositionsEqual(instances)) {
32
+ messages.addMessage(DisplaySetMessage.CODES.INCONSISTENT_POSITION_INFORMATION);
33
+ }
34
+ areAllImageSpacingEqual(instances, messages);
35
+ }
36
+ }