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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/dist/ohif-extension-default.umd.js +1 -1
  2. package/package.json +9 -6
  3. package/src/Actions/createReportAsync.tsx +45 -0
  4. package/src/Components/DataSourceConfigurationComponent.tsx +142 -0
  5. package/src/Components/DataSourceConfigurationModalComponent.tsx +200 -0
  6. package/src/Components/ItemListComponent.tsx +95 -0
  7. package/src/Components/LineChartViewport/LineChartViewport.tsx +31 -0
  8. package/src/Components/LineChartViewport/index.ts +1 -0
  9. package/src/Components/MoreDropdownMenu.tsx +112 -0
  10. package/src/Components/ProgressDropdownWithService.tsx +101 -0
  11. package/src/Components/SidePanelWithServices.tsx +122 -0
  12. package/src/CustomizableContextMenu/ContextMenuController.tsx +216 -0
  13. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.test.js +29 -0
  14. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.ts +176 -0
  15. package/src/CustomizableContextMenu/index.ts +5 -0
  16. package/src/CustomizableContextMenu/types.ts +126 -0
  17. package/src/DataSourceConfigurationAPI/GoogleCloudDataSourceConfigurationAPI.ts +236 -0
  18. package/src/DicomJSONDataSource/index.js +326 -0
  19. package/src/DicomLocalDataSource/index.js +273 -0
  20. package/src/DicomTagBrowser/DicomTagBrowser.css +49 -0
  21. package/src/DicomTagBrowser/DicomTagBrowser.tsx +454 -0
  22. package/src/DicomTagBrowser/DicomTagTable.tsx +311 -0
  23. package/src/DicomWebDataSource/dcm4cheeReject.js +45 -0
  24. package/src/DicomWebDataSource/exampleInstances.js +280 -0
  25. package/src/DicomWebDataSource/index.ts +808 -0
  26. package/src/DicomWebDataSource/qido.js +215 -0
  27. package/src/DicomWebDataSource/retrieveBulkData.test.ts +35 -0
  28. package/src/DicomWebDataSource/retrieveBulkData.ts +31 -0
  29. package/src/DicomWebDataSource/retrieveRendered.test.ts +147 -0
  30. package/src/DicomWebDataSource/retrieveRendered.ts +141 -0
  31. package/src/DicomWebDataSource/retrieveStudyMetadata.js +108 -0
  32. package/src/DicomWebDataSource/retrieveStudyMetadata.test.js +75 -0
  33. package/src/DicomWebDataSource/retrieveThumbnail.ts +346 -0
  34. package/src/DicomWebDataSource/serviceUrls.test.ts +143 -0
  35. package/src/DicomWebDataSource/utils/StaticWadoClient.ts +272 -0
  36. package/src/DicomWebDataSource/utils/cleanDenaturalizedDataset.ts +78 -0
  37. package/src/DicomWebDataSource/utils/findIndexOfString.ts +47 -0
  38. package/src/DicomWebDataSource/utils/fixBulkDataURI.test.ts +68 -0
  39. package/src/DicomWebDataSource/utils/fixBulkDataURI.ts +78 -0
  40. package/src/DicomWebDataSource/utils/fixMultiValueKeys.ts +12 -0
  41. package/src/DicomWebDataSource/utils/fixMultipart.ts +70 -0
  42. package/src/DicomWebDataSource/utils/getImageId.js +54 -0
  43. package/src/DicomWebDataSource/utils/getWADORSImageId.js +51 -0
  44. package/src/DicomWebDataSource/utils/index.ts +9 -0
  45. package/src/DicomWebDataSource/utils/retrieveMetadataFiltered.js +61 -0
  46. package/src/DicomWebDataSource/wado/retrieveMetadata.js +41 -0
  47. package/src/DicomWebDataSource/wado/retrieveMetadataLoader.js +64 -0
  48. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderAsync.js +159 -0
  49. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderSync.js +58 -0
  50. package/src/DicomWebProxyDataSource/index.ts +90 -0
  51. package/src/MergeDataSource/index.test.ts +212 -0
  52. package/src/MergeDataSource/index.ts +319 -0
  53. package/src/MergeDataSource/types.ts +46 -0
  54. package/src/Panels/DataSourceSelector.tsx +55 -0
  55. package/src/Panels/StudyBrowser/PanelStudyBrowser.tsx +612 -0
  56. package/src/Panels/StudyBrowser/PanelStudyBrowserHeader.tsx +88 -0
  57. package/src/Panels/StudyBrowser/constants/actionIcons.ts +12 -0
  58. package/src/Panels/StudyBrowser/constants/index.ts +4 -0
  59. package/src/Panels/StudyBrowser/constants/viewPresets.ts +16 -0
  60. package/src/Panels/StudyBrowser/resolveThumbnailDetails.test.ts +197 -0
  61. package/src/Panels/StudyBrowser/resolveThumbnailDetails.ts +132 -0
  62. package/src/Panels/StudyBrowser/types/actionIcon.ts +9 -0
  63. package/src/Panels/StudyBrowser/types/index.ts +4 -0
  64. package/src/Panels/StudyBrowser/types/viewPreset.ts +7 -0
  65. package/src/Panels/WrappedPanelStudyBrowser.tsx +61 -0
  66. package/src/Panels/createReportDialogPrompt.tsx +128 -0
  67. package/src/Panels/debounce.js +25 -0
  68. package/src/Panels/getImageSrcFromImageId.js +16 -0
  69. package/src/Panels/getStudiesForPatientByMRN.js +19 -0
  70. package/src/Panels/index.js +5 -0
  71. package/src/Panels/requestDisplaySetCreationForStudy.js +19 -0
  72. package/src/SOPClassHandlers/chartSOPClassHandler.test.ts +81 -0
  73. package/src/SOPClassHandlers/chartSOPClassHandler.ts +127 -0
  74. package/src/Toolbar/ToolBoxWrapper.tsx +64 -0
  75. package/src/Toolbar/ToolButtonListWrapper.tsx +77 -0
  76. package/src/Toolbar/ToolButtonWrapper.tsx +32 -0
  77. package/src/Toolbar/ToolRowWrapper.tsx +41 -0
  78. package/src/Toolbar/Toolbar.tsx +98 -0
  79. package/src/Toolbar/ToolbarDivider.tsx +5 -0
  80. package/src/Toolbar/ToolbarLayoutSelector.tsx +195 -0
  81. package/src/Toolbar/index.ts +7 -0
  82. package/src/ViewerLayout/HeaderPatientInfo/HeaderPatientInfo.tsx +96 -0
  83. package/src/ViewerLayout/HeaderPatientInfo/index.js +3 -0
  84. package/src/ViewerLayout/HeaderUndoRedo.tsx +47 -0
  85. package/src/ViewerLayout/ResizablePanelsHook.tsx +334 -0
  86. package/src/ViewerLayout/ViewerHeader.tsx +124 -0
  87. package/src/ViewerLayout/constants/panels.ts +42 -0
  88. package/src/ViewerLayout/index.tsx +227 -0
  89. package/src/ViewerLayout/useUndoRedoState.ts +75 -0
  90. package/src/__tests__/commandsModuleToggleOneUp.test.ts +147 -0
  91. package/src/commandsModule.ts +970 -0
  92. package/src/customizations/aboutModalCustomization.tsx +42 -0
  93. package/src/customizations/appearanceModalCustomization.tsx +143 -0
  94. package/src/customizations/contextMenuCustomization.ts +25 -0
  95. package/src/customizations/contextMenuUICustomization.ts +5 -0
  96. package/src/customizations/customRoutesCustomization.ts +6 -0
  97. package/src/customizations/dataSourceConfigurationCustomization.ts +19 -0
  98. package/src/customizations/datasourcesCustomization.tsx +14 -0
  99. package/src/customizations/defaultContextMenuCustomization.ts +22 -0
  100. package/src/customizations/hangingProtocolsCustomization.ts +15 -0
  101. package/src/customizations/headerRightSideCustomization.ts +19 -0
  102. package/src/customizations/helloPageCustomization.tsx +14 -0
  103. package/src/customizations/hideHeaderUndoRedoCustomization.ts +22 -0
  104. package/src/customizations/hotkeyBindingsCustomization.ts +5 -0
  105. package/src/customizations/instanceSortingCriteriaCustomization.ts +6 -0
  106. package/src/customizations/labellingFlowCustomization.tsx +5 -0
  107. package/src/customizations/loadingIndicatorProgressCustomization.tsx +5 -0
  108. package/src/customizations/loadingIndicatorTotalPercentCustomization.tsx +5 -0
  109. package/src/customizations/menuContentCustomization.tsx +67 -0
  110. package/src/customizations/metadataContextCustomization.test.ts +22 -0
  111. package/src/customizations/metadataContextCustomization.ts +28 -0
  112. package/src/customizations/metadataDisplaySetCustomization.ts +55 -0
  113. package/src/customizations/missingReferenceDisplaySetHandler.ts +5 -0
  114. package/src/customizations/multimonitorCustomization.ts +63 -0
  115. package/src/customizations/notificationCustomization.ts +29 -0
  116. package/src/customizations/onDropHandlerCustomization.ts +5 -0
  117. package/src/customizations/onboardingCustomization.ts +200 -0
  118. package/src/customizations/overlayItemCustomization.tsx +33 -0
  119. package/src/customizations/progressDropdownCustomization.ts +5 -0
  120. package/src/customizations/progressLoadingBarCustomization.tsx +5 -0
  121. package/src/customizations/reportDialogCustomization.test.ts +701 -0
  122. package/src/customizations/reportDialogCustomization.tsx +661 -0
  123. package/src/customizations/sortingCriteriaCustomization.ts +14 -0
  124. package/src/customizations/studyBrowserCustomization.test.ts +69 -0
  125. package/src/customizations/studyBrowserCustomization.ts +95 -0
  126. package/src/customizations/thumbnailDetailsCustomization.ts +91 -0
  127. package/src/customizations/userPreferencesCustomization.tsx +342 -0
  128. package/src/customizations/workListCustomization.ts +107 -0
  129. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.test.ts +181 -0
  130. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.ts +240 -0
  131. package/src/displaySetSplitting/makeImageSetDisplaySet.ts +276 -0
  132. package/src/displaySetSplitting/stackSopClassUids.ts +60 -0
  133. package/src/displaySetSplitting/urlSplitModules.test.ts +333 -0
  134. package/src/findViewportsByPosition.ts +102 -0
  135. package/src/getCustomizationModule.tsx +109 -0
  136. package/src/getDataSourcesModule.js +44 -0
  137. package/src/getDisplaySetMessages.ts +54 -0
  138. package/src/getDisplaySetsFromUnsupportedSeries.js +63 -0
  139. package/src/getDisplaySetsFromUnsupportedSeries.test.js +14 -0
  140. package/src/getHangingProtocolModule.js +155 -0
  141. package/src/getLayoutTemplateModule.js +28 -0
  142. package/src/getPTImageIdInstanceMetadata.test.ts +102 -0
  143. package/src/getPTImageIdInstanceMetadata.ts +124 -0
  144. package/src/getPanelModule.tsx +29 -0
  145. package/src/getSopClassHandlerModule.js +152 -0
  146. package/src/getSopClassHandlerModule.test.js +78 -0
  147. package/src/getToolbarModule.tsx +63 -0
  148. package/src/getViewportModule.tsx +12 -0
  149. package/src/hangingprotocols/hpCompare.ts +189 -0
  150. package/src/hangingprotocols/hpEcgCustomization.test.ts +104 -0
  151. package/src/hangingprotocols/hpMNGrid.test.ts +120 -0
  152. package/src/hangingprotocols/hpMNGrid.ts +419 -0
  153. package/src/hangingprotocols/hpMammo.ts +202 -0
  154. package/src/hangingprotocols/hpScale.ts +132 -0
  155. package/src/hangingprotocols/index.ts +16 -0
  156. package/src/hangingprotocols/protocolMatchChanges.test.ts +73 -0
  157. package/src/hangingprotocols/utils/isNewestOfModality.ts +19 -0
  158. package/src/hangingprotocols/utils/laterality.ts +9 -0
  159. package/src/hangingprotocols/utils/mammoDisplaySetSelector.ts +214 -0
  160. package/src/hangingprotocols/utils/registerHangingProtocolAttributes.ts +14 -0
  161. package/src/hangingprotocols/utils/seriesSelectors.ts +62 -0
  162. package/src/hangingprotocols/utils/studySelectors.ts +14 -0
  163. package/src/hangingprotocols/utils/viewCode.test.js +25 -0
  164. package/src/hangingprotocols/utils/viewCode.ts +17 -0
  165. package/src/hangingprotocols/utils/viewportOptions.ts +18 -0
  166. package/src/hooks/usePatientInfo.tsx +63 -0
  167. package/src/id.js +5 -0
  168. package/src/index.ts +113 -0
  169. package/src/init.ts +169 -0
  170. package/src/stores/index.ts +7 -0
  171. package/src/stores/useDisplaySetSelectorStore.ts +83 -0
  172. package/src/stores/useHangingProtocolStageIndexStore.ts +76 -0
  173. package/src/stores/useToggleHangingProtocolStore.ts +76 -0
  174. package/src/stores/useToggleOneUpViewportGridStore.ts +19 -0
  175. package/src/stores/useUIStateStore.ts +87 -0
  176. package/src/stores/useViewportGridStore.ts +89 -0
  177. package/src/stores/useViewportsByPositionStore.ts +100 -0
  178. package/src/types/AppTypes.ts +20 -0
  179. package/src/types/commandModuleTypes.tsx +6 -0
  180. package/src/utils/Toolbox.tsx +123 -0
  181. package/src/utils/_shared/PROMPT_RESPONSES.ts +10 -0
  182. package/src/utils/addIcon.ts +6 -0
  183. package/src/utils/appendFrameQueryToImageId.js +9 -0
  184. package/src/utils/callInputDialog.tsx +126 -0
  185. package/src/utils/colorPickerDialog.css +4 -0
  186. package/src/utils/colorPickerDialog.tsx +45 -0
  187. package/src/utils/createRenderedRetrieve.js +32 -0
  188. package/src/utils/createRenderedRetrieve.test.js +46 -0
  189. package/src/utils/dicomWriter.test.ts +228 -0
  190. package/src/utils/dicomWriter.ts +110 -0
  191. package/src/utils/getBulkdataValue.js +45 -0
  192. package/src/utils/getBulkdataValue.test.js +105 -0
  193. package/src/utils/getDirectURL.test.ts +207 -0
  194. package/src/utils/getDirectURL.ts +65 -0
  195. package/src/utils/getSRSeriesAndInstanceNumber.js +48 -0
  196. package/src/utils/index.ts +2 -0
  197. package/src/utils/layerConfigurationUtils.ts +202 -0
  198. package/src/utils/promptLabelAnnotation.js +47 -0
  199. package/src/utils/promptSaveReport.test.ts +106 -0
  200. package/src/utils/promptSaveReport.tsx +117 -0
  201. package/src/utils/registerNaturalizedDatasetForLocalWadouri.js +146 -0
  202. package/src/utils/registerNaturalizedDatasetForLocalWadouri.test.js +177 -0
  203. package/src/utils/registerStoredInstanceImageId.test.ts +73 -0
  204. package/src/utils/registerStoredInstanceImageId.ts +66 -0
  205. package/src/utils/reuseCachedLayouts.ts +92 -0
  206. package/src/utils/secureConfigFetch.js +115 -0
  207. package/src/utils/secureConfigFetch.test.js +163 -0
  208. package/src/utils/seriesDescriptionHistory.ts +83 -0
  209. package/src/utils/validations/areAllImageComponentsEqual.ts +24 -0
  210. package/src/utils/validations/areAllImageDimensionsEqual.test.ts +41 -0
  211. package/src/utils/validations/areAllImageDimensionsEqual.ts +27 -0
  212. package/src/utils/validations/areAllImagePositionsEqual.ts +75 -0
  213. package/src/utils/validations/areAllImageSpacingEqual.ts +66 -0
  214. package/src/utils/validations/checkMultiframe.ts +25 -0
  215. package/src/utils/validations/checkSingleFrames.ts +36 -0
