@cornerstonejs/metadata 5.0.0

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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/dist/esm/enums/CalibrationTypes.d.ts +12 -0
  3. package/dist/esm/enums/CalibrationTypes.js +13 -0
  4. package/dist/esm/enums/MetadataModules.d.ts +54 -0
  5. package/dist/esm/enums/MetadataModules.js +57 -0
  6. package/dist/esm/enums/index.d.ts +4 -0
  7. package/dist/esm/enums/index.js +4 -0
  8. package/dist/esm/index.d.ts +10 -0
  9. package/dist/esm/index.js +9 -0
  10. package/dist/esm/metaData.d.ts +33 -0
  11. package/dist/esm/metaData.js +181 -0
  12. package/dist/esm/registerDefaultProviders.d.ts +1 -0
  13. package/dist/esm/registerDefaultProviders.js +38 -0
  14. package/dist/esm/types/DicomStreamTypes.d.ts +13 -0
  15. package/dist/esm/types/DicomStreamTypes.js +0 -0
  16. package/dist/esm/types/IImageCalibration.d.ts +11 -0
  17. package/dist/esm/types/IImageCalibration.js +0 -0
  18. package/dist/esm/types/MetadataModuleTypes.d.ts +100 -0
  19. package/dist/esm/types/MetadataModuleTypes.js +0 -0
  20. package/dist/esm/types/index.d.ts +3 -0
  21. package/dist/esm/types/index.js +0 -0
  22. package/dist/esm/utilities/Tags.d.ts +25 -0
  23. package/dist/esm/utilities/Tags.js +112 -0
  24. package/dist/esm/utilities/bulkDataFromArray.d.ts +1 -0
  25. package/dist/esm/utilities/bulkDataFromArray.js +38 -0
  26. package/dist/esm/utilities/calibratedPixelSpacingMetadataProvider.d.ts +7 -0
  27. package/dist/esm/utilities/calibratedPixelSpacingMetadataProvider.js +21 -0
  28. package/dist/esm/utilities/dicomStream/MetaDataIterator.d.ts +11 -0
  29. package/dist/esm/utilities/dicomStream/MetaDataIterator.js +58 -0
  30. package/dist/esm/utilities/dicomStream/NaturalTagListener.d.ts +22 -0
  31. package/dist/esm/utilities/dicomStream/NaturalTagListener.js +106 -0
  32. package/dist/esm/utilities/dicomStream/index.d.ts +3 -0
  33. package/dist/esm/utilities/dicomStream/index.js +2 -0
  34. package/dist/esm/utilities/getNaturalizedField.d.ts +3 -0
  35. package/dist/esm/utilities/getNaturalizedField.js +34 -0
  36. package/dist/esm/utilities/getPixelSpacingInformation.d.ts +13 -0
  37. package/dist/esm/utilities/getPixelSpacingInformation.js +93 -0
  38. package/dist/esm/utilities/imageIdToURI.d.ts +1 -0
  39. package/dist/esm/utilities/imageIdToURI.js +15 -0
  40. package/dist/esm/utilities/index.d.ts +15 -0
  41. package/dist/esm/utilities/index.js +15 -0
  42. package/dist/esm/utilities/isEqual.d.ts +2 -0
  43. package/dist/esm/utilities/isEqual.js +2 -0
  44. package/dist/esm/utilities/isVideoTransferSyntax.d.ts +2 -0
  45. package/dist/esm/utilities/isVideoTransferSyntax.js +25 -0
  46. package/dist/esm/utilities/logging.d.ts +3 -0
  47. package/dist/esm/utilities/logging.js +2 -0
  48. package/dist/esm/utilities/metadataProvider/addDicomPart10Instance.d.ts +2 -0
  49. package/dist/esm/utilities/metadataProvider/addDicomPart10Instance.js +12 -0
  50. package/dist/esm/utilities/metadataProvider/cacheData.d.ts +39 -0
  51. package/dist/esm/utilities/metadataProvider/cacheData.js +235 -0
  52. package/dist/esm/utilities/metadataProvider/calibrationModule.d.ts +2 -0
  53. package/dist/esm/utilities/metadataProvider/calibrationModule.js +25 -0
  54. package/dist/esm/utilities/metadataProvider/combineFrameInstance.d.ts +5 -0
  55. package/dist/esm/utilities/metadataProvider/combineFrameInstance.js +158 -0
  56. package/dist/esm/utilities/metadataProvider/compressedFrameData.d.ts +1 -0
  57. package/dist/esm/utilities/metadataProvider/compressedFrameData.js +133 -0
  58. package/dist/esm/utilities/metadataProvider/dataLookup.d.ts +7 -0
  59. package/dist/esm/utilities/metadataProvider/dataLookup.js +18 -0
  60. package/dist/esm/utilities/metadataProvider/dicomSplit.d.ts +1 -0
  61. package/dist/esm/utilities/metadataProvider/dicomSplit.js +5 -0
  62. package/dist/esm/utilities/metadataProvider/ecgFromInstance.d.ts +18 -0
  63. package/dist/esm/utilities/metadataProvider/ecgFromInstance.js +228 -0
  64. package/dist/esm/utilities/metadataProvider/ecgModule.d.ts +1 -0
  65. package/dist/esm/utilities/metadataProvider/ecgModule.js +0 -0
  66. package/dist/esm/utilities/metadataProvider/imageIdsProviders.d.ts +11 -0
  67. package/dist/esm/utilities/metadataProvider/imageIdsProviders.js +117 -0
  68. package/dist/esm/utilities/metadataProvider/imagePlaneCalibrated.d.ts +4 -0
  69. package/dist/esm/utilities/metadataProvider/imagePlaneCalibrated.js +89 -0
  70. package/dist/esm/utilities/metadataProvider/index.d.ts +18 -0
  71. package/dist/esm/utilities/metadataProvider/index.js +17 -0
  72. package/dist/esm/utilities/metadataProvider/instanceFromListener.d.ts +2 -0
  73. package/dist/esm/utilities/metadataProvider/instanceFromListener.js +9 -0
  74. package/dist/esm/utilities/metadataProvider/makeArrayLike.d.ts +1 -0
  75. package/dist/esm/utilities/metadataProvider/makeArrayLike.js +25 -0
  76. package/dist/esm/utilities/metadataProvider/naturalizedHandlers.d.ts +5 -0
  77. package/dist/esm/utilities/metadataProvider/naturalizedHandlers.js +67 -0
  78. package/dist/esm/utilities/metadataProvider/pixelDataUpdate.d.ts +2 -0
  79. package/dist/esm/utilities/metadataProvider/pixelDataUpdate.js +133 -0
  80. package/dist/esm/utilities/metadataProvider/scalingFromInstance.d.ts +1 -0
  81. package/dist/esm/utilities/metadataProvider/scalingFromInstance.js +148 -0
  82. package/dist/esm/utilities/metadataProvider/tagModules.d.ts +7 -0
  83. package/dist/esm/utilities/metadataProvider/tagModules.js +62 -0
  84. package/dist/esm/utilities/metadataProvider/transferSyntaxProvider.d.ts +2 -0
  85. package/dist/esm/utilities/metadataProvider/transferSyntaxProvider.js +20 -0
  86. package/dist/esm/utilities/metadataProvider/uriModule.d.ts +19 -0
  87. package/dist/esm/utilities/metadataProvider/uriModule.js +26 -0
  88. package/dist/esm/utilities/modules/cine.d.ts +2 -0
  89. package/dist/esm/utilities/modules/cine.js +4 -0
  90. package/dist/esm/utilities/modules/clinicalTrial.d.ts +2 -0
  91. package/dist/esm/utilities/modules/clinicalTrial.js +6 -0
  92. package/dist/esm/utilities/modules/ecg.d.ts +2 -0
  93. package/dist/esm/utilities/modules/ecg.js +11 -0
  94. package/dist/esm/utilities/modules/generalImage.d.ts +2 -0
  95. package/dist/esm/utilities/modules/generalImage.js +14 -0
  96. package/dist/esm/utilities/modules/generalSeries.d.ts +2 -0
  97. package/dist/esm/utilities/modules/generalSeries.js +11 -0
  98. package/dist/esm/utilities/modules/generalStudy.d.ts +2 -0
  99. package/dist/esm/utilities/modules/generalStudy.js +7 -0
  100. package/dist/esm/utilities/modules/imagePixel.d.ts +2 -0
  101. package/dist/esm/utilities/modules/imagePixel.js +31 -0
  102. package/dist/esm/utilities/modules/imagePlane.d.ts +2 -0
  103. package/dist/esm/utilities/modules/imagePlane.js +8 -0
  104. package/dist/esm/utilities/modules/index.d.ts +5 -0
  105. package/dist/esm/utilities/modules/index.js +48 -0
  106. package/dist/esm/utilities/modules/modalityLut.d.ts +2 -0
  107. package/dist/esm/utilities/modules/modalityLut.js +5 -0
  108. package/dist/esm/utilities/modules/patient.d.ts +2 -0
  109. package/dist/esm/utilities/modules/patient.js +6 -0
  110. package/dist/esm/utilities/modules/patientStudy.d.ts +2 -0
  111. package/dist/esm/utilities/modules/patientStudy.js +6 -0
  112. package/dist/esm/utilities/modules/ptImage.d.ts +2 -0
  113. package/dist/esm/utilities/modules/ptImage.js +4 -0
  114. package/dist/esm/utilities/modules/ptIsotope.d.ts +2 -0
  115. package/dist/esm/utilities/modules/ptIsotope.js +1 -0
  116. package/dist/esm/utilities/modules/ptSeries.d.ts +2 -0
  117. package/dist/esm/utilities/modules/ptSeries.js +5 -0
  118. package/dist/esm/utilities/modules/radiopharmaceuticalInfo.d.ts +2 -0
  119. package/dist/esm/utilities/modules/radiopharmaceuticalInfo.js +6 -0
  120. package/dist/esm/utilities/modules/sopCommon.d.ts +2 -0
  121. package/dist/esm/utilities/modules/sopCommon.js +1 -0
  122. package/dist/esm/utilities/modules/transferSyntax.d.ts +2 -0
  123. package/dist/esm/utilities/modules/transferSyntax.js +4 -0
  124. package/dist/esm/utilities/modules/ultrasoundEnhancedRegion.d.ts +2 -0
  125. package/dist/esm/utilities/modules/ultrasoundEnhancedRegion.js +1 -0
  126. package/dist/esm/utilities/modules/unassigned.d.ts +2 -0
  127. package/dist/esm/utilities/modules/unassigned.js +15 -0
  128. package/dist/esm/utilities/modules/usRegionChild.d.ts +2 -0
  129. package/dist/esm/utilities/modules/usRegionChild.js +18 -0
  130. package/dist/esm/utilities/modules/voiLut.d.ts +2 -0
  131. package/dist/esm/utilities/modules/voiLut.js +6 -0
  132. package/dist/esm/utilities/splitImageIdsBy4DTags.d.ts +12 -0
  133. package/dist/esm/utilities/splitImageIdsBy4DTags.js +314 -0
  134. package/dist/esm/utilities/toNumber.d.ts +2 -0
  135. package/dist/esm/utilities/toNumber.js +2 -0
  136. package/dist/esm/version.d.ts +1 -0
  137. package/dist/esm/version.js +1 -0
  138. package/package.json +99 -0
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,4 @@
1
+ export const tags = [
2
+ 'FrameReferenceTime',
3
+ 'ActualFrameDuration',
4
+ ];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1 @@
1
+ export const tags = [['RadiopharmaceuticalInfo', '00540016']];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,5 @@
1
+ export const tags = [
2
+ 'CorrectedImage',
3
+ 'Units',
4
+ 'DecayCorrection',
5
+ ];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,6 @@
1
+ export const tags = [
2
+ 'RadiopharmaceuticalStartTime',
3
+ 'RadiopharmaceuticalStopTime',
4
+ 'RadionuclideTotalDose',
5
+ 'RadionuclideHalfLife',
6
+ ];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1 @@
1
+ export const tags = ['SOPInstanceUID', 'SOPClassUID'];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,4 @@
1
+ export const tags = [
2
+ 'TransferSyntaxUID',
3
+ 'AvailableTransferSyntaxUID',
4
+ ];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1 @@
1
+ export const tags = ['SequenceOfUltrasoundRegions'];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,15 @@
1
+ export const tags = [
2
+ 'ReferencedImageSequence',
3
+ 'ReferencedSOPClassUID',
4
+ 'ReferencedSOPInstanceUID',
5
+ 'ReferencedFrameNumber',
6
+ 'SharedFunctionalGroupsSequence',
7
+ 'PerFrameFunctionalGroupsSequence',
8
+ 'PlanePositionSequence',
9
+ 'AnatomicRegionSequence',
10
+ 'PlaneOrientationSequence',
11
+ 'PixelMeasuresSequence',
12
+ 'PixelValueTransformationSequence',
13
+ 'ParametricMapFrameTypeSequence',
14
+ 'RealWorldValueMappingSequence',
15
+ ];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,18 @@
1
+ export const tags = [
2
+ 'PhysicalDeltaX',
3
+ 'PhysicalDeltaY',
4
+ 'PhysicalUnitsXDirection',
5
+ 'PhysicalUnitsYDirection',
6
+ 'RegionLocationMinY0',
7
+ 'RegionLocationMaxY1',
8
+ 'RegionLocationMinX0',
9
+ 'RegionLocationMaxX1',
10
+ 'ReferencePixelX0',
11
+ 'ReferencePixelY0',
12
+ ['ReferencePhysicalPixelValueY', '0018602A'],
13
+ ['ReferencePhysicalPixelValueX', '00186028'],
14
+ 'RegionSpatialFormat',
15
+ 'RegionDataType',
16
+ 'RegionFlags',
17
+ 'TransducerFrequency',
18
+ ];
@@ -0,0 +1,2 @@
1
+ import type { ModuleTagEntry } from './index';
2
+ export declare const tags: ModuleTagEntry[];
@@ -0,0 +1,6 @@
1
+ export const tags = [
2
+ 'WindowCenter',
3
+ 'WindowWidth',
4
+ 'VOILUTFunction',
5
+ 'WindowCenterWidthExplanation',
6
+ ];
@@ -0,0 +1,12 @@
1
+ interface MultiframeSplitResult {
2
+ imageIdGroups: string[][];
3
+ splittingTag: string;
4
+ }
5
+ declare function generateFrameImageId(baseImageId: string, frameNumber: number): string;
6
+ declare function handleMultiframe4D(imageIds: string[]): MultiframeSplitResult | null;
7
+ declare function splitImageIdsBy4DTags(imageIds: string[]): {
8
+ imageIdGroups: string[][];
9
+ splittingTag: string | null;
10
+ };
11
+ export default splitImageIdsBy4DTags;
12
+ export { handleMultiframe4D, generateFrameImageId };
@@ -0,0 +1,314 @@
1
+ import * as metaData from '../metaData';
2
+ import { toFiniteNumber } from './toNumber';
3
+ function generateFrameImageId(baseImageId, frameNumber) {
4
+ const framePattern = /\/frames\/\d+/;
5
+ if (!framePattern.test(baseImageId)) {
6
+ throw new Error(`generateFrameImageId: baseImageId must contain a "/frames/" pattern followed by a digit. ` +
7
+ `Expected format: e.g., "wadouri:http://example.com/image/frames/1" or "wadors:/path/to/image.dcm/frames/1". ` +
8
+ `Received: ${baseImageId}`);
9
+ }
10
+ return baseImageId.replace(framePattern, `/frames/${frameNumber}`);
11
+ }
12
+ function handleMultiframe4D(imageIds) {
13
+ if (!imageIds || imageIds.length === 0) {
14
+ return null;
15
+ }
16
+ const baseImageId = imageIds[0];
17
+ const instance = metaData.get('instance', baseImageId);
18
+ if (!instance) {
19
+ return null;
20
+ }
21
+ const numberOfFrames = instance.NumberOfFrames;
22
+ if (!numberOfFrames || numberOfFrames <= 1) {
23
+ return null;
24
+ }
25
+ const timeSlotVector = instance.TimeSlotVector;
26
+ if (!timeSlotVector || !Array.isArray(timeSlotVector)) {
27
+ return null;
28
+ }
29
+ const sliceVector = instance.SliceVector;
30
+ const numberOfSlices = instance.NumberOfSlices;
31
+ if (timeSlotVector.length !== numberOfFrames) {
32
+ console.warn('TimeSlotVector length does not match NumberOfFrames:', timeSlotVector.length, 'vs', numberOfFrames);
33
+ return null;
34
+ }
35
+ if (sliceVector) {
36
+ if (!Array.isArray(sliceVector)) {
37
+ console.warn('SliceVector exists but is not an array. Expected length:', numberOfFrames);
38
+ return null;
39
+ }
40
+ if (sliceVector.length !== numberOfFrames ||
41
+ sliceVector.some((val) => val === undefined)) {
42
+ console.warn('SliceVector exists but has invalid length or undefined entries. Expected length:', numberOfFrames, 'Actual length:', sliceVector.length);
43
+ return null;
44
+ }
45
+ }
46
+ const timeSlotGroups = new Map();
47
+ for (let frameIndex = 0; frameIndex < numberOfFrames; frameIndex++) {
48
+ const timeSlot = timeSlotVector[frameIndex];
49
+ const sliceIndex = sliceVector?.[frameIndex] ?? frameIndex;
50
+ if (!timeSlotGroups.has(timeSlot)) {
51
+ timeSlotGroups.set(timeSlot, []);
52
+ }
53
+ timeSlotGroups.get(timeSlot).push({ frameIndex, sliceIndex });
54
+ }
55
+ const sortedTimeSlots = Array.from(timeSlotGroups.keys()).sort((a, b) => a - b);
56
+ const imageIdGroups = sortedTimeSlots.map((timeSlot) => {
57
+ const frames = timeSlotGroups.get(timeSlot);
58
+ frames.sort((a, b) => a.sliceIndex - b.sliceIndex);
59
+ return frames.map((frame) => generateFrameImageId(baseImageId, frame.frameIndex + 1));
60
+ });
61
+ const expectedSlicesPerTimeSlot = numberOfSlices || imageIdGroups[0]?.length;
62
+ const allGroupsHaveSameLength = imageIdGroups.every((group) => group.length === expectedSlicesPerTimeSlot);
63
+ if (!allGroupsHaveSameLength) {
64
+ console.warn('Multiframe 4D split resulted in uneven time slot groups. Expected', expectedSlicesPerTimeSlot, 'slices per time slot.');
65
+ }
66
+ return {
67
+ imageIdGroups,
68
+ splittingTag: 'TimeSlotVector',
69
+ };
70
+ }
71
+ function handleCardiac4D(imageIds) {
72
+ if (!imageIds || imageIds.length === 0) {
73
+ return null;
74
+ }
75
+ const cardiacNumberOfImages = getFiniteValue(imageIds[0], 'CardiacNumberOfImages');
76
+ if (cardiacNumberOfImages === undefined) {
77
+ return null;
78
+ }
79
+ const stacks = new Map();
80
+ for (const imageId of imageIds) {
81
+ const stackId = metaData.get('StackID', imageId);
82
+ const inStackPositionNumber = getFiniteValue(imageId, 'InStackPositionNumber');
83
+ const triggerTime = getFiniteValue(imageId, 'TriggerTime');
84
+ if (stackId === undefined ||
85
+ inStackPositionNumber === undefined ||
86
+ triggerTime === undefined) {
87
+ return null;
88
+ }
89
+ const stackKey = String(stackId);
90
+ if (!stacks.has(stackKey)) {
91
+ stacks.set(stackKey, new Map());
92
+ }
93
+ const positions = stacks.get(stackKey);
94
+ if (!positions.has(inStackPositionNumber)) {
95
+ positions.set(inStackPositionNumber, []);
96
+ }
97
+ positions.get(inStackPositionNumber).push({ imageId, triggerTime });
98
+ }
99
+ const sortedStackIds = Array.from(stacks.keys()).sort((a, b) => Number(a) - Number(b));
100
+ if (sortedStackIds.length === 0) {
101
+ return null;
102
+ }
103
+ const preparedStacks = [];
104
+ let timeCount;
105
+ for (const stackId of sortedStackIds) {
106
+ const positions = stacks.get(stackId);
107
+ const sortedPositions = Array.from(positions.keys()).sort((a, b) => a - b);
108
+ for (const position of sortedPositions) {
109
+ const frames = positions.get(position);
110
+ frames.sort((a, b) => a.triggerTime - b.triggerTime);
111
+ if (timeCount === undefined) {
112
+ timeCount = frames.length;
113
+ }
114
+ else if (frames.length !== timeCount) {
115
+ return null;
116
+ }
117
+ }
118
+ preparedStacks.push({
119
+ stackId,
120
+ positions: sortedPositions,
121
+ framesByPosition: positions,
122
+ });
123
+ }
124
+ if (!timeCount) {
125
+ return null;
126
+ }
127
+ const imageIdGroups = [];
128
+ for (let timeIndex = 0; timeIndex < timeCount; timeIndex++) {
129
+ const group = [];
130
+ for (const stack of preparedStacks) {
131
+ for (const position of stack.positions) {
132
+ const frames = stack.framesByPosition.get(position);
133
+ group.push(frames[timeIndex].imageId);
134
+ }
135
+ }
136
+ imageIdGroups.push(group);
137
+ }
138
+ return {
139
+ imageIdGroups,
140
+ splittingTag: 'CardiacTriggerTime',
141
+ };
142
+ }
143
+ const groupBy = (array, key) => {
144
+ return array.reduce((rv, x) => {
145
+ (rv[x[key]] = rv[x[key]] || []).push(x);
146
+ return rv;
147
+ }, {});
148
+ };
149
+ function getIPPGroups(imageIds) {
150
+ const ippMetadata = imageIds.map((imageId) => {
151
+ const { imagePositionPatient } = metaData.get('imagePlaneModule', imageId) || {};
152
+ return { imageId, imagePositionPatient };
153
+ });
154
+ if (!ippMetadata.every((item) => item.imagePositionPatient)) {
155
+ return null;
156
+ }
157
+ const positionGroups = groupBy(ippMetadata, 'imagePositionPatient');
158
+ const positions = Object.keys(positionGroups);
159
+ const frame_count = positionGroups[positions[0]].length;
160
+ if (frame_count === 1) {
161
+ return null;
162
+ }
163
+ const frame_count_equal = positions.every((k) => positionGroups[k].length === frame_count);
164
+ if (!frame_count_equal) {
165
+ return null;
166
+ }
167
+ return positionGroups;
168
+ }
169
+ function test4DTag(IPPGroups, value_getter) {
170
+ const frame_groups = {};
171
+ let first_frame_value_set = [];
172
+ const positions = Object.keys(IPPGroups);
173
+ for (let i = 0; i < positions.length; i++) {
174
+ const frame_value_set = new Set();
175
+ const frames = IPPGroups[positions[i]];
176
+ for (let j = 0; j < frames.length; j++) {
177
+ const frame_value = value_getter(frames[j].imageId) || 0;
178
+ frame_groups[frame_value] = frame_groups[frame_value] || [];
179
+ frame_groups[frame_value].push({ imageId: frames[j].imageId });
180
+ frame_value_set.add(frame_value);
181
+ if (frame_value_set.size - 1 < j) {
182
+ return undefined;
183
+ }
184
+ }
185
+ if (i == 0) {
186
+ first_frame_value_set = Array.from(frame_value_set);
187
+ }
188
+ else if (!setEquals(first_frame_value_set, frame_value_set)) {
189
+ return undefined;
190
+ }
191
+ }
192
+ return frame_groups;
193
+ }
194
+ function getTagValue(imageId, tag) {
195
+ const value = metaData.get(tag, imageId);
196
+ try {
197
+ return parseFloat(value);
198
+ }
199
+ catch {
200
+ return undefined;
201
+ }
202
+ }
203
+ function getFiniteValue(imageId, tag) {
204
+ return toFiniteNumber(getTagValue(imageId, tag));
205
+ }
206
+ function getPhilipsPrivateBValue(imageId) {
207
+ const value = metaData.get('20011003', imageId);
208
+ try {
209
+ const { InlineBinary } = value;
210
+ if (InlineBinary) {
211
+ const value_bytes = atob(InlineBinary);
212
+ const ary_buf = new ArrayBuffer(value_bytes.length);
213
+ const dv = new DataView(ary_buf);
214
+ for (let i = 0; i < value_bytes.length; i++) {
215
+ dv.setUint8(i, value_bytes.charCodeAt(i));
216
+ }
217
+ return new Float32Array(ary_buf)[0];
218
+ }
219
+ return parseFloat(value);
220
+ }
221
+ catch {
222
+ return undefined;
223
+ }
224
+ }
225
+ function getSiemensPrivateBValue(imageId) {
226
+ let value = metaData.get('0019100c', imageId) || metaData.get('0019100C', imageId);
227
+ try {
228
+ const { InlineBinary } = value;
229
+ if (InlineBinary) {
230
+ value = atob(InlineBinary);
231
+ }
232
+ return parseFloat(value);
233
+ }
234
+ catch {
235
+ return undefined;
236
+ }
237
+ }
238
+ function getGEPrivateBValue(imageId) {
239
+ let value = metaData.get('00431039', imageId);
240
+ try {
241
+ const { InlineBinary } = value;
242
+ if (InlineBinary) {
243
+ value = atob(InlineBinary).split('//');
244
+ }
245
+ return parseFloat(value[0]) % 100000;
246
+ }
247
+ catch {
248
+ return undefined;
249
+ }
250
+ }
251
+ function setEquals(set_a, set_b) {
252
+ if (set_a.length != set_b.size) {
253
+ return false;
254
+ }
255
+ for (let i = 0; i < set_a.length; i++) {
256
+ if (!set_b.has(set_a[i])) {
257
+ return false;
258
+ }
259
+ }
260
+ return true;
261
+ }
262
+ function getPetFrameReferenceTime(imageId) {
263
+ const moduleInfo = metaData.get('petImageModule', imageId);
264
+ return moduleInfo ? moduleInfo['frameReferenceTime'] : 0;
265
+ }
266
+ function splitImageIdsBy4DTags(imageIds) {
267
+ const multiframeResult = handleMultiframe4D(imageIds);
268
+ if (multiframeResult) {
269
+ return multiframeResult;
270
+ }
271
+ const cardiacResult = handleCardiac4D(imageIds);
272
+ if (cardiacResult) {
273
+ return cardiacResult;
274
+ }
275
+ const positionGroups = getIPPGroups(imageIds);
276
+ if (!positionGroups) {
277
+ return { imageIdGroups: [imageIds], splittingTag: null };
278
+ }
279
+ const tags = [
280
+ 'TemporalPositionIdentifier',
281
+ 'DiffusionBValue',
282
+ 'TriggerTime',
283
+ 'EchoTime',
284
+ 'EchoNumber',
285
+ 'PhilipsPrivateBValue',
286
+ 'SiemensPrivateBValue',
287
+ 'GEPrivateBValue',
288
+ 'PetFrameReferenceTime',
289
+ ];
290
+ const fncList2 = [
291
+ (imageId) => getTagValue(imageId, tags[0]),
292
+ (imageId) => getTagValue(imageId, tags[1]),
293
+ (imageId) => getTagValue(imageId, tags[2]),
294
+ (imageId) => getTagValue(imageId, tags[3]),
295
+ (imageId) => getTagValue(imageId, tags[4]),
296
+ getPhilipsPrivateBValue,
297
+ getSiemensPrivateBValue,
298
+ getGEPrivateBValue,
299
+ getPetFrameReferenceTime,
300
+ ];
301
+ for (let i = 0; i < fncList2.length; i++) {
302
+ const frame_groups = test4DTag(positionGroups, fncList2[i]);
303
+ if (frame_groups) {
304
+ const sortedKeys = Object.keys(frame_groups)
305
+ .map(Number.parseFloat)
306
+ .sort((a, b) => a - b);
307
+ const imageIdGroups = sortedKeys.map((key) => frame_groups[key].map((item) => item.imageId));
308
+ return { imageIdGroups, splittingTag: tags[i] };
309
+ }
310
+ }
311
+ return { imageIdGroups: [imageIds], splittingTag: null };
312
+ }
313
+ export default splitImageIdsBy4DTags;
314
+ export { handleMultiframe4D, generateFrameImageId };
@@ -0,0 +1,2 @@
1
+ export { toNumber, toFiniteNumber } from '@cornerstonejs/utils';
2
+ export { toNumber as default } from '@cornerstonejs/utils';
@@ -0,0 +1,2 @@
1
+ export { toNumber, toFiniteNumber } from '@cornerstonejs/utils';
2
+ export { toNumber as default } from '@cornerstonejs/utils';
@@ -0,0 +1 @@
1
+ export declare const version = "5.0.0";
@@ -0,0 +1 @@
1
+ export const version = '5.0.0';
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@cornerstonejs/metadata",
3
+ "version": "5.0.0",
4
+ "description": "Cornerstone3D Metadata Foundation - Provider chain, DICOM stream parsing, tag modules, and series splitting",
5
+ "module": "./dist/esm/index.js",
6
+ "types": "./dist/esm/index.d.ts",
7
+ "repository": "https://github.com/cornerstonejs/cornerstone3D",
8
+ "files": [
9
+ "./dist/"
10
+ ],
11
+ "sideEffects": false,
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/esm/index.js",
15
+ "node": "./dist/esm/index.js",
16
+ "types": "./dist/esm/index.d.ts"
17
+ },
18
+ "./metaData": {
19
+ "import": "./dist/esm/metaData.js",
20
+ "node": "./dist/esm/metaData.js",
21
+ "types": "./dist/esm/metaData.d.ts"
22
+ },
23
+ "./enums": {
24
+ "import": "./dist/esm/enums/index.js",
25
+ "node": "./dist/esm/enums/index.js",
26
+ "types": "./dist/esm/enums/index.d.ts"
27
+ },
28
+ "./enums/*": {
29
+ "import": "./dist/esm/enums/*.js",
30
+ "node": "./dist/esm/enums/*.js",
31
+ "types": "./dist/esm/enums/*.d.ts"
32
+ },
33
+ "./utilities": {
34
+ "import": "./dist/esm/utilities/index.js",
35
+ "node": "./dist/esm/utilities/index.js",
36
+ "types": "./dist/esm/utilities/index.d.ts"
37
+ },
38
+ "./utilities/dicomStream": {
39
+ "import": "./dist/esm/utilities/dicomStream/index.js",
40
+ "node": "./dist/esm/utilities/dicomStream/index.js",
41
+ "types": "./dist/esm/utilities/dicomStream/index.d.ts"
42
+ },
43
+ "./utilities/metadataProvider": {
44
+ "import": "./dist/esm/utilities/metadataProvider/index.js",
45
+ "node": "./dist/esm/utilities/metadataProvider/index.js",
46
+ "types": "./dist/esm/utilities/metadataProvider/index.d.ts"
47
+ },
48
+ "./utilities/*": {
49
+ "import": "./dist/esm/utilities/*.js",
50
+ "node": "./dist/esm/utilities/*.js",
51
+ "types": "./dist/esm/utilities/*.d.ts"
52
+ },
53
+ "./types": {
54
+ "types": "./dist/esm/types/index.d.ts"
55
+ },
56
+ "./types/*": {
57
+ "types": "./dist/esm/types/*.d.ts"
58
+ },
59
+ "./version": {
60
+ "import": "./dist/esm/version.js",
61
+ "node": "./dist/esm/version.js",
62
+ "types": "./dist/esm/version.d.ts"
63
+ }
64
+ },
65
+ "publishConfig": {
66
+ "access": "public"
67
+ },
68
+ "scripts": {
69
+ "prebuild": "node ../../scripts/generate-version.js ./",
70
+ "build:esm": "pnpm run prebuild && tsc --project ./tsconfig.json",
71
+ "build:esm:watch": "tsc --project ./tsconfig.json --watch",
72
+ "clean": "rm -rf node_modules/.cache/storybook && shx rm -rf dist",
73
+ "clean:deep": "pnpm run clean && shx rm -rf node_modules",
74
+ "build": "pnpm run build:esm",
75
+ "build:all": "pnpm run build:esm",
76
+ "dev": "tsc --project ./tsconfig.json --watch",
77
+ "api-check": "api-extractor --debug run",
78
+ "lint": "oxlint .",
79
+ "prepublishOnly": "pnpm run build"
80
+ },
81
+ "dependencies": {
82
+ "@cornerstonejs/calculate-suv": "1.0.3",
83
+ "@cornerstonejs/utils": "5.0.0",
84
+ "dcmjs": "0.50.1",
85
+ "gl-matrix": "3.4.3"
86
+ },
87
+ "contributors": [
88
+ {
89
+ "name": "Cornerstone.js Contributors",
90
+ "url": "https://github.com/orgs/cornerstonejs/people"
91
+ }
92
+ ],
93
+ "license": "MIT",
94
+ "funding": {
95
+ "type": "individual",
96
+ "url": "https://ohif.org/donate"
97
+ },
98
+ "gitHead": "d6f3fba43abcbaaf7468ff534588f6a88720b875"
99
+ }