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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/dist/ohif-extension-default.css +1 -1
  2. package/dist/ohif-extension-default.umd.js +1 -1
  3. package/package.json +14 -10
  4. package/src/Actions/createReportAsync.tsx +45 -0
  5. package/src/Components/DataSourceConfigurationComponent.tsx +142 -0
  6. package/src/Components/DataSourceConfigurationModalComponent.tsx +200 -0
  7. package/src/Components/ItemListComponent.tsx +95 -0
  8. package/src/Components/LineChartViewport/LineChartViewport.tsx +31 -0
  9. package/src/Components/LineChartViewport/index.ts +1 -0
  10. package/src/Components/MoreDropdownMenu.tsx +112 -0
  11. package/src/Components/ProgressDropdownWithService.tsx +101 -0
  12. package/src/Components/SidePanelWithServices.tsx +122 -0
  13. package/src/CustomizableContextMenu/ContextMenuController.tsx +216 -0
  14. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.test.js +29 -0
  15. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.ts +176 -0
  16. package/src/CustomizableContextMenu/index.ts +5 -0
  17. package/src/CustomizableContextMenu/types.ts +126 -0
  18. package/src/DataSourceConfigurationAPI/GoogleCloudDataSourceConfigurationAPI.ts +236 -0
  19. package/src/DicomJSONDataSource/index.js +326 -0
  20. package/src/DicomLocalDataSource/index.js +273 -0
  21. package/src/DicomTagBrowser/DicomTagBrowser.css +49 -0
  22. package/src/DicomTagBrowser/DicomTagBrowser.tsx +454 -0
  23. package/src/DicomTagBrowser/DicomTagTable.tsx +311 -0
  24. package/src/DicomWebDataSource/dcm4cheeReject.js +45 -0
  25. package/src/DicomWebDataSource/exampleInstances.js +280 -0
  26. package/src/DicomWebDataSource/index.ts +808 -0
  27. package/src/DicomWebDataSource/qido.js +215 -0
  28. package/src/DicomWebDataSource/retrieveBulkData.test.ts +35 -0
  29. package/src/DicomWebDataSource/retrieveBulkData.ts +31 -0
  30. package/src/DicomWebDataSource/retrieveRendered.test.ts +147 -0
  31. package/src/DicomWebDataSource/retrieveRendered.ts +141 -0
  32. package/src/DicomWebDataSource/retrieveStudyMetadata.js +108 -0
  33. package/src/DicomWebDataSource/retrieveStudyMetadata.test.js +75 -0
  34. package/src/DicomWebDataSource/retrieveThumbnail.ts +346 -0
  35. package/src/DicomWebDataSource/serviceUrls.test.ts +143 -0
  36. package/src/DicomWebDataSource/utils/StaticWadoClient.ts +272 -0
  37. package/src/DicomWebDataSource/utils/cleanDenaturalizedDataset.ts +78 -0
  38. package/src/DicomWebDataSource/utils/findIndexOfString.ts +47 -0
  39. package/src/DicomWebDataSource/utils/fixBulkDataURI.test.ts +68 -0
  40. package/src/DicomWebDataSource/utils/fixBulkDataURI.ts +78 -0
  41. package/src/DicomWebDataSource/utils/fixMultiValueKeys.ts +12 -0
  42. package/src/DicomWebDataSource/utils/fixMultipart.ts +70 -0
  43. package/src/DicomWebDataSource/utils/getImageId.js +54 -0
  44. package/src/DicomWebDataSource/utils/getWADORSImageId.js +51 -0
  45. package/src/DicomWebDataSource/utils/index.ts +9 -0
  46. package/src/DicomWebDataSource/utils/retrieveMetadataFiltered.js +61 -0
  47. package/src/DicomWebDataSource/wado/retrieveMetadata.js +41 -0
  48. package/src/DicomWebDataSource/wado/retrieveMetadataLoader.js +64 -0
  49. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderAsync.js +159 -0
  50. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderSync.js +58 -0
  51. package/src/DicomWebProxyDataSource/index.ts +90 -0
  52. package/src/MergeDataSource/index.test.ts +212 -0
  53. package/src/MergeDataSource/index.ts +319 -0
  54. package/src/MergeDataSource/types.ts +46 -0
  55. package/src/Panels/DataSourceSelector.tsx +55 -0
  56. package/src/Panels/StudyBrowser/PanelStudyBrowser.tsx +612 -0
  57. package/src/Panels/StudyBrowser/PanelStudyBrowserHeader.tsx +88 -0
  58. package/src/Panels/StudyBrowser/constants/actionIcons.ts +12 -0
  59. package/src/Panels/StudyBrowser/constants/index.ts +4 -0
  60. package/src/Panels/StudyBrowser/constants/viewPresets.ts +16 -0
  61. package/src/Panels/StudyBrowser/resolveThumbnailDetails.test.ts +197 -0
  62. package/src/Panels/StudyBrowser/resolveThumbnailDetails.ts +132 -0
  63. package/src/Panels/StudyBrowser/types/actionIcon.ts +9 -0
  64. package/src/Panels/StudyBrowser/types/index.ts +4 -0
  65. package/src/Panels/StudyBrowser/types/viewPreset.ts +7 -0
  66. package/src/Panels/WrappedPanelStudyBrowser.tsx +61 -0
  67. package/src/Panels/createReportDialogPrompt.tsx +128 -0
  68. package/src/Panels/debounce.js +25 -0
  69. package/src/Panels/getImageSrcFromImageId.js +16 -0
  70. package/src/Panels/getStudiesForPatientByMRN.js +19 -0
  71. package/src/Panels/index.js +5 -0
  72. package/src/Panels/requestDisplaySetCreationForStudy.js +19 -0
  73. package/src/SOPClassHandlers/chartSOPClassHandler.test.ts +81 -0
  74. package/src/SOPClassHandlers/chartSOPClassHandler.ts +127 -0
  75. package/src/Toolbar/ToolBoxWrapper.tsx +64 -0
  76. package/src/Toolbar/ToolButtonListWrapper.tsx +77 -0
  77. package/src/Toolbar/ToolButtonWrapper.tsx +32 -0
  78. package/src/Toolbar/ToolRowWrapper.tsx +41 -0
  79. package/src/Toolbar/Toolbar.tsx +98 -0
  80. package/src/Toolbar/ToolbarDivider.tsx +5 -0
  81. package/src/Toolbar/ToolbarLayoutSelector.tsx +195 -0
  82. package/src/Toolbar/index.ts +7 -0
  83. package/src/ViewerLayout/HeaderPatientInfo/HeaderPatientInfo.tsx +96 -0
  84. package/src/ViewerLayout/HeaderPatientInfo/index.js +3 -0
  85. package/src/ViewerLayout/HeaderUndoRedo.tsx +47 -0
  86. package/src/ViewerLayout/ResizablePanelsHook.tsx +334 -0
  87. package/src/ViewerLayout/ViewerHeader.tsx +124 -0
  88. package/src/ViewerLayout/constants/panels.ts +42 -0
  89. package/src/ViewerLayout/index.tsx +227 -0
  90. package/src/ViewerLayout/useUndoRedoState.ts +75 -0
  91. package/src/__tests__/commandsModuleToggleOneUp.test.ts +147 -0
  92. package/src/commandsModule.ts +970 -0
  93. package/src/customizations/aboutModalCustomization.tsx +42 -0
  94. package/src/customizations/appearanceModalCustomization.tsx +143 -0
  95. package/src/customizations/contextMenuCustomization.ts +25 -0
  96. package/src/customizations/contextMenuUICustomization.ts +5 -0
  97. package/src/customizations/customRoutesCustomization.ts +6 -0
  98. package/src/customizations/dataSourceConfigurationCustomization.ts +19 -0
  99. package/src/customizations/datasourcesCustomization.tsx +14 -0
  100. package/src/customizations/defaultContextMenuCustomization.ts +22 -0
  101. package/src/customizations/hangingProtocolsCustomization.ts +15 -0
  102. package/src/customizations/headerRightSideCustomization.ts +19 -0
  103. package/src/customizations/helloPageCustomization.tsx +14 -0
  104. package/src/customizations/hideHeaderUndoRedoCustomization.ts +22 -0
  105. package/src/customizations/hotkeyBindingsCustomization.ts +5 -0
  106. package/src/customizations/instanceSortingCriteriaCustomization.ts +6 -0
  107. package/src/customizations/labellingFlowCustomization.tsx +5 -0
  108. package/src/customizations/loadingIndicatorProgressCustomization.tsx +5 -0
  109. package/src/customizations/loadingIndicatorTotalPercentCustomization.tsx +5 -0
  110. package/src/customizations/menuContentCustomization.tsx +67 -0
  111. package/src/customizations/metadataContextCustomization.test.ts +22 -0
  112. package/src/customizations/metadataContextCustomization.ts +28 -0
  113. package/src/customizations/metadataDisplaySetCustomization.ts +55 -0
  114. package/src/customizations/missingReferenceDisplaySetHandler.ts +5 -0
  115. package/src/customizations/multimonitorCustomization.ts +63 -0
  116. package/src/customizations/notificationCustomization.ts +29 -0
  117. package/src/customizations/onDropHandlerCustomization.ts +5 -0
  118. package/src/customizations/onboardingCustomization.ts +200 -0
  119. package/src/customizations/overlayItemCustomization.tsx +33 -0
  120. package/src/customizations/progressDropdownCustomization.ts +5 -0
  121. package/src/customizations/progressLoadingBarCustomization.tsx +5 -0
  122. package/src/customizations/reportDialogCustomization.test.ts +701 -0
  123. package/src/customizations/reportDialogCustomization.tsx +661 -0
  124. package/src/customizations/sortingCriteriaCustomization.ts +14 -0
  125. package/src/customizations/studyBrowserCustomization.test.ts +69 -0
  126. package/src/customizations/studyBrowserCustomization.ts +95 -0
  127. package/src/customizations/thumbnailDetailsCustomization.ts +91 -0
  128. package/src/customizations/userPreferencesCustomization.tsx +342 -0
  129. package/src/customizations/workListCustomization.ts +107 -0
  130. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.test.ts +181 -0
  131. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.ts +240 -0
  132. package/src/displaySetSplitting/makeImageSetDisplaySet.ts +276 -0
  133. package/src/displaySetSplitting/stackSopClassUids.ts +60 -0
  134. package/src/displaySetSplitting/urlSplitModules.test.ts +333 -0
  135. package/src/findViewportsByPosition.ts +102 -0
  136. package/src/getCustomizationModule.tsx +109 -0
  137. package/src/getDataSourcesModule.js +44 -0
  138. package/src/getDisplaySetMessages.ts +54 -0
  139. package/src/getDisplaySetsFromUnsupportedSeries.js +63 -0
  140. package/src/getDisplaySetsFromUnsupportedSeries.test.js +14 -0
  141. package/src/getHangingProtocolModule.js +155 -0
  142. package/src/getLayoutTemplateModule.js +28 -0
  143. package/src/getPTImageIdInstanceMetadata.test.ts +102 -0
  144. package/src/getPTImageIdInstanceMetadata.ts +124 -0
  145. package/src/getPanelModule.tsx +29 -0
  146. package/src/getSopClassHandlerModule.js +152 -0
  147. package/src/getSopClassHandlerModule.test.js +78 -0
  148. package/src/getToolbarModule.tsx +63 -0
  149. package/src/getViewportModule.tsx +12 -0
  150. package/src/hangingprotocols/hpCompare.ts +189 -0
  151. package/src/hangingprotocols/hpEcgCustomization.test.ts +104 -0
  152. package/src/hangingprotocols/hpMNGrid.test.ts +120 -0
  153. package/src/hangingprotocols/hpMNGrid.ts +419 -0
  154. package/src/hangingprotocols/hpMammo.ts +202 -0
  155. package/src/hangingprotocols/hpScale.ts +132 -0
  156. package/src/hangingprotocols/index.ts +16 -0
  157. package/src/hangingprotocols/protocolMatchChanges.test.ts +73 -0
  158. package/src/hangingprotocols/utils/isNewestOfModality.ts +19 -0
  159. package/src/hangingprotocols/utils/laterality.ts +9 -0
  160. package/src/hangingprotocols/utils/mammoDisplaySetSelector.ts +214 -0
  161. package/src/hangingprotocols/utils/registerHangingProtocolAttributes.ts +14 -0
  162. package/src/hangingprotocols/utils/seriesSelectors.ts +62 -0
  163. package/src/hangingprotocols/utils/studySelectors.ts +14 -0
  164. package/src/hangingprotocols/utils/viewCode.test.js +25 -0
  165. package/src/hangingprotocols/utils/viewCode.ts +17 -0
  166. package/src/hangingprotocols/utils/viewportOptions.ts +18 -0
  167. package/src/hooks/usePatientInfo.tsx +63 -0
  168. package/src/id.js +5 -0
  169. package/src/index.ts +113 -0
  170. package/src/init.ts +169 -0
  171. package/src/stores/index.ts +7 -0
  172. package/src/stores/useDisplaySetSelectorStore.ts +83 -0
  173. package/src/stores/useHangingProtocolStageIndexStore.ts +76 -0
  174. package/src/stores/useToggleHangingProtocolStore.ts +76 -0
  175. package/src/stores/useToggleOneUpViewportGridStore.ts +19 -0
  176. package/src/stores/useUIStateStore.ts +87 -0
  177. package/src/stores/useViewportGridStore.ts +89 -0
  178. package/src/stores/useViewportsByPositionStore.ts +100 -0
  179. package/src/types/AppTypes.ts +20 -0
  180. package/src/types/commandModuleTypes.tsx +6 -0
  181. package/src/utils/Toolbox.tsx +123 -0
  182. package/src/utils/_shared/PROMPT_RESPONSES.ts +10 -0
  183. package/src/utils/addIcon.ts +6 -0
  184. package/src/utils/appendFrameQueryToImageId.js +9 -0
  185. package/src/utils/callInputDialog.tsx +126 -0
  186. package/src/utils/colorPickerDialog.css +4 -0
  187. package/src/utils/colorPickerDialog.tsx +45 -0
  188. package/src/utils/createRenderedRetrieve.js +32 -0
  189. package/src/utils/createRenderedRetrieve.test.js +46 -0
  190. package/src/utils/dicomWriter.test.ts +228 -0
  191. package/src/utils/dicomWriter.ts +110 -0
  192. package/src/utils/getBulkdataValue.js +45 -0
  193. package/src/utils/getBulkdataValue.test.js +105 -0
  194. package/src/utils/getDirectURL.test.ts +207 -0
  195. package/src/utils/getDirectURL.ts +65 -0
  196. package/src/utils/getSRSeriesAndInstanceNumber.js +48 -0
  197. package/src/utils/index.ts +2 -0
  198. package/src/utils/layerConfigurationUtils.ts +202 -0
  199. package/src/utils/promptLabelAnnotation.js +47 -0
  200. package/src/utils/promptSaveReport.test.ts +106 -0
  201. package/src/utils/promptSaveReport.tsx +117 -0
  202. package/src/utils/registerNaturalizedDatasetForLocalWadouri.js +146 -0
  203. package/src/utils/registerNaturalizedDatasetForLocalWadouri.test.js +177 -0
  204. package/src/utils/registerStoredInstanceImageId.test.ts +73 -0
  205. package/src/utils/registerStoredInstanceImageId.ts +66 -0
  206. package/src/utils/reuseCachedLayouts.ts +92 -0
  207. package/src/utils/secureConfigFetch.js +115 -0
  208. package/src/utils/secureConfigFetch.test.js +163 -0
  209. package/src/utils/seriesDescriptionHistory.ts +83 -0
  210. package/src/utils/validations/areAllImageComponentsEqual.ts +24 -0
  211. package/src/utils/validations/areAllImageDimensionsEqual.test.ts +41 -0
  212. package/src/utils/validations/areAllImageDimensionsEqual.ts +27 -0
  213. package/src/utils/validations/areAllImagePositionsEqual.ts +75 -0
  214. package/src/utils/validations/areAllImageSpacingEqual.ts +66 -0
  215. package/src/utils/validations/checkMultiframe.ts +25 -0
  216. package/src/utils/validations/checkSingleFrames.ts +36 -0