@@ -0,0 +1,126 @@
1
+ import { Types } from '@ohif/core';
2
+
3
+ /**
4
+ * SelectorProps are properties used to decide whether to select a menu or
5
+ * menu item for display.
6
+ * An instance of SelectorProps is provided to the selector functions, which
7
+ * return true to include the item or false to exclude it.
8
+ * The point of this is to allow more specific context menus which hide
9
+ * non-relevant menu options, optimizing the speed of selection of menus
10
+ */
11
+ export interface SelectorProps {
12
+ // If the context menu is invoked in the context of a measurement, then it
13
+ // will contain the nearby tool data.
14
+ nearbyToolData?: Record<string, unknown>;
15
+
16
+ // The tool name for the nearby tool
17
+ toolName?: string;
18
+
19
+ // An annotation UID - this will be present if nearbyToolData is present.
20
+ uid?: string;
21
+
22
+ // If the context menu is invoked on an active viewport, then it will contain
23
+ // the first display set.
24
+ displaySet?: Record<string, unknown>;
25
+
26
+ // The triggering event - can be used to determine key modifiers
27
+ event?: Event;
28
+
29
+ // Any other properties
30
+ [propertyName: string]: unknown;
31
+ }
32
+
33
+ /**
34
+ * The type of item actually required for the ContextMenu UI display
35
+ */
36
+ export type UIMenuItem = {
37
+ label: string;
38
+ // Called when the item is selected
39
+ action?: (itemRef, componentProps) => void;
40
+ };
41
+
42
+ /**
43
+ * A MenuItem is a single line item within a menu, and specifies a selectable
44
+ * value for the menu.
45
+ */
46
+ export interface MenuItem {
47
+ id?: string;
48
+ /**
49
+ * The customization type is used to apply preset values to this item
50
+ * when registered with the customization service.
51
+ */
52
+ inheritsFrom?: string;
53
+
54
+ // The label is the value to show in the menu for this item
55
+ label?: string;
56
+
57
+ // Delegating items are used to include other sub-menus inline within
58
+ // this menu. That allows sharing part of the menu structure, but also,
59
+ // more importantly to use a single selector function to include/exclude
60
+ // and entire section of sub-menu.
61
+ // See the `siteSelectionSubMenu` within the example `findingsMenu`
62
+ // for an example
63
+ delegating?: boolean;
64
+
65
+ // A sub-menu is shown when this item is selected or is delegating.
66
+ // This item gives the name of the sub-menu.
67
+ subMenu?: string;
68
+
69
+ // The selector is used to determine if this menu entry will be shown
70
+ // or more importantly, if the delegating subMenu will be included.
71
+ selector?: (props: SelectorProps) => boolean;
72
+
73
+ /** Adapts the item by filling in additional properties as required */
74
+ adaptItem?: (item: MenuItem, props: ContextMenuProps) => UIMenuItem;
75
+
76
+ /** List of commands to run when this item's action is taken. */
77
+ commands?: Types.Command[];
78
+ }
79
+
80
+ /**
81
+ * A menu is a list of menu items, plus a selector.
82
+ * The selector is used to determine whether the menu should be displayed
83
+ * in a given context. The parameters passed to the selector come from
84
+ * the 'selectorProps' value in the options, and are intended to be context
85
+ * specific values containing things like the selected object, the currently
86
+ * displayed study etc so that the context menu can dynamically choose which
87
+ * view to show.
88
+ */
89
+ export interface Menu {
90
+ id: string;
91
+
92
+ /** The customization type is used to apply preset values to this item
93
+ * when registered with the customization service.
94
+ */
95
+ inheritsFrom?: string;
96
+
97
+ // Choose whether this menu applies.
98
+ selector?: Types.Predicate;
99
+
100
+ items: MenuItem[];
101
+ }
102
+
103
+ export type Point = {
104
+ x: number;
105
+ y: number;
106
+ };
107
+
108
+ /**
109
+ * ContextMenuProps is the top level argument used to invoke the context menu
110
+ * itself. It contains the menus available for display, as well as the event
111
+ * and selector props used to decide the menu.
112
+ */
113
+ export type ContextMenuProps = {
114
+ event?: EventTarget;
115
+ menuCustomizationId?: string;
116
+ menuId: string;
117
+ element?: HTMLElement;
118
+
119
+ /** A set of menus to choose from for this context menu */
120
+ menus: Menu[];
121
+
122
+ /** The properties used to decide the menu type */
123
+ selectorProps: SelectorProps;
124
+
125
+ defaultPointsPosition?: [number, number] | [];
126
+ };
@@ -0,0 +1,236 @@
1
+ import { ExtensionManager, Types } from '@ohif/core';
2
+
3
+ /**
4
+ * This file contains the implementations of BaseDataSourceConfigurationAPIItem
5
+ * and BaseDataSourceConfigurationAPI for the Google cloud healthcare API. To
6
+ * better understand this implementation and/or to implement custom implementations,
7
+ * see the platform\core\src\types\DataSourceConfigurationAPI.ts and its JS doc
8
+ * comments as a guide.
9
+ */
10
+
11
+ /**
12
+ * The various Google Cloud Healthcare path item types.
13
+ */
14
+ enum ItemType {
15
+ projects = 0,
16
+ locations = 1,
17
+ datasets = 2,
18
+ dicomStores = 3,
19
+ }
20
+
21
+ interface NamedItem {
22
+ name: string;
23
+ }
24
+ interface Project extends NamedItem {
25
+ projectId: string;
26
+ }
27
+
28
+ const initialUrl = 'https://cloudresourcemanager.googleapis.com/v1';
29
+ const baseHealthcareUrl = 'https://healthcare.googleapis.com/v1';
30
+
31
+ class GoogleCloudDataSourceConfigurationAPIItem
32
+ implements Types.BaseDataSourceConfigurationAPIItem
33
+ {
34
+ id: string;
35
+ name: string;
36
+ url: string;
37
+ itemType: ItemType;
38
+ }
39
+
40
+ class GoogleCloudDataSourceConfigurationAPI implements Types.BaseDataSourceConfigurationAPI {
41
+ private _extensionManager: ExtensionManager;
42
+ private _fetchOptions: { method: string; headers: unknown };
43
+ private _dataSourceName: string;
44
+
45
+ constructor(dataSourceName, servicesManager: AppTypes.ServicesManager, extensionManager) {
46
+ this._dataSourceName = dataSourceName;
47
+ this._extensionManager = extensionManager;
48
+ const userAuthenticationService = servicesManager.services.userAuthenticationService;
49
+ this._fetchOptions = {
50
+ method: 'GET',
51
+ headers: userAuthenticationService.getAuthorizationHeader(),
52
+ };
53
+ }
54
+
55
+ getItemLabels = () => ['Project', 'Location', 'Data set', 'DICOM store'];
56
+
57
+ async initialize(): Promise<Types.BaseDataSourceConfigurationAPIItem[]> {
58
+ const url = `${initialUrl}/projects`;
59
+
60
+ const projects = (await GoogleCloudDataSourceConfigurationAPI._doFetch(
61
+ url,
62
+ ItemType.projects,
63
+ this._fetchOptions
64
+ )) as Array<Project>;
65
+
66
+ if (!projects?.length) {
67
+ return [];
68
+ }
69
+
70
+ const projectItems = projects.map(project => {
71
+ return {
72
+ id: project.projectId,
73
+ name: project.name,
74
+ itemType: ItemType.projects,
75
+ url: `${baseHealthcareUrl}/projects/${project.projectId}`,
76
+ };
77
+ });
78
+
79
+ return projectItems;
80
+ }
81
+
82
+ async setCurrentItem(
83
+ anItem: Types.BaseDataSourceConfigurationAPIItem
84
+ ): Promise<Types.BaseDataSourceConfigurationAPIItem[]> {
85
+ const googleCloudItem = anItem as GoogleCloudDataSourceConfigurationAPIItem;
86
+
87
+ if (googleCloudItem.itemType === ItemType.dicomStores) {
88
+ // Last configurable item, so update the data source configuration.
89
+ const url = `${googleCloudItem.url}/dicomWeb`;
90
+ const dataSourceDefCopy = JSON.parse(
91
+ JSON.stringify(this._extensionManager.getDataSourceDefinition(this._dataSourceName))
92
+ );
93
+ dataSourceDefCopy.configuration = {
94
+ ...dataSourceDefCopy.configuration,
95
+ wadoUriRoot: url,
96
+ qidoRoot: url,
97
+ wadoRoot: url,
98
+ };
99
+
100
+ this._extensionManager.updateDataSourceConfiguration(
101
+ dataSourceDefCopy.sourceName,
102
+ dataSourceDefCopy.configuration
103
+ );
104
+
105
+ return [];
106
+ }
107
+
108
+ const subItemType = googleCloudItem.itemType + 1;
109
+ const subItemField = `${ItemType[subItemType]}`;
110
+
111
+ const url = `${googleCloudItem.url}/${subItemField}`;
112
+
113
+ const fetchedSubItems = await GoogleCloudDataSourceConfigurationAPI._doFetch(
114
+ url,
115
+ subItemType,
116
+ this._fetchOptions
117
+ );
118
+
119
+ if (!fetchedSubItems?.length) {
120
+ return [];
121
+ }
122
+
123
+ const subItems = fetchedSubItems.map(subItem => {
124
+ const nameSplit = subItem.name.split('/');
125
+ return {
126
+ id: subItem.name,
127
+ name: nameSplit[nameSplit.length - 1],
128
+ itemType: subItemType,
129
+ url: `${baseHealthcareUrl}/${subItem.name}`,
130
+ };
131
+ });
132
+
133
+ return subItems;
134
+ }
135
+
136
+ async getConfiguredItems(): Promise<Array<GoogleCloudDataSourceConfigurationAPIItem>> {
137
+ const dataSourceDefinition = this._extensionManager.getDataSourceDefinition(
138
+ this._dataSourceName
139
+ );
140
+
141
+ const url = dataSourceDefinition.configuration.wadoUriRoot;
142
+ const projectsIndex = url.indexOf('projects');
143
+ // Split the configured URL into (essentially) pairs (i.e. item type followed by item)
144
+ // Explicitly: ['projects','aProject','locations','aLocation','datasets','aDataSet','dicomStores','aDicomStore']
145
+ // Note that a partial configuration will have a subset of the above.
146
+ const urlSplit = url.substring(projectsIndex).split('/');
147
+
148
+ const configuredItems = [];
149
+
150
+ for (
151
+ let itemType = 0;
152
+ // the number of configured items is either the max (4) or the number extracted from the url split
153
+ itemType < 4 && (itemType + 1) * 2 < urlSplit.length;
154
+ itemType += 1
155
+ ) {
156
+ if (itemType === ItemType.projects) {
157
+ const projectId = urlSplit[1];
158
+ const projectUrl = `${initialUrl}/projects/${projectId}`;
159
+ const data = await GoogleCloudDataSourceConfigurationAPI._doFetch(
160
+ projectUrl,
161
+ ItemType.projects,
162
+ this._fetchOptions
163
+ );
164
+ const project = data[0] as Project;
165
+ configuredItems.push({
166
+ id: project.projectId,
167
+ name: project.name,
168
+ itemType: itemType,
169
+ url: `${baseHealthcareUrl}/projects/${project.projectId}`,
170
+ });
171
+ } else {
172
+ const relativePath = urlSplit.slice(0, itemType * 2 + 2).join('/');
173
+ configuredItems.push({
174
+ id: relativePath,
175
+ name: urlSplit[itemType * 2 + 1],
176
+ itemType: itemType,
177
+ url: `${baseHealthcareUrl}/${relativePath}`,
178
+ });
179
+ }
180
+ }
181
+
182
+ return configuredItems;
183
+ }
184
+
185
+ /**
186
+ * Fetches an array of items the specified item type.
187
+ * @param urlStr the fetch url
188
+ * @param fetchItemType the type to fetch
189
+ * @param fetchOptions the header options for the fetch (e.g. authorization header)
190
+ * @param fetchSearchParams any search query params; currently only used for paging results
191
+ * @returns an array of items of the specified type
192
+ */
193
+ private static async _doFetch(
194
+ urlStr: string,
195
+ fetchItemType: ItemType,
196
+ fetchOptions = {},
197
+ fetchSearchParams: Record<string, string> = {}
198
+ ): Promise<Array<Project> | Array<NamedItem>> {
199
+ try {
200
+ const url = new URL(urlStr);
201
+ url.search = new URLSearchParams(fetchSearchParams).toString();
202
+
203
+ const response = await fetch(url, fetchOptions);
204
+ const data = await response.json();
205
+ if (response.status >= 200 && response.status < 300 && data != null) {
206
+ if (data.nextPageToken != null) {
207
+ fetchSearchParams.pageToken = data.nextPageToken;
208
+ const subPageData = await this._doFetch(
209
+ urlStr,
210
+ fetchItemType,
211
+ fetchOptions,
212
+ fetchSearchParams
213
+ );
214
+ data[ItemType[fetchItemType]] = data[ItemType[fetchItemType]].concat(subPageData);
215
+ }
216
+ if (data[ItemType[fetchItemType]]) {
217
+ return data[ItemType[fetchItemType]];
218
+ } else if (data.name) {
219
+ return [data];
220
+ } else {
221
+ return [];
222
+ }
223
+ } else {
224
+ const message =
225
+ data?.error?.message ||
226
+ `Error returned from Google Cloud Healthcare: ${response.status} - ${response.statusText}`;
227
+ throw new Error(message);
228
+ }
229
+ } catch (err) {
230
+ const message = err?.message || 'Error occurred during fetch request.';
231
+ throw new Error(message);
232
+ }
233
+ }
234
+ }
235
+
236
+ export { GoogleCloudDataSourceConfigurationAPI };
@@ -0,0 +1,326 @@
1
+ import { DicomMetadataStore, IWebApiDataSource } from '@ohif/core';
2
+ import OHIF from '@ohif/core';
3
+ import qs from 'query-string';
4
+
5
+ import getImageId from '../DicomWebDataSource/utils/getImageId';
6
+ import getDirectURL from '../utils/getDirectURL';
7
+ import { resolveConfigFetchPolicy, fetchConfigJson } from '../utils/secureConfigFetch';
8
+
9
+ const metadataProvider = OHIF.classes.MetadataProvider;
10
+
11
+ const mappings = {
12
+ studyInstanceUid: 'StudyInstanceUID',
13
+ patientId: 'PatientID',
14
+ };
15
+
16
+ let _store = {
17
+ urls: [],
18
+ studyInstanceUIDMap: new Map(), // map of urls to array of study instance UIDs
19
+ // {
20
+ // url: url1
21
+ // studies: [Study1, Study2], // if multiple studies
22
+ // }
23
+ // {
24
+ // url: url2
25
+ // studies: [Study1],
26
+ // }
27
+ // }
28
+ };
29
+
30
+ function wrapSequences(obj) {
31
+ return Object.keys(obj).reduce(
32
+ (acc, key) => {
33
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
34
+ // Recursively wrap sequences for nested objects
35
+ acc[key] = wrapSequences(obj[key]);
36
+ } else {
37
+ acc[key] = obj[key];
38
+ }
39
+ if (key.endsWith('Sequence')) {
40
+ acc[key] = OHIF.utils.addAccessors(acc[key]);
41
+ }
42
+ return acc;
43
+ },
44
+ Array.isArray(obj) ? [] : {}
45
+ );
46
+ }
47
+ const getMetaDataByURL = url => {
48
+ return _store.urls.find(metaData => metaData.url === url);
49
+ };
50
+
51
+ const findStudies = (key, value) => {
52
+ let studies = [];
53
+ _store.urls.map(metaData => {
54
+ metaData.studies.map(aStudy => {
55
+ if (aStudy[key] === value) {
56
+ studies.push(aStudy);
57
+ }
58
+ });
59
+ });
60
+ return studies;
61
+ };
62
+
63
+ function createDicomJSONApi(dicomJsonConfig, servicesManager) {
64
+ const { userAuthenticationService } = servicesManager.services;
65
+ const implementation = {
66
+ initialize: async ({ query, url }) => {
67
+ if (!url) {
68
+ url = query.get('url');
69
+ }
70
+ const evaluatedUrl = resolveConfigFetchPolicy(url, {
71
+ allowedOrigins: dicomJsonConfig.dangerouslyAllowedOriginsForAuthenticatedEnvironments,
72
+ userAuthenticationService,
73
+ });
74
+ let metaData = getMetaDataByURL(evaluatedUrl.normalizedUrl);
75
+
76
+ // if we have already cached the data from this specific url
77
+ // We are only handling one StudyInstanceUID to run; however,
78
+ // all studies for patientID will be put in the correct tab
79
+ if (metaData) {
80
+ return metaData.studies.map(aStudy => {
81
+ return aStudy.StudyInstanceUID;
82
+ });
83
+ }
84
+
85
+ const data = await fetchConfigJson(evaluatedUrl);
86
+
87
+ let StudyInstanceUID;
88
+ let SeriesInstanceUID;
89
+ data.studies.forEach(study => {
90
+ StudyInstanceUID = study.StudyInstanceUID;
91
+
92
+ study.series.forEach(series => {
93
+ SeriesInstanceUID = series.SeriesInstanceUID;
94
+
95
+ series.instances.forEach(instance => {
96
+ const { metadata: naturalizedDicom } = instance;
97
+ const imageId = getImageId({ instance, config: dicomJsonConfig });
98
+
99
+ const { query } = qs.parseUrl(instance.url);
100
+
101
+ // Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI.
102
+ metadataProvider.addImageIdToUIDs(imageId, {
103
+ StudyInstanceUID,
104
+ SeriesInstanceUID,
105
+ SOPInstanceUID: naturalizedDicom.SOPInstanceUID,
106
+ frameNumber: query.frame ? parseInt(query.frame) : undefined,
107
+ });
108
+ });
109
+ });
110
+ });
111
+
112
+ _store.urls.push({
113
+ url: evaluatedUrl.normalizedUrl,
114
+ studies: [...data.studies],
115
+ });
116
+ _store.studyInstanceUIDMap.set(
117
+ evaluatedUrl.normalizedUrl,
118
+ data.studies.map(study => study.StudyInstanceUID)
119
+ );
120
+ },
121
+ query: {
122
+ studies: {
123
+ mapParams: () => {},
124
+ search: async param => {
125
+ const [key, value] = Object.entries(param)[0];
126
+ const mappedParam = mappings[key];
127
+
128
+ // todo: should fetch from dicomMetadataStore
129
+ const studies = findStudies(mappedParam, value);
130
+
131
+ return studies.map(aStudy => {
132
+ return {
133
+ accession: aStudy.AccessionNumber,
134
+ date: aStudy.StudyDate,
135
+ description: aStudy.StudyDescription,
136
+ instances: aStudy.NumInstances,
137
+ modalities: aStudy.Modalities,
138
+ mrn: aStudy.PatientID,
139
+ patientName: aStudy.PatientName,
140
+ studyInstanceUid: aStudy.StudyInstanceUID,
141
+ NumInstances: aStudy.NumInstances,
142
+ time: aStudy.StudyTime,
143
+ };
144
+ });
145
+ },
146
+ processResults: () => {
147
+ console.warn(' DICOMJson QUERY processResults not implemented');
148
+ },
149
+ },
150
+ series: {
151
+ // mapParams: mapParams.bind(),
152
+ search: () => {
153
+ console.warn(' DICOMJson QUERY SERIES SEARCH not implemented');
154
+ },
155
+ },
156
+ instances: {
157
+ search: () => {
158
+ console.warn(' DICOMJson QUERY instances SEARCH not implemented');
159
+ },
160
+ },
161
+ },
162
+ retrieve: {
163
+ /**
164
+ * Generates a URL that can be used for direct retrieve of the bulkdata
165
+ *
166
+ * @param {object} params
167
+ * @param {string} params.tag is the tag name of the URL to retrieve
168
+ * @param {string} params.defaultPath path for the pixel data url
169
+ * @param {object} params.instance is the instance object that the tag is in
170
+ * @param {string} params.defaultType is the mime type of the response
171
+ * @param {string} params.singlepart is the type of the part to retrieve
172
+ * @param {string} params.fetchPart unknown?
173
+ * @returns an absolute URL to the resource, if the absolute URL can be retrieved as singlepart,
174
+ * or is already retrieved, or a promise to a URL for such use if a BulkDataURI
175
+ */
176
+ directURL: params => {
177
+ return getDirectURL(dicomJsonConfig, params);
178
+ },
179
+ series: {
180
+ metadata: async ({ filters, StudyInstanceUID, madeInClient = false, customSort } = {}) => {
181
+ if (!StudyInstanceUID) {
182
+ throw new Error('Unable to query for SeriesMetadata without StudyInstanceUID');
183
+ }
184
+
185
+ const study = findStudies('StudyInstanceUID', StudyInstanceUID)[0];
186
+ let series;
187
+
188
+ if (customSort) {
189
+ series = customSort(study.series);
190
+ } else {
191
+ series = study.series;
192
+ }
193
+
194
+ const seriesKeys = [
195
+ 'SeriesInstanceUID',
196
+ 'SeriesInstanceUIDs',
197
+ 'seriesInstanceUID',
198
+ 'seriesInstanceUIDs',
199
+ ];
200
+ const seriesFilter = seriesKeys.find(key => filters[key]);
201
+ if (seriesFilter) {
202
+ const seriesUIDs = filters[seriesFilter];
203
+ series = series.filter(s => seriesUIDs.includes(s.SeriesInstanceUID));
204
+ }
205
+
206
+ const seriesSummaryMetadata = series.map(series => {
207
+ const seriesSummary = {
208
+ StudyInstanceUID: study.StudyInstanceUID,
209
+ ...series,
210
+ };
211
+ delete seriesSummary.instances;
212
+ return seriesSummary;
213
+ });
214
+
215
+ // Async load series, store as retrieved
216
+ function storeInstances(naturalizedInstances) {
217
+ DicomMetadataStore.addInstances(naturalizedInstances, madeInClient);
218
+ }
219
+
220
+ DicomMetadataStore.addSeriesMetadata(seriesSummaryMetadata, madeInClient);
221
+
222
+ function setSuccessFlag() {
223
+ const study = DicomMetadataStore.getStudy(StudyInstanceUID, madeInClient);
224
+ study.isLoaded = true;
225
+ }
226
+
227
+ const numberOfSeries = series.length;
228
+ series.forEach((series, index) => {
229
+ const instances = series.instances.map(instance => {
230
+ // for instance.metadata if the key ends with sequence then
231
+ // we need to add a proxy to the first item in the sequence
232
+ // so that we can access the value of the sequence
233
+ // by using sequenceName.value
234
+ const modifiedMetadata = wrapSequences(instance.metadata);
235
+
236
+ const obj = {
237
+ ...modifiedMetadata,
238
+ url: instance.url,
239
+ imageId: getImageId({ instance, config: dicomJsonConfig }),
240
+ ...series,
241
+ ...study,
242
+ };
243
+ delete obj.instances;
244
+ delete obj.series;
245
+ return obj;
246
+ });
247
+ storeInstances(instances);
248
+ if (index === numberOfSeries - 1) {
249
+ setSuccessFlag();
250
+ }
251
+ });
252
+ },
253
+ },
254
+ },
255
+ store: {
256
+ dicom: () => {
257
+ console.warn(' DICOMJson store dicom not implemented');
258
+ },
259
+ },
260
+ reject: {},
261
+ deleteStudyMetadataPromise: () => {},
262
+ getImageIdsForDisplaySet(displaySet) {
263
+ const images = displaySet.images;
264
+ const imageIds = [];
265
+
266
+ if (!images) {
267
+ return imageIds;
268
+ }
269
+
270
+ const { StudyInstanceUID, SeriesInstanceUID } = displaySet;
271
+ const study = findStudies('StudyInstanceUID', StudyInstanceUID)[0];
272
+ const series = study.series.find(s => s.SeriesInstanceUID === SeriesInstanceUID) || {};
273
+
274
+ const instanceMap = new Map();
275
+ if (series.instances) {
276
+ series.instances.forEach(instance => {
277
+ if (instance?.metadata?.SOPInstanceUID) {
278
+ const { metadata, url } = instance;
279
+ const existingInstances = instanceMap.get(metadata.SOPInstanceUID) || [];
280
+ existingInstances.push({ ...metadata, url });
281
+ instanceMap.set(metadata.SOPInstanceUID, existingInstances);
282
+ }
283
+ });
284
+ }
285
+
286
+ displaySet.images.forEach(instance => {
287
+ const NumberOfFrames = instance.NumberOfFrames || 1;
288
+ const instances = instanceMap.get(instance.SOPInstanceUID) || [instance];
289
+ for (let i = 0; i < NumberOfFrames; i++) {
290
+ const imageId = getImageId({
291
+ instance: instances[Math.min(i, instances.length - 1)],
292
+ frame: NumberOfFrames > 1 ? i : undefined,
293
+ config: dicomJsonConfig,
294
+ });
295
+ imageIds.push(imageId);
296
+ }
297
+ });
298
+
299
+ return imageIds;
300
+ },
301
+ getImageIdsForInstance({ instance, frame }) {
302
+ const imageIds = getImageId({ instance, frame });
303
+ return imageIds;
304
+ },
305
+ getStudyInstanceUIDs: ({ params, query }) => {
306
+ const url = query.get('url');
307
+ if (!url) {
308
+ return;
309
+ }
310
+
311
+ try {
312
+ const evaluatedUrl = resolveConfigFetchPolicy(url, {
313
+ allowedOrigins: dicomJsonConfig.dangerouslyAllowedOriginsForAuthenticatedEnvironments,
314
+ userAuthenticationService,
315
+ });
316
+ return _store.studyInstanceUIDMap.get(evaluatedUrl.normalizedUrl);
317
+ } catch {
318
+ return;
319
+ }
320
+ },
321
+ getConfig: () => dicomJsonConfig,
322
+ };
323
+ return IWebApiDataSource.create(implementation);
324
+ }
325
+
326
+ export { createDicomJSONApi };