@@ -0,0 +1,454 @@
1
+ import dcmjs from 'dcmjs';
2
+ import moment from 'moment';
3
+ import React, { useState, useMemo, useCallback } from 'react';
4
+ import { classes, Types } from '@ohif/core';
5
+ import { InputFilter } from '@ohif/ui-next';
6
+ import {
7
+ Select,
8
+ SelectTrigger,
9
+ SelectValue,
10
+ SelectContent,
11
+ SelectItem,
12
+ Slider,
13
+ } from '@ohif/ui-next';
14
+
15
+ import DicomTagTable from './DicomTagTable';
16
+ import './DicomTagBrowser.css';
17
+
18
+ export type Row = {
19
+ uid: string;
20
+ tag: string;
21
+ valueRepresentation: string;
22
+ keyword: string;
23
+ value: string;
24
+ isVisible: boolean;
25
+ depth: number;
26
+ parents?: string[];
27
+ children?: string[];
28
+ areChildrenVisible?: boolean;
29
+ };
30
+
31
+ let rowCounter = 0;
32
+ const generateRowId = () => `row_${++rowCounter}`;
33
+
34
+ const { ImageSet } = classes;
35
+ const { DicomMetaDictionary } = dcmjs.data;
36
+ const { nameMap } = DicomMetaDictionary;
37
+
38
+ const DicomTagBrowser = ({
39
+ displaySets,
40
+ displaySetInstanceUID,
41
+ }: {
42
+ displaySets: Types.DisplaySet[];
43
+ displaySetInstanceUID: string;
44
+ }) => {
45
+ const [selectedDisplaySetInstanceUID, setSelectedDisplaySetInstanceUID] =
46
+ useState(displaySetInstanceUID);
47
+ const [instanceNumber, setInstanceNumber] = useState(1);
48
+ const [filterValue, setFilterValue] = useState('');
49
+
50
+ const onSelectChange = value => {
51
+ setSelectedDisplaySetInstanceUID(value.value);
52
+ setInstanceNumber(1);
53
+ };
54
+
55
+ const activeDisplaySet = displaySets.find(
56
+ ds => ds.displaySetInstanceUID === selectedDisplaySetInstanceUID
57
+ );
58
+
59
+ const displaySetList = useMemo(() => {
60
+ displaySets.sort((a, b) => a.SeriesNumber - b.SeriesNumber);
61
+ return displaySets.map(displaySet => {
62
+ const {
63
+ displaySetInstanceUID,
64
+ SeriesDate,
65
+ SeriesTime,
66
+ SeriesNumber,
67
+ SeriesDescription,
68
+ Modality,
69
+ } = displaySet;
70
+
71
+ /* Map to display representation */
72
+ const dateStr = `${SeriesDate}:${SeriesTime}`.split('.')[0];
73
+ const date = moment(dateStr, 'YYYYMMDD:HHmmss');
74
+ const displayDate = date.format('ddd, MMM Do YYYY');
75
+
76
+ return {
77
+ value: displaySetInstanceUID,
78
+ label: `${SeriesNumber} (${Modality}): ${SeriesDescription}`,
79
+ description: displayDate,
80
+ };
81
+ });
82
+ }, [displaySets]);
83
+
84
+ const getMetadata = useCallback(
85
+ isImageStack => {
86
+ if (isImageStack) {
87
+ return activeDisplaySet.images[instanceNumber - 1];
88
+ }
89
+ return activeDisplaySet.instance || activeDisplaySet;
90
+ },
91
+ [activeDisplaySet, instanceNumber]
92
+ );
93
+
94
+ // Derived, not state: it is a pure function of the active display set, and
95
+ // computing it inside the rows memo meant the JSX below read the previous
96
+ // render's value.
97
+ const shouldShowInstanceList =
98
+ activeDisplaySet instanceof ImageSet && activeDisplaySet.images.length > 1;
99
+
100
+ const rows = useMemo(() => {
101
+ const isImageStack = activeDisplaySet instanceof ImageSet;
102
+ const metadata = getMetadata(isImageStack);
103
+
104
+ const tags = getSortedTags(metadata);
105
+ const rows = getFormattedRowsFromTags({ tags, metadata });
106
+ return rows;
107
+ }, [getMetadata, activeDisplaySet]);
108
+
109
+ const filteredRows = useMemo(() => {
110
+ if (!filterValue) {
111
+ return rows;
112
+ }
113
+
114
+ const matchedRowIds = new Set();
115
+
116
+ const propertiesToCheck = ['tag', 'valueRepresentation', 'keyword', 'value'];
117
+
118
+ const setIsMatched = row => {
119
+ const isDirectMatch = propertiesToCheck.some(propertyName =>
120
+ row[propertyName]?.toLowerCase().includes(filterValueLowerCase)
121
+ );
122
+
123
+ if (!isDirectMatch) {
124
+ return;
125
+ }
126
+
127
+ matchedRowIds.add(row.uid);
128
+
129
+ [...(row.parents ?? []), ...(row.children ?? [])].forEach(uid => matchedRowIds.add(uid));
130
+ };
131
+
132
+ const filterValueLowerCase = filterValue.toLowerCase();
133
+ rows.forEach(setIsMatched);
134
+ return rows.filter(row => matchedRowIds.has(row.uid));
135
+ }, [rows, filterValue]);
136
+
137
+ return (
138
+ <div className="dicom-tag-browser-content bg-muted">
139
+ <div className="mb-6 flex flex-row items-start pl-1">
140
+ <div className="flex w-full flex-row items-start gap-6">
141
+ <div className="flex w-1/3 flex-col">
142
+ <span className="text-muted-foreground flex h-6 items-center pb-2 text-base">
143
+ Series
144
+ </span>
145
+ <Select
146
+ value={selectedDisplaySetInstanceUID}
147
+ onValueChange={value => onSelectChange({ value })}
148
+ >
149
+ <SelectTrigger data-cy="dicom-tag-series-select-trigger">
150
+ <SelectValue data-cy="dicom-tag-series-select-value">
151
+ {displaySetList.find(ds => ds.value === selectedDisplaySetInstanceUID)?.label ||
152
+ 'Select Series'}
153
+ </SelectValue>
154
+ </SelectTrigger>
155
+ <SelectContent>
156
+ {displaySetList.map(item => {
157
+ return (
158
+ <SelectItem
159
+ key={item.value}
160
+ value={item.value}
161
+ >
162
+ {item.label}
163
+ <span className="text-muted-foreground ml-1 text-xs">{item.description}</span>
164
+ </SelectItem>
165
+ );
166
+ })}
167
+ </SelectContent>
168
+ </Select>
169
+ </div>
170
+ {shouldShowInstanceList && (
171
+ <div className="mx-auto mt-0.5 flex w-1/4 flex-col">
172
+ <span className="text-muted-foreground flex h-6 min-w-0 items-center whitespace-nowrap pb-2 text-base">
173
+ <span className="truncate">Instance Number</span>
174
+ <span className="shrink-0">
175
+ &nbsp;({instanceNumber} of {activeDisplaySet?.images?.length})
176
+ </span>
177
+ </span>
178
+ <Slider
179
+ value={[instanceNumber]}
180
+ onValueChange={([value]) => {
181
+ setInstanceNumber(value);
182
+ }}
183
+ min={1}
184
+ max={activeDisplaySet?.images?.length}
185
+ step={1}
186
+ className="pt-3"
187
+ />
188
+ </div>
189
+ )}
190
+ <div className="ml-auto mr-1 flex w-1/3 flex-col">
191
+ <span className="text-muted-foreground flex h-6 items-center pb-2 text-base">
192
+ Search metadata
193
+ </span>
194
+ <InputFilter
195
+ className="text-muted-foreground"
196
+ onChange={setFilterValue}
197
+ >
198
+ <InputFilter.SearchIcon />
199
+ <InputFilter.Input
200
+ placeholder="Search metadata"
201
+ className="pl-9 pr-9"
202
+ />
203
+ <InputFilter.ClearButton className="text-primary mr-0.5 p-0.5" />
204
+ </InputFilter>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ <DicomTagTable rows={filteredRows} />
209
+ </div>
210
+ );
211
+ };
212
+
213
+ function getFormattedRowsFromTags({ tags, metadata }) {
214
+ const rows: Row[] = [];
215
+ const stack = [{ tags, depth: 0, parents: null, index: 0, children: [] }];
216
+ const parentChildMap = new Map();
217
+
218
+ while (stack.length > 0) {
219
+ const current = stack.pop();
220
+ const { tags, depth, parents, index, children } = current;
221
+
222
+ for (let i = index; i < tags.length; i++) {
223
+ const tagInfo = tags[i];
224
+ const uid = tagInfo.uid ?? generateRowId();
225
+
226
+ if (parents?.length > 0) {
227
+ parents.forEach(parent => {
228
+ parentChildMap.get(parent).push(uid);
229
+ });
230
+ }
231
+
232
+ if (tagInfo.vr === 'SQ') {
233
+ const row: Row = {
234
+ uid,
235
+ tag: tagInfo.tag,
236
+ valueRepresentation: tagInfo.vr,
237
+ keyword: tagInfo.keyword,
238
+ value: '',
239
+ depth,
240
+ isVisible: true,
241
+ areChildrenVisible: true,
242
+ children: [],
243
+ parents,
244
+ };
245
+ rows.push(row);
246
+ parentChildMap.set(uid, row.children);
247
+
248
+ const newParents = parents ? [...parents, uid] : [uid];
249
+
250
+ if (tagInfo.values.length > 0) {
251
+ stack.push({ tags, depth, parents, index: i + 1, children });
252
+ for (
253
+ let j = tagInfo.values.length - 1, values = tagInfo.values[j];
254
+ j >= 0;
255
+ values = tagInfo.values[--j]
256
+ ) {
257
+ const itemUid = generateRowId();
258
+ stack.push({
259
+ tags: values,
260
+ depth: depth + 2,
261
+ parents: [...newParents, itemUid],
262
+ index: 0,
263
+ children: [],
264
+ });
265
+ const itemTagInfo = {
266
+ tags: [
267
+ {
268
+ tag: '(FFFE,E000)',
269
+ vr: '',
270
+ keyword: `Item #${j}`,
271
+ value: '',
272
+ uid: itemUid,
273
+ },
274
+ ],
275
+ depth: depth + 1,
276
+ parents: newParents,
277
+ index: 0,
278
+ children: [],
279
+ };
280
+ stack.push(itemTagInfo);
281
+ parentChildMap.set(itemUid, itemTagInfo.children);
282
+ }
283
+ break;
284
+ }
285
+ } else {
286
+ if (tagInfo.vr === 'xs') {
287
+ try {
288
+ const tag = dcmjs.data.Tag.fromPString(tagInfo.tag).toCleanString();
289
+ const originalTagInfo = metadata[tag];
290
+ tagInfo.vr = originalTagInfo.vr;
291
+ } catch (error) {
292
+ console.warn(`Failed to parse value representation for tag '${tagInfo.keyword}'`);
293
+ }
294
+ }
295
+ const row: Row = {
296
+ uid,
297
+ tag: tagInfo.tag,
298
+ valueRepresentation: tagInfo.vr,
299
+ keyword: tagInfo.keyword,
300
+ value: tagInfo.value,
301
+ depth,
302
+ isVisible: true,
303
+ parents,
304
+ };
305
+ rows.push(row);
306
+ if (row.tag === '(FFFE,E000)') {
307
+ row.areChildrenVisible = true;
308
+ row.children = [];
309
+ }
310
+ }
311
+ }
312
+ }
313
+ return rows;
314
+ }
315
+
316
+ function getSortedTags(metadata) {
317
+ const tagList = getRows(metadata);
318
+
319
+ // Sort top level tags, sequence groups are sorted when created.
320
+ _sortTagList(tagList);
321
+
322
+ return tagList;
323
+ }
324
+
325
+ function getRows(metadata, depth = 0) {
326
+ // Tag, Type, Value, Keyword
327
+
328
+ if (!metadata) {
329
+ return [];
330
+ }
331
+
332
+ const keywords = Object.keys(metadata);
333
+
334
+ const rows = [];
335
+ for (let i = 0; i < keywords.length; i++) {
336
+ let keyword = keywords[i];
337
+
338
+ if (keyword === '_vrMap') {
339
+ continue;
340
+ }
341
+
342
+ const tagInfo = nameMap[keyword];
343
+
344
+ let value = metadata[keyword];
345
+
346
+ if (tagInfo && tagInfo.vr === 'SQ') {
347
+ const sequenceAsArray = toArray(value);
348
+
349
+ // Push line defining the sequence
350
+
351
+ const sequence = {
352
+ tag: tagInfo.tag,
353
+ vr: tagInfo.vr,
354
+ keyword,
355
+ values: [],
356
+ };
357
+
358
+ rows.push(sequence);
359
+
360
+ if (value === null) {
361
+ // Type 2 Sequence
362
+ continue;
363
+ }
364
+
365
+ sequenceAsArray.forEach(item => {
366
+ const sequenceRows = getRows(item, depth + 1);
367
+
368
+ if (sequenceRows.length) {
369
+ // Sort the sequence group.
370
+ _sortTagList(sequenceRows);
371
+ sequence.values.push(sequenceRows);
372
+ }
373
+ });
374
+
375
+ continue;
376
+ }
377
+
378
+ if (Array.isArray(value)) {
379
+ if (value.length > 0 && typeof value[0] != 'object') {
380
+ value = value.join('\\');
381
+ }
382
+ }
383
+
384
+ if (typeof value === 'number') {
385
+ value = value.toString();
386
+ }
387
+
388
+ if (typeof value !== 'string') {
389
+ if (value === null) {
390
+ value = ' ';
391
+ } else {
392
+ if (typeof value === 'object') {
393
+ if (value.InlineBinary) {
394
+ value = 'Inline Binary';
395
+ } else if (value.BulkDataURI) {
396
+ value = `Bulk Data URI`; //: ${value.BulkDataURI}`;
397
+ } else if (value.Alphabetic) {
398
+ value = value.Alphabetic;
399
+ } else {
400
+ console.warn(`Unrecognised Value: ${value} for ${keyword}:`);
401
+ console.warn(value);
402
+ value = ' ';
403
+ }
404
+ } else {
405
+ console.warn(`Unrecognised Value: ${value} for ${keyword}:`);
406
+ value = ' ';
407
+ }
408
+ }
409
+ }
410
+
411
+ // tag / vr/ keyword/ value
412
+
413
+ // Remove retired tags
414
+ keyword = keyword.replace('RETIRED_', '');
415
+ if (tagInfo) {
416
+ rows.push({
417
+ tag: tagInfo.tag,
418
+ vr: tagInfo.vr,
419
+ keyword,
420
+ value,
421
+ });
422
+ } else {
423
+ // skip properties without hex tag numbers
424
+ const regex = /[0-9A-Fa-f]{6}/g;
425
+ if (keyword.match(regex)) {
426
+ const tag = `(${keyword.substring(0, 4)},${keyword.substring(4, 8)})`;
427
+ rows.push({
428
+ tag,
429
+ vr: '',
430
+ keyword: 'Private Tag',
431
+ value,
432
+ });
433
+ }
434
+ }
435
+ }
436
+
437
+ return rows;
438
+ }
439
+
440
+ function toArray(objectOrArray) {
441
+ return Array.isArray(objectOrArray) ? objectOrArray : [objectOrArray];
442
+ }
443
+
444
+ function _sortTagList(tagList) {
445
+ tagList.sort((a, b) => {
446
+ if (a.tag < b.tag) {
447
+ return -1;
448
+ }
449
+
450
+ return 1;
451
+ });
452
+ }
453
+
454
+ export default DicomTagBrowser;