@dcmjs-org/dicomdir 0.0.0-stage → 1.0.0-beta.10

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.
package/License.txt ADDED
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2017 Steve Pieper
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
- # Temporary Holding Version
1
+ # @dcmjs-org/dicomdir
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DICOMDIR (Media Storage Directory, PS3.10 / PS3.3 Annex F) building and
4
+ writing — the index file at the root of patient CDs, DVDs, and USB media.
5
+
6
+ Give `writeDicomDir` a flat list of file-set entries (one per referenced
7
+ file) and it builds the PATIENT → STUDY → SERIES → leaf directory record
8
+ hierarchy, computes the real byte offsets that link the records
9
+ (`OffsetOfTheNextDirectoryRecord`,
10
+ `OffsetOfReferencedLowerLevelDirectoryEntity`, and the root first/last
11
+ record offsets), and serializes the complete Part 10 file in a single
12
+ pass — no patch-and-rewrite, no buffer scanning.
13
+
14
+ Grouping is automatic and unbounded: entries are bucketed by `PatientID`,
15
+ then `StudyInstanceUID`, then `SeriesInstanceUID`, so any mix of patients,
16
+ studies, and series on one piece of media comes out as the correct tree
17
+ with sibling records chained at every level. The media below carries two
18
+ patients — one with two studies — and the records land as
19
+
20
+ ```
21
+ PATIENT DOE^JANE ─ STUDY 1.2.3.4 ─ SERIES MR ─ IMAGE IM000001
22
+ └ STUDY 1.2.9.9 ─ SERIES CT ─ IMAGE IM000002
23
+ PATIENT FOX^SAM ─ STUDY 5.6.7.8 ─ SERIES US ─ IMAGE IM000003
24
+ ```
25
+
26
+ ```js
27
+ import { writeDicomDir } from "@dcmjs-org/dicomdir";
28
+
29
+ const mr = {
30
+ referencedFileID: ["DICOM", "IM000001"],
31
+ sopClassUid: "1.2.840.10008.5.1.4.1.1.4",
32
+ sopInstanceUid: "1.2.3.4.100",
33
+ transferSyntaxUid: "1.2.840.10008.1.2.1",
34
+ patient: { PatientID: "998877", PatientName: "DOE^JANE" },
35
+ study: { StudyInstanceUID: "1.2.3.4" },
36
+ series: { SeriesInstanceUID: "1.2.3.4.5", Modality: "MR" },
37
+ instance: { InstanceNumber: 1 }
38
+ };
39
+
40
+ // Same patient, second study.
41
+ const ct = {
42
+ ...mr,
43
+ referencedFileID: ["DICOM", "IM000002"],
44
+ sopClassUid: "1.2.840.10008.5.1.4.1.1.2",
45
+ sopInstanceUid: "1.2.9.9.100",
46
+ study: { StudyInstanceUID: "1.2.9.9" },
47
+ series: { SeriesInstanceUID: "1.2.9.9.1", Modality: "CT" }
48
+ };
49
+
50
+ // Different patient entirely.
51
+ const us = {
52
+ ...mr,
53
+ referencedFileID: ["DICOM", "IM000003"],
54
+ sopClassUid: "1.2.840.10008.5.1.4.1.1.6.1",
55
+ sopInstanceUid: "5.6.7.8.100",
56
+ patient: { PatientID: "112233", PatientName: "FOX^SAM" },
57
+ study: { StudyInstanceUID: "5.6.7.8" },
58
+ series: { SeriesInstanceUID: "5.6.7.8.1", Modality: "US" }
59
+ };
60
+
61
+ const arrayBuffer = writeDicomDir([mr, ct, us], { fileSetID: "MY_CD" });
62
+ ```
63
+
64
+ `buildDicomDirDataset` exposes the record tree before serialization (all
65
+ offsets zero) for inspection or customization.
66
+
67
+ The package covers building and writing. Reading a DICOMDIR needs no
68
+ dedicated API — it is an ordinary Part 10 file, so either engine returns
69
+ the records as `DirectoryRecordSequence` — but there is no convenience
70
+ walker or QIDO-style query surface over those records yet; that follow-up
71
+ is tracked in
72
+ [#611](https://github.com/dcmjs-org/dcmjs/issues/611).
73
+
74
+ Depends only on `@dcmjs-org/core`.
package/dist/index.cjs ADDED
@@ -0,0 +1,487 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@dcmjs-org/core');
6
+
7
+ // packages/dicomdir/src/directoryOffsets.js
8
+ //
9
+ // Byte-offset computation for DICOMDIR directory records.
10
+ //
11
+ // The load-bearing fact: every DICOMDIR offset attribute (0004,1200/1202/
12
+ // 1400/1420) is VR UL — a fixed four-byte value — so the values NEVER affect
13
+ // the byte layout. One measurement pass over the exact structures the final
14
+ // write will serialize (same writer, same options, placeholder zeros)
15
+ // therefore yields the exact offsets of the final file, and the file is
16
+ // written once with the real values filled in.
17
+ //
18
+ // Layout being measured (mirrors the Part 10 envelope in dicomdir.js):
19
+ // 128-byte preamble + "DICM"
20
+ // FileMetaInformationGroupLength element
21
+ // meta group (Explicit VR Little Endian)
22
+ // body tags below (0004,1220), sorted ascending
23
+ // (0004,1220) DirectoryRecordSequence: 12-byte SQ header (undefined
24
+ // length), then per item: 8-byte item header (FFFE,E000, undefined
25
+ // length) + item body + 8-byte item delimiter (FFFE,E00D) — see
26
+ // SequenceOfItems.writeBytes — and a trailing 8-byte sequence delimiter.
27
+ //
28
+ // A directory-record offset points at the FFFE,E000 item tag of that record,
29
+ // counted from byte 0 of the file (PS3.10 8.6).
30
+
31
+
32
+ const DIRECTORY_RECORD_SEQUENCE = "00041220";
33
+
34
+ const ITEM_HEADER_BYTES = 8; // FFFE,E000 + 4-byte undefined length
35
+ const ITEM_DELIMITER_BYTES = 8; // FFFE,E00D + 4-byte zero length
36
+
37
+ /** Bytes writeDataSet produces for one tag-keyed object. */
38
+ function measure(jsonObject, writeOptions) {
39
+ const stream = new core.WriteBufferStream(1024);
40
+ core.writeDataSet(jsonObject, stream, core.EXPLICIT_LITTLE_ENDIAN, writeOptions);
41
+ return stream.size;
42
+ }
43
+
44
+ /**
45
+ * Compute the absolute byte offset of every directory record item in the
46
+ * file the Part 10 envelope write will produce. Call with the offsets
47
+ * still zero; patch the returned values in, then write — the layout is
48
+ * guaranteed identical because offsets are fixed-width.
49
+ *
50
+ * @param {{ meta: Object, dict: Object }} dicomDict - denaturalized
51
+ * DICOMDIR ({ meta, dict }) whose dict contains (0004,1220)
52
+ * @param {Object} writeOptions - the SAME object later passed to write()
53
+ * @returns {number[]} byte offset of each record's item tag, in item order
54
+ */
55
+ function computeDirectoryOffsets(dicomDict, writeOptions) {
56
+ // Preamble + magic.
57
+ let cursor = 128 + 4;
58
+
59
+ // FileMetaInformationGroupLength + meta group. The group length element
60
+ // is measured with the real meta size as its value — UL again, so the
61
+ // element size is value-independent, but measuring keeps zero assumptions.
62
+ const metaSize = measure(dicomDict.meta, writeOptions);
63
+ const groupLengthStream = new core.WriteBufferStream(64);
64
+ core.writeTagObject(
65
+ groupLengthStream,
66
+ core.TagHex.FileMetaInformationGroupLength,
67
+ "UL",
68
+ metaSize,
69
+ core.EXPLICIT_LITTLE_ENDIAN,
70
+ writeOptions
71
+ );
72
+ cursor += groupLengthStream.size + metaSize;
73
+
74
+ // Body tags before the record sequence, in the writer's sorted order.
75
+ const bodyTags = Object.keys(dicomDict.dict).sort();
76
+ for (const tag of bodyTags) {
77
+ if (tag >= DIRECTORY_RECORD_SEQUENCE) {
78
+ break;
79
+ }
80
+ cursor += measure({ [tag]: dicomDict.dict[tag] }, writeOptions);
81
+ }
82
+
83
+ // SQ element header: measure an empty sequence (header + 8-byte
84
+ // sequence delimiter) rather than assuming the 12-byte constant.
85
+ const sequence = dicomDict.dict[DIRECTORY_RECORD_SEQUENCE];
86
+ const emptySequenceSize = measure(
87
+ { [DIRECTORY_RECORD_SEQUENCE]: { vr: "SQ", Value: [] } },
88
+ writeOptions
89
+ );
90
+ cursor += emptySequenceSize - ITEM_DELIMITER_BYTES;
91
+
92
+ const offsets = [];
93
+ const items = (sequence && sequence.Value) || [];
94
+ for (const item of items) {
95
+ offsets.push(cursor);
96
+ cursor +=
97
+ ITEM_HEADER_BYTES +
98
+ measure(item, writeOptions) +
99
+ ITEM_DELIMITER_BYTES;
100
+ }
101
+
102
+ return offsets;
103
+ }
104
+
105
+ // packages/dicomdir/src/dicomdir.js
106
+ //
107
+ // DICOMDIR (Media Storage Directory, PS3.10 / PS3.3 F) builder. Turns a flat
108
+ // file-set description into the PATIENT -> STUDY -> SERIES -> leaf record
109
+ // hierarchy and serializes it with real byte offsets in the three offset
110
+ // attributes (OffsetOfTheNextDirectoryRecord, OffsetOfReferencedLowerLevel-
111
+ // DirectoryEntity, and the root first/last record offsets).
112
+ //
113
+ // Offsets are computed by measure-then-write (see directoryOffsets.js): every
114
+ // offset attribute is VR UL — fixed four bytes — so a measurement pass with
115
+ // placeholder zeros produces the exact final layout, and the file is written
116
+ // once. No patch-and-rewrite, no buffer scanning.
117
+
118
+
119
+ const MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID = "1.2.840.10008.1.3.10";
120
+
121
+ // PS3.10 8.5: each File ID component is 1-8 characters from the ISO 9660
122
+ // level 1 repertoire (A-Z, 0-9, underscore), at most 8 components deep.
123
+ const FILE_ID_COMPONENT = /^[A-Z0-9_]{1,8}$/;
124
+
125
+ function assertEntry(entry, index) {
126
+ const where = `buildDicomDirDataset: entries[${index}]`;
127
+ if (!entry || typeof entry !== "object") {
128
+ throw new Error(`${where} is not an object`);
129
+ }
130
+ if (
131
+ !Array.isArray(entry.referencedFileID) ||
132
+ !entry.referencedFileID.length
133
+ ) {
134
+ throw new Error(
135
+ `${where}.referencedFileID must be a non-empty array of path components`
136
+ );
137
+ }
138
+ for (const required of [
139
+ "sopClassUid",
140
+ "sopInstanceUid",
141
+ "transferSyntaxUid"
142
+ ]) {
143
+ if (!entry[required]) {
144
+ throw new Error(`${where}.${required} is required`);
145
+ }
146
+ }
147
+ if (!entry.patient?.PatientID) {
148
+ throw new Error(`${where}.patient.PatientID is required`);
149
+ }
150
+ if (!entry.study?.StudyInstanceUID) {
151
+ throw new Error(`${where}.study.StudyInstanceUID is required`);
152
+ }
153
+ if (!entry.series?.SeriesInstanceUID) {
154
+ throw new Error(`${where}.series.SeriesInstanceUID is required`);
155
+ }
156
+ }
157
+
158
+ function assertFileID(components, index, allowNonConforming) {
159
+ if (components.length > 8) {
160
+ throw new Error(
161
+ `buildDicomDirDataset: entries[${index}].referencedFileID has ` +
162
+ `${components.length} components (max 8)`
163
+ );
164
+ }
165
+ if (allowNonConforming) {
166
+ return;
167
+ }
168
+ for (const component of components) {
169
+ if (!FILE_ID_COMPONENT.test(component)) {
170
+ throw new Error(
171
+ `buildDicomDirDataset: entries[${index}].referencedFileID ` +
172
+ `component "${component}" is not ISO 9660 level 1 ` +
173
+ `conformant (A-Z 0-9 _, 1-8 chars) — rename the file or ` +
174
+ `pass allowNonConformingFileIDs: true`
175
+ );
176
+ }
177
+ }
178
+ }
179
+
180
+ /** The four keys every directory record starts with (PS3.3 F.3). */
181
+ function recordCommon(recordType) {
182
+ return {
183
+ OffsetOfTheNextDirectoryRecord: 0,
184
+ RecordInUseFlag: 0xffff,
185
+ OffsetOfReferencedLowerLevelDirectoryEntity: 0,
186
+ DirectoryRecordType: recordType
187
+ };
188
+ }
189
+
190
+ /**
191
+ * Group the flat entries into the PATIENT -> STUDY -> SERIES -> leaf tree,
192
+ * preserving first-seen order at every level.
193
+ */
194
+ function groupEntries(entries, options) {
195
+ const patients = new Map();
196
+ entries.forEach((entry, index) => {
197
+ assertEntry(entry, index);
198
+ assertFileID(
199
+ entry.referencedFileID,
200
+ index,
201
+ options.allowNonConformingFileIDs
202
+ );
203
+
204
+ const patientKey = entry.patient.PatientID;
205
+ if (!patients.has(patientKey)) {
206
+ patients.set(patientKey, {
207
+ attributes: entry.patient,
208
+ studies: new Map()
209
+ });
210
+ }
211
+ const patient = patients.get(patientKey);
212
+
213
+ const studyKey = entry.study.StudyInstanceUID;
214
+ if (!patient.studies.has(studyKey)) {
215
+ patient.studies.set(studyKey, {
216
+ attributes: entry.study,
217
+ series: new Map()
218
+ });
219
+ }
220
+ const study = patient.studies.get(studyKey);
221
+
222
+ const seriesKey = entry.series.SeriesInstanceUID;
223
+ if (!study.series.has(seriesKey)) {
224
+ study.series.set(seriesKey, {
225
+ attributes: entry.series,
226
+ leaves: []
227
+ });
228
+ }
229
+ study.series.get(seriesKey).leaves.push(entry);
230
+ });
231
+ return patients;
232
+ }
233
+
234
+ /**
235
+ * Flatten the tree depth-first into naturalized record objects, tracking the
236
+ * flat index of each record's next sibling and first child so the offset
237
+ * pass can wire the chains. Depth-first order means every link points
238
+ * strictly forward in the file.
239
+ *
240
+ * @returns {{ records: Object[], links: Array<{next: number|null, child: number|null}> }}
241
+ */
242
+ function flattenRecords(patients) {
243
+ const records = [];
244
+ const links = [];
245
+
246
+ const push = record => {
247
+ records.push(record);
248
+ links.push({ next: null, child: null });
249
+ return records.length - 1;
250
+ };
251
+
252
+ const patientList = [...patients.values()];
253
+ let previousPatientIndex = null;
254
+
255
+ for (const patient of patientList) {
256
+ const patientIndex = push({
257
+ ...recordCommon("PATIENT"),
258
+ PatientName: patient.attributes.PatientName ?? "",
259
+ PatientID: patient.attributes.PatientID
260
+ });
261
+ if (previousPatientIndex !== null) {
262
+ links[previousPatientIndex].next = patientIndex;
263
+ }
264
+ previousPatientIndex = patientIndex;
265
+
266
+ const studyList = [...patient.studies.values()];
267
+ let previousStudyIndex = null;
268
+ for (const study of studyList) {
269
+ const studyIndex = push({
270
+ ...recordCommon("STUDY"),
271
+ StudyDate: study.attributes.StudyDate ?? "",
272
+ StudyTime: study.attributes.StudyTime ?? "",
273
+ StudyDescription: study.attributes.StudyDescription ?? "",
274
+ AccessionNumber: study.attributes.AccessionNumber ?? "",
275
+ StudyInstanceUID: study.attributes.StudyInstanceUID,
276
+ StudyID: study.attributes.StudyID ?? ""
277
+ });
278
+ if (previousStudyIndex === null) {
279
+ links[patientIndex].child = studyIndex;
280
+ } else {
281
+ links[previousStudyIndex].next = studyIndex;
282
+ }
283
+ previousStudyIndex = studyIndex;
284
+
285
+ const seriesList = [...study.series.values()];
286
+ let previousSeriesIndex = null;
287
+ for (const series of seriesList) {
288
+ const seriesIndex = push({
289
+ ...recordCommon("SERIES"),
290
+ Modality: series.attributes.Modality ?? "OT",
291
+ SeriesInstanceUID: series.attributes.SeriesInstanceUID,
292
+ SeriesNumber: series.attributes.SeriesNumber ?? 1
293
+ });
294
+ if (previousSeriesIndex === null) {
295
+ links[studyIndex].child = seriesIndex;
296
+ } else {
297
+ links[previousSeriesIndex].next = seriesIndex;
298
+ }
299
+ previousSeriesIndex = seriesIndex;
300
+
301
+ let previousLeafIndex = null;
302
+ for (const entry of series.leaves) {
303
+ const leafIndex = push({
304
+ ...recordCommon(entry.recordType || "IMAGE"),
305
+ ReferencedFileID: [...entry.referencedFileID],
306
+ ReferencedSOPClassUIDInFile: entry.sopClassUid,
307
+ ReferencedSOPInstanceUIDInFile: entry.sopInstanceUid,
308
+ ReferencedTransferSyntaxUIDInFile:
309
+ entry.transferSyntaxUid,
310
+ InstanceNumber: entry.instance?.InstanceNumber ?? 1,
311
+ ...entry.instance
312
+ });
313
+ if (previousLeafIndex === null) {
314
+ links[seriesIndex].child = leafIndex;
315
+ } else {
316
+ links[previousLeafIndex].next = leafIndex;
317
+ }
318
+ previousLeafIndex = leafIndex;
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+ return { records, links };
325
+ }
326
+
327
+ /**
328
+ * Build the naturalized DICOMDIR dataset (all offsets zero) plus the link
329
+ * table the offset pass needs. Pure and inspectable — no serialization.
330
+ *
331
+ * @param {Array} entries - flat file-set entries; see module JSDoc/typedef
332
+ * @param {Object} [options]
333
+ * @param {string} [options.fileSetID=""]
334
+ * @param {boolean} [options.allowNonConformingFileIDs=false]
335
+ * @returns {{ dataset: Object, links: Array, rootIndices: number[] }}
336
+ */
337
+ function buildDicomDirDataset(entries = [], options = {}) {
338
+ const patients = groupEntries(entries, options);
339
+ const { records, links } = flattenRecords(patients);
340
+
341
+ const rootIndices = [];
342
+ records.forEach((record, index) => {
343
+ if (record.DirectoryRecordType === "PATIENT") {
344
+ rootIndices.push(index);
345
+ }
346
+ });
347
+
348
+ const dataset = {
349
+ FileSetID: options.fileSetID ?? "",
350
+ OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity: 0,
351
+ OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity: 0,
352
+ FileSetConsistencyFlag: 0,
353
+ DirectoryRecordSequence: records
354
+ };
355
+
356
+ return { dataset, links, rootIndices };
357
+ }
358
+
359
+ /** Mint the DICOMDIR file meta group (SOP identity lives here, not the body). */
360
+ function buildDicomDirMeta(options = {}) {
361
+ const fileMetaInformationVersion = new Uint8Array(2);
362
+ fileMetaInformationVersion[1] = 1;
363
+ return core.DicomMetaDictionary.denaturalizeDataset({
364
+ FileMetaInformationVersion: fileMetaInformationVersion.buffer,
365
+ MediaStorageSOPClassUID: MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID,
366
+ MediaStorageSOPInstanceUID:
367
+ options.fileSetUID || core.DicomMetaDictionary.uid(),
368
+ TransferSyntaxUID: core.EXPLICIT_LITTLE_ENDIAN,
369
+ ImplementationClassUID:
370
+ "2.25.80302813137786398554742050926734630921603366648225212145404",
371
+ ImplementationVersionName: "dcmjs-0.0"
372
+ });
373
+ }
374
+
375
+ /**
376
+ * Build and serialize a complete DICOMDIR: build the record tree,
377
+ * denaturalize it, measure the layout, wire the offset chains, write once.
378
+ *
379
+ * @param {Array} entries - flat file-set entries
380
+ * @param {Object} [options] - buildDicomDirDataset options plus
381
+ * {string} [options.fileSetUID] fixed MediaStorageSOPInstanceUID
382
+ * @returns {ArrayBuffer} the DICOMDIR file bytes
383
+ */
384
+ /**
385
+ * The DICOM data dictionary gives the directory offset attributes the
386
+ * special VR "up" (byte offset); the dcmjs writer has no "up" representation
387
+ * and would fall back to UN. They are four-byte unsigned offsets — pin them
388
+ * to UL so they serialize (and measure) as the fixed-width values the
389
+ * offset algorithm depends on.
390
+ */
391
+ function pinOffsetVRs(dict) {
392
+ for (const tag of ["00041200", "00041202"]) {
393
+ if (dict[tag]) {
394
+ dict[tag].vr = "UL";
395
+ }
396
+ }
397
+ const items = dict["00041220"]?.Value || [];
398
+ for (const item of items) {
399
+ for (const tag of ["00041400", "00041420"]) {
400
+ if (item[tag]) {
401
+ item[tag].vr = "UL";
402
+ }
403
+ }
404
+ }
405
+ }
406
+
407
+ /**
408
+ * Serialize { meta, dict } as a Part 10 file. This is the body of
409
+ * DicomDict.write (packages/legacy) minus the deflate branch — a DICOMDIR
410
+ * is always Explicit VR Little Endian, never deflated — rebuilt on core's
411
+ * writeDataSet/writeTagObject so this package does not depend on
412
+ * @dcmjs-org/legacy. DicomMessage.write and DicomMessage.writeTagObject
413
+ * are one-line delegates to those same core functions, so the bytes this
414
+ * produces are identical to DicomDict.write's, which is what keeps the
415
+ * measured directory offsets valid.
416
+ */
417
+ function writePart10(meta, dict, writeOptions) {
418
+ const metaSyntax = core.EXPLICIT_LITTLE_ENDIAN;
419
+ const fileStream = new core.WriteBufferStream(4096, true);
420
+ fileStream.writeUint8Repeat(0, 128);
421
+ fileStream.writeAsciiString("DICM");
422
+
423
+ const metaStream = new core.WriteBufferStream(1024);
424
+ if (!meta[core.TagHex.TransferSyntaxUID]) {
425
+ meta[core.TagHex.TransferSyntaxUID] = {
426
+ vr: "UI",
427
+ Value: [core.EXPLICIT_LITTLE_ENDIAN]
428
+ };
429
+ }
430
+ core.writeDataSet(meta, metaStream, metaSyntax, writeOptions);
431
+ core.writeTagObject(
432
+ fileStream,
433
+ core.TagHex.FileMetaInformationGroupLength,
434
+ "UL",
435
+ metaStream.size,
436
+ metaSyntax,
437
+ writeOptions
438
+ );
439
+ fileStream.concat(metaStream);
440
+
441
+ const useSyntax = meta[core.TagHex.TransferSyntaxUID].Value[0];
442
+ core.writeDataSet(dict, fileStream, useSyntax, writeOptions);
443
+ return fileStream.getBuffer();
444
+ }
445
+
446
+ function writeDicomDir(entries = [], options = {}) {
447
+ const { dataset, links, rootIndices } = buildDicomDirDataset(
448
+ entries,
449
+ options
450
+ );
451
+
452
+ const meta = buildDicomDirMeta(options);
453
+ const dict = core.DicomMetaDictionary.denaturalizeDataset(dataset);
454
+ pinOffsetVRs(dict);
455
+
456
+ const writeOptions = { allowInvalidVRLength: false };
457
+ const recordOffsets = computeDirectoryOffsets({ meta, dict }, writeOptions);
458
+
459
+ const sequence = dict["00041220"];
460
+ const items = (sequence && sequence.Value) || [];
461
+ items.forEach((item, index) => {
462
+ const { next, child } = links[index];
463
+ item["00041400"].Value = [next === null ? 0 : recordOffsets[next]];
464
+ item["00041420"].Value = [child === null ? 0 : recordOffsets[child]];
465
+ });
466
+
467
+ const first = rootIndices.length ? recordOffsets[rootIndices[0]] : 0;
468
+ const last = rootIndices.length
469
+ ? recordOffsets[rootIndices[rootIndices.length - 1]]
470
+ : 0;
471
+ dict["00041200"].Value = [first];
472
+ dict["00041202"].Value = [last];
473
+
474
+ return writePart10(meta, dict, writeOptions);
475
+ }
476
+
477
+ var index = {
478
+ buildDicomDirDataset,
479
+ writeDicomDir,
480
+ MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID
481
+ };
482
+
483
+ exports.MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID = MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID;
484
+ exports.buildDicomDirDataset = buildDicomDirDataset;
485
+ exports.default = index;
486
+ exports.writeDicomDir = writeDicomDir;
487
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/directoryOffsets.js","../src/dicomdir.js","../src/index.js"],"sourcesContent":["// packages/dicomdir/src/directoryOffsets.js\n//\n// Byte-offset computation for DICOMDIR directory records.\n//\n// The load-bearing fact: every DICOMDIR offset attribute (0004,1200/1202/\n// 1400/1420) is VR UL — a fixed four-byte value — so the values NEVER affect\n// the byte layout. One measurement pass over the exact structures the final\n// write will serialize (same writer, same options, placeholder zeros)\n// therefore yields the exact offsets of the final file, and the file is\n// written once with the real values filled in.\n//\n// Layout being measured (mirrors the Part 10 envelope in dicomdir.js):\n// 128-byte preamble + \"DICM\"\n// FileMetaInformationGroupLength element\n// meta group (Explicit VR Little Endian)\n// body tags below (0004,1220), sorted ascending\n// (0004,1220) DirectoryRecordSequence: 12-byte SQ header (undefined\n// length), then per item: 8-byte item header (FFFE,E000, undefined\n// length) + item body + 8-byte item delimiter (FFFE,E00D) — see\n// SequenceOfItems.writeBytes — and a trailing 8-byte sequence delimiter.\n//\n// A directory-record offset points at the FFFE,E000 item tag of that record,\n// counted from byte 0 of the file (PS3.10 8.6).\n\nimport {\n WriteBufferStream,\n writeDataSet,\n writeTagObject,\n EXPLICIT_LITTLE_ENDIAN,\n TagHex\n} from \"@dcmjs-org/core\";\n\nconst DIRECTORY_RECORD_SEQUENCE = \"00041220\";\n\nconst ITEM_HEADER_BYTES = 8; // FFFE,E000 + 4-byte undefined length\nconst ITEM_DELIMITER_BYTES = 8; // FFFE,E00D + 4-byte zero length\n\n/** Bytes writeDataSet produces for one tag-keyed object. */\nfunction measure(jsonObject, writeOptions) {\n const stream = new WriteBufferStream(1024);\n writeDataSet(jsonObject, stream, EXPLICIT_LITTLE_ENDIAN, writeOptions);\n return stream.size;\n}\n\n/**\n * Compute the absolute byte offset of every directory record item in the\n * file the Part 10 envelope write will produce. Call with the offsets\n * still zero; patch the returned values in, then write — the layout is\n * guaranteed identical because offsets are fixed-width.\n *\n * @param {{ meta: Object, dict: Object }} dicomDict - denaturalized\n * DICOMDIR ({ meta, dict }) whose dict contains (0004,1220)\n * @param {Object} writeOptions - the SAME object later passed to write()\n * @returns {number[]} byte offset of each record's item tag, in item order\n */\nexport function computeDirectoryOffsets(dicomDict, writeOptions) {\n // Preamble + magic.\n let cursor = 128 + 4;\n\n // FileMetaInformationGroupLength + meta group. The group length element\n // is measured with the real meta size as its value — UL again, so the\n // element size is value-independent, but measuring keeps zero assumptions.\n const metaSize = measure(dicomDict.meta, writeOptions);\n const groupLengthStream = new WriteBufferStream(64);\n writeTagObject(\n groupLengthStream,\n TagHex.FileMetaInformationGroupLength,\n \"UL\",\n metaSize,\n EXPLICIT_LITTLE_ENDIAN,\n writeOptions\n );\n cursor += groupLengthStream.size + metaSize;\n\n // Body tags before the record sequence, in the writer's sorted order.\n const bodyTags = Object.keys(dicomDict.dict).sort();\n for (const tag of bodyTags) {\n if (tag >= DIRECTORY_RECORD_SEQUENCE) {\n break;\n }\n cursor += measure({ [tag]: dicomDict.dict[tag] }, writeOptions);\n }\n\n // SQ element header: measure an empty sequence (header + 8-byte\n // sequence delimiter) rather than assuming the 12-byte constant.\n const sequence = dicomDict.dict[DIRECTORY_RECORD_SEQUENCE];\n const emptySequenceSize = measure(\n { [DIRECTORY_RECORD_SEQUENCE]: { vr: \"SQ\", Value: [] } },\n writeOptions\n );\n cursor += emptySequenceSize - ITEM_DELIMITER_BYTES;\n\n const offsets = [];\n const items = (sequence && sequence.Value) || [];\n for (const item of items) {\n offsets.push(cursor);\n cursor +=\n ITEM_HEADER_BYTES +\n measure(item, writeOptions) +\n ITEM_DELIMITER_BYTES;\n }\n\n return offsets;\n}\n","// packages/dicomdir/src/dicomdir.js\n//\n// DICOMDIR (Media Storage Directory, PS3.10 / PS3.3 F) builder. Turns a flat\n// file-set description into the PATIENT -> STUDY -> SERIES -> leaf record\n// hierarchy and serializes it with real byte offsets in the three offset\n// attributes (OffsetOfTheNextDirectoryRecord, OffsetOfReferencedLowerLevel-\n// DirectoryEntity, and the root first/last record offsets).\n//\n// Offsets are computed by measure-then-write (see directoryOffsets.js): every\n// offset attribute is VR UL — fixed four bytes — so a measurement pass with\n// placeholder zeros produces the exact final layout, and the file is written\n// once. No patch-and-rewrite, no buffer scanning.\n\nimport {\n DicomMetaDictionary,\n WriteBufferStream,\n writeDataSet,\n writeTagObject,\n EXPLICIT_LITTLE_ENDIAN,\n TagHex\n} from \"@dcmjs-org/core\";\nimport { computeDirectoryOffsets } from \"./directoryOffsets.js\";\n\nconst MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID = \"1.2.840.10008.1.3.10\";\n\n// PS3.10 8.5: each File ID component is 1-8 characters from the ISO 9660\n// level 1 repertoire (A-Z, 0-9, underscore), at most 8 components deep.\nconst FILE_ID_COMPONENT = /^[A-Z0-9_]{1,8}$/;\n\nfunction assertEntry(entry, index) {\n const where = `buildDicomDirDataset: entries[${index}]`;\n if (!entry || typeof entry !== \"object\") {\n throw new Error(`${where} is not an object`);\n }\n if (\n !Array.isArray(entry.referencedFileID) ||\n !entry.referencedFileID.length\n ) {\n throw new Error(\n `${where}.referencedFileID must be a non-empty array of path components`\n );\n }\n for (const required of [\n \"sopClassUid\",\n \"sopInstanceUid\",\n \"transferSyntaxUid\"\n ]) {\n if (!entry[required]) {\n throw new Error(`${where}.${required} is required`);\n }\n }\n if (!entry.patient?.PatientID) {\n throw new Error(`${where}.patient.PatientID is required`);\n }\n if (!entry.study?.StudyInstanceUID) {\n throw new Error(`${where}.study.StudyInstanceUID is required`);\n }\n if (!entry.series?.SeriesInstanceUID) {\n throw new Error(`${where}.series.SeriesInstanceUID is required`);\n }\n}\n\nfunction assertFileID(components, index, allowNonConforming) {\n if (components.length > 8) {\n throw new Error(\n `buildDicomDirDataset: entries[${index}].referencedFileID has ` +\n `${components.length} components (max 8)`\n );\n }\n if (allowNonConforming) {\n return;\n }\n for (const component of components) {\n if (!FILE_ID_COMPONENT.test(component)) {\n throw new Error(\n `buildDicomDirDataset: entries[${index}].referencedFileID ` +\n `component \"${component}\" is not ISO 9660 level 1 ` +\n `conformant (A-Z 0-9 _, 1-8 chars) — rename the file or ` +\n `pass allowNonConformingFileIDs: true`\n );\n }\n }\n}\n\n/** The four keys every directory record starts with (PS3.3 F.3). */\nfunction recordCommon(recordType) {\n return {\n OffsetOfTheNextDirectoryRecord: 0,\n RecordInUseFlag: 0xffff,\n OffsetOfReferencedLowerLevelDirectoryEntity: 0,\n DirectoryRecordType: recordType\n };\n}\n\n/**\n * Group the flat entries into the PATIENT -> STUDY -> SERIES -> leaf tree,\n * preserving first-seen order at every level.\n */\nfunction groupEntries(entries, options) {\n const patients = new Map();\n entries.forEach((entry, index) => {\n assertEntry(entry, index);\n assertFileID(\n entry.referencedFileID,\n index,\n options.allowNonConformingFileIDs\n );\n\n const patientKey = entry.patient.PatientID;\n if (!patients.has(patientKey)) {\n patients.set(patientKey, {\n attributes: entry.patient,\n studies: new Map()\n });\n }\n const patient = patients.get(patientKey);\n\n const studyKey = entry.study.StudyInstanceUID;\n if (!patient.studies.has(studyKey)) {\n patient.studies.set(studyKey, {\n attributes: entry.study,\n series: new Map()\n });\n }\n const study = patient.studies.get(studyKey);\n\n const seriesKey = entry.series.SeriesInstanceUID;\n if (!study.series.has(seriesKey)) {\n study.series.set(seriesKey, {\n attributes: entry.series,\n leaves: []\n });\n }\n study.series.get(seriesKey).leaves.push(entry);\n });\n return patients;\n}\n\n/**\n * Flatten the tree depth-first into naturalized record objects, tracking the\n * flat index of each record's next sibling and first child so the offset\n * pass can wire the chains. Depth-first order means every link points\n * strictly forward in the file.\n *\n * @returns {{ records: Object[], links: Array<{next: number|null, child: number|null}> }}\n */\nfunction flattenRecords(patients) {\n const records = [];\n const links = [];\n\n const push = record => {\n records.push(record);\n links.push({ next: null, child: null });\n return records.length - 1;\n };\n\n const patientList = [...patients.values()];\n let previousPatientIndex = null;\n\n for (const patient of patientList) {\n const patientIndex = push({\n ...recordCommon(\"PATIENT\"),\n PatientName: patient.attributes.PatientName ?? \"\",\n PatientID: patient.attributes.PatientID\n });\n if (previousPatientIndex !== null) {\n links[previousPatientIndex].next = patientIndex;\n }\n previousPatientIndex = patientIndex;\n\n const studyList = [...patient.studies.values()];\n let previousStudyIndex = null;\n for (const study of studyList) {\n const studyIndex = push({\n ...recordCommon(\"STUDY\"),\n StudyDate: study.attributes.StudyDate ?? \"\",\n StudyTime: study.attributes.StudyTime ?? \"\",\n StudyDescription: study.attributes.StudyDescription ?? \"\",\n AccessionNumber: study.attributes.AccessionNumber ?? \"\",\n StudyInstanceUID: study.attributes.StudyInstanceUID,\n StudyID: study.attributes.StudyID ?? \"\"\n });\n if (previousStudyIndex === null) {\n links[patientIndex].child = studyIndex;\n } else {\n links[previousStudyIndex].next = studyIndex;\n }\n previousStudyIndex = studyIndex;\n\n const seriesList = [...study.series.values()];\n let previousSeriesIndex = null;\n for (const series of seriesList) {\n const seriesIndex = push({\n ...recordCommon(\"SERIES\"),\n Modality: series.attributes.Modality ?? \"OT\",\n SeriesInstanceUID: series.attributes.SeriesInstanceUID,\n SeriesNumber: series.attributes.SeriesNumber ?? 1\n });\n if (previousSeriesIndex === null) {\n links[studyIndex].child = seriesIndex;\n } else {\n links[previousSeriesIndex].next = seriesIndex;\n }\n previousSeriesIndex = seriesIndex;\n\n let previousLeafIndex = null;\n for (const entry of series.leaves) {\n const leafIndex = push({\n ...recordCommon(entry.recordType || \"IMAGE\"),\n ReferencedFileID: [...entry.referencedFileID],\n ReferencedSOPClassUIDInFile: entry.sopClassUid,\n ReferencedSOPInstanceUIDInFile: entry.sopInstanceUid,\n ReferencedTransferSyntaxUIDInFile:\n entry.transferSyntaxUid,\n InstanceNumber: entry.instance?.InstanceNumber ?? 1,\n ...entry.instance\n });\n if (previousLeafIndex === null) {\n links[seriesIndex].child = leafIndex;\n } else {\n links[previousLeafIndex].next = leafIndex;\n }\n previousLeafIndex = leafIndex;\n }\n }\n }\n }\n\n return { records, links };\n}\n\n/**\n * Build the naturalized DICOMDIR dataset (all offsets zero) plus the link\n * table the offset pass needs. Pure and inspectable — no serialization.\n *\n * @param {Array} entries - flat file-set entries; see module JSDoc/typedef\n * @param {Object} [options]\n * @param {string} [options.fileSetID=\"\"]\n * @param {boolean} [options.allowNonConformingFileIDs=false]\n * @returns {{ dataset: Object, links: Array, rootIndices: number[] }}\n */\nfunction buildDicomDirDataset(entries = [], options = {}) {\n const patients = groupEntries(entries, options);\n const { records, links } = flattenRecords(patients);\n\n const rootIndices = [];\n records.forEach((record, index) => {\n if (record.DirectoryRecordType === \"PATIENT\") {\n rootIndices.push(index);\n }\n });\n\n const dataset = {\n FileSetID: options.fileSetID ?? \"\",\n OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity: 0,\n OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity: 0,\n FileSetConsistencyFlag: 0,\n DirectoryRecordSequence: records\n };\n\n return { dataset, links, rootIndices };\n}\n\n/** Mint the DICOMDIR file meta group (SOP identity lives here, not the body). */\nfunction buildDicomDirMeta(options = {}) {\n const fileMetaInformationVersion = new Uint8Array(2);\n fileMetaInformationVersion[1] = 1;\n return DicomMetaDictionary.denaturalizeDataset({\n FileMetaInformationVersion: fileMetaInformationVersion.buffer,\n MediaStorageSOPClassUID: MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID,\n MediaStorageSOPInstanceUID:\n options.fileSetUID || DicomMetaDictionary.uid(),\n TransferSyntaxUID: EXPLICIT_LITTLE_ENDIAN,\n ImplementationClassUID:\n \"2.25.80302813137786398554742050926734630921603366648225212145404\",\n ImplementationVersionName: \"dcmjs-0.0\"\n });\n}\n\n/**\n * Build and serialize a complete DICOMDIR: build the record tree,\n * denaturalize it, measure the layout, wire the offset chains, write once.\n *\n * @param {Array} entries - flat file-set entries\n * @param {Object} [options] - buildDicomDirDataset options plus\n * {string} [options.fileSetUID] fixed MediaStorageSOPInstanceUID\n * @returns {ArrayBuffer} the DICOMDIR file bytes\n */\n/**\n * The DICOM data dictionary gives the directory offset attributes the\n * special VR \"up\" (byte offset); the dcmjs writer has no \"up\" representation\n * and would fall back to UN. They are four-byte unsigned offsets — pin them\n * to UL so they serialize (and measure) as the fixed-width values the\n * offset algorithm depends on.\n */\nfunction pinOffsetVRs(dict) {\n for (const tag of [\"00041200\", \"00041202\"]) {\n if (dict[tag]) {\n dict[tag].vr = \"UL\";\n }\n }\n const items = dict[\"00041220\"]?.Value || [];\n for (const item of items) {\n for (const tag of [\"00041400\", \"00041420\"]) {\n if (item[tag]) {\n item[tag].vr = \"UL\";\n }\n }\n }\n}\n\n/**\n * Serialize { meta, dict } as a Part 10 file. This is the body of\n * DicomDict.write (packages/legacy) minus the deflate branch — a DICOMDIR\n * is always Explicit VR Little Endian, never deflated — rebuilt on core's\n * writeDataSet/writeTagObject so this package does not depend on\n * @dcmjs-org/legacy. DicomMessage.write and DicomMessage.writeTagObject\n * are one-line delegates to those same core functions, so the bytes this\n * produces are identical to DicomDict.write's, which is what keeps the\n * measured directory offsets valid.\n */\nfunction writePart10(meta, dict, writeOptions) {\n const metaSyntax = EXPLICIT_LITTLE_ENDIAN;\n const fileStream = new WriteBufferStream(4096, true);\n fileStream.writeUint8Repeat(0, 128);\n fileStream.writeAsciiString(\"DICM\");\n\n const metaStream = new WriteBufferStream(1024);\n if (!meta[TagHex.TransferSyntaxUID]) {\n meta[TagHex.TransferSyntaxUID] = {\n vr: \"UI\",\n Value: [EXPLICIT_LITTLE_ENDIAN]\n };\n }\n writeDataSet(meta, metaStream, metaSyntax, writeOptions);\n writeTagObject(\n fileStream,\n TagHex.FileMetaInformationGroupLength,\n \"UL\",\n metaStream.size,\n metaSyntax,\n writeOptions\n );\n fileStream.concat(metaStream);\n\n const useSyntax = meta[TagHex.TransferSyntaxUID].Value[0];\n writeDataSet(dict, fileStream, useSyntax, writeOptions);\n return fileStream.getBuffer();\n}\n\nfunction writeDicomDir(entries = [], options = {}) {\n const { dataset, links, rootIndices } = buildDicomDirDataset(\n entries,\n options\n );\n\n const meta = buildDicomDirMeta(options);\n const dict = DicomMetaDictionary.denaturalizeDataset(dataset);\n pinOffsetVRs(dict);\n\n const writeOptions = { allowInvalidVRLength: false };\n const recordOffsets = computeDirectoryOffsets({ meta, dict }, writeOptions);\n\n const sequence = dict[\"00041220\"];\n const items = (sequence && sequence.Value) || [];\n items.forEach((item, index) => {\n const { next, child } = links[index];\n item[\"00041400\"].Value = [next === null ? 0 : recordOffsets[next]];\n item[\"00041420\"].Value = [child === null ? 0 : recordOffsets[child]];\n });\n\n const first = rootIndices.length ? recordOffsets[rootIndices[0]] : 0;\n const last = rootIndices.length\n ? recordOffsets[rootIndices[rootIndices.length - 1]]\n : 0;\n dict[\"00041200\"].Value = [first];\n dict[\"00041202\"].Value = [last];\n\n return writePart10(meta, dict, writeOptions);\n}\n\nexport {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n};\n","import {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n} from \"./dicomdir.js\";\n\nexport {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n};\n\nexport default {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n};\n"],"names":["WriteBufferStream","writeDataSet","EXPLICIT_LITTLE_ENDIAN","writeTagObject","TagHex","DicomMetaDictionary"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAUA,MAAM,yBAAyB,GAAG,UAAU;;AAE5C,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,M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;AAEN,IAAI,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACxE,IAAI,MAAM,IAAI,GAAG,WAAW,CAAC;AAC7B,UAAU,aAAa,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3D,UAAU,CAAC;AACX,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC;AACpC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC;;AAEnC,IAAI,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC;AAChD;;AC/WA,YAAe;AACf,IAAI,oBAAoB;AACxB,IAAI,aAAa;AACjB,IAAI;AACJ,CAAC;;;;;;;"}
package/dist/index.mjs ADDED
@@ -0,0 +1,480 @@
1
+ import { WriteBufferStream, writeTagObject, TagHex, EXPLICIT_LITTLE_ENDIAN, writeDataSet, DicomMetaDictionary } from '@dcmjs-org/core';
2
+
3
+ // packages/dicomdir/src/directoryOffsets.js
4
+ //
5
+ // Byte-offset computation for DICOMDIR directory records.
6
+ //
7
+ // The load-bearing fact: every DICOMDIR offset attribute (0004,1200/1202/
8
+ // 1400/1420) is VR UL — a fixed four-byte value — so the values NEVER affect
9
+ // the byte layout. One measurement pass over the exact structures the final
10
+ // write will serialize (same writer, same options, placeholder zeros)
11
+ // therefore yields the exact offsets of the final file, and the file is
12
+ // written once with the real values filled in.
13
+ //
14
+ // Layout being measured (mirrors the Part 10 envelope in dicomdir.js):
15
+ // 128-byte preamble + "DICM"
16
+ // FileMetaInformationGroupLength element
17
+ // meta group (Explicit VR Little Endian)
18
+ // body tags below (0004,1220), sorted ascending
19
+ // (0004,1220) DirectoryRecordSequence: 12-byte SQ header (undefined
20
+ // length), then per item: 8-byte item header (FFFE,E000, undefined
21
+ // length) + item body + 8-byte item delimiter (FFFE,E00D) — see
22
+ // SequenceOfItems.writeBytes — and a trailing 8-byte sequence delimiter.
23
+ //
24
+ // A directory-record offset points at the FFFE,E000 item tag of that record,
25
+ // counted from byte 0 of the file (PS3.10 8.6).
26
+
27
+
28
+ const DIRECTORY_RECORD_SEQUENCE = "00041220";
29
+
30
+ const ITEM_HEADER_BYTES = 8; // FFFE,E000 + 4-byte undefined length
31
+ const ITEM_DELIMITER_BYTES = 8; // FFFE,E00D + 4-byte zero length
32
+
33
+ /** Bytes writeDataSet produces for one tag-keyed object. */
34
+ function measure(jsonObject, writeOptions) {
35
+ const stream = new WriteBufferStream(1024);
36
+ writeDataSet(jsonObject, stream, EXPLICIT_LITTLE_ENDIAN, writeOptions);
37
+ return stream.size;
38
+ }
39
+
40
+ /**
41
+ * Compute the absolute byte offset of every directory record item in the
42
+ * file the Part 10 envelope write will produce. Call with the offsets
43
+ * still zero; patch the returned values in, then write — the layout is
44
+ * guaranteed identical because offsets are fixed-width.
45
+ *
46
+ * @param {{ meta: Object, dict: Object }} dicomDict - denaturalized
47
+ * DICOMDIR ({ meta, dict }) whose dict contains (0004,1220)
48
+ * @param {Object} writeOptions - the SAME object later passed to write()
49
+ * @returns {number[]} byte offset of each record's item tag, in item order
50
+ */
51
+ function computeDirectoryOffsets(dicomDict, writeOptions) {
52
+ // Preamble + magic.
53
+ let cursor = 128 + 4;
54
+
55
+ // FileMetaInformationGroupLength + meta group. The group length element
56
+ // is measured with the real meta size as its value — UL again, so the
57
+ // element size is value-independent, but measuring keeps zero assumptions.
58
+ const metaSize = measure(dicomDict.meta, writeOptions);
59
+ const groupLengthStream = new WriteBufferStream(64);
60
+ writeTagObject(
61
+ groupLengthStream,
62
+ TagHex.FileMetaInformationGroupLength,
63
+ "UL",
64
+ metaSize,
65
+ EXPLICIT_LITTLE_ENDIAN,
66
+ writeOptions
67
+ );
68
+ cursor += groupLengthStream.size + metaSize;
69
+
70
+ // Body tags before the record sequence, in the writer's sorted order.
71
+ const bodyTags = Object.keys(dicomDict.dict).sort();
72
+ for (const tag of bodyTags) {
73
+ if (tag >= DIRECTORY_RECORD_SEQUENCE) {
74
+ break;
75
+ }
76
+ cursor += measure({ [tag]: dicomDict.dict[tag] }, writeOptions);
77
+ }
78
+
79
+ // SQ element header: measure an empty sequence (header + 8-byte
80
+ // sequence delimiter) rather than assuming the 12-byte constant.
81
+ const sequence = dicomDict.dict[DIRECTORY_RECORD_SEQUENCE];
82
+ const emptySequenceSize = measure(
83
+ { [DIRECTORY_RECORD_SEQUENCE]: { vr: "SQ", Value: [] } },
84
+ writeOptions
85
+ );
86
+ cursor += emptySequenceSize - ITEM_DELIMITER_BYTES;
87
+
88
+ const offsets = [];
89
+ const items = (sequence && sequence.Value) || [];
90
+ for (const item of items) {
91
+ offsets.push(cursor);
92
+ cursor +=
93
+ ITEM_HEADER_BYTES +
94
+ measure(item, writeOptions) +
95
+ ITEM_DELIMITER_BYTES;
96
+ }
97
+
98
+ return offsets;
99
+ }
100
+
101
+ // packages/dicomdir/src/dicomdir.js
102
+ //
103
+ // DICOMDIR (Media Storage Directory, PS3.10 / PS3.3 F) builder. Turns a flat
104
+ // file-set description into the PATIENT -> STUDY -> SERIES -> leaf record
105
+ // hierarchy and serializes it with real byte offsets in the three offset
106
+ // attributes (OffsetOfTheNextDirectoryRecord, OffsetOfReferencedLowerLevel-
107
+ // DirectoryEntity, and the root first/last record offsets).
108
+ //
109
+ // Offsets are computed by measure-then-write (see directoryOffsets.js): every
110
+ // offset attribute is VR UL — fixed four bytes — so a measurement pass with
111
+ // placeholder zeros produces the exact final layout, and the file is written
112
+ // once. No patch-and-rewrite, no buffer scanning.
113
+
114
+
115
+ const MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID = "1.2.840.10008.1.3.10";
116
+
117
+ // PS3.10 8.5: each File ID component is 1-8 characters from the ISO 9660
118
+ // level 1 repertoire (A-Z, 0-9, underscore), at most 8 components deep.
119
+ const FILE_ID_COMPONENT = /^[A-Z0-9_]{1,8}$/;
120
+
121
+ function assertEntry(entry, index) {
122
+ const where = `buildDicomDirDataset: entries[${index}]`;
123
+ if (!entry || typeof entry !== "object") {
124
+ throw new Error(`${where} is not an object`);
125
+ }
126
+ if (
127
+ !Array.isArray(entry.referencedFileID) ||
128
+ !entry.referencedFileID.length
129
+ ) {
130
+ throw new Error(
131
+ `${where}.referencedFileID must be a non-empty array of path components`
132
+ );
133
+ }
134
+ for (const required of [
135
+ "sopClassUid",
136
+ "sopInstanceUid",
137
+ "transferSyntaxUid"
138
+ ]) {
139
+ if (!entry[required]) {
140
+ throw new Error(`${where}.${required} is required`);
141
+ }
142
+ }
143
+ if (!entry.patient?.PatientID) {
144
+ throw new Error(`${where}.patient.PatientID is required`);
145
+ }
146
+ if (!entry.study?.StudyInstanceUID) {
147
+ throw new Error(`${where}.study.StudyInstanceUID is required`);
148
+ }
149
+ if (!entry.series?.SeriesInstanceUID) {
150
+ throw new Error(`${where}.series.SeriesInstanceUID is required`);
151
+ }
152
+ }
153
+
154
+ function assertFileID(components, index, allowNonConforming) {
155
+ if (components.length > 8) {
156
+ throw new Error(
157
+ `buildDicomDirDataset: entries[${index}].referencedFileID has ` +
158
+ `${components.length} components (max 8)`
159
+ );
160
+ }
161
+ if (allowNonConforming) {
162
+ return;
163
+ }
164
+ for (const component of components) {
165
+ if (!FILE_ID_COMPONENT.test(component)) {
166
+ throw new Error(
167
+ `buildDicomDirDataset: entries[${index}].referencedFileID ` +
168
+ `component "${component}" is not ISO 9660 level 1 ` +
169
+ `conformant (A-Z 0-9 _, 1-8 chars) — rename the file or ` +
170
+ `pass allowNonConformingFileIDs: true`
171
+ );
172
+ }
173
+ }
174
+ }
175
+
176
+ /** The four keys every directory record starts with (PS3.3 F.3). */
177
+ function recordCommon(recordType) {
178
+ return {
179
+ OffsetOfTheNextDirectoryRecord: 0,
180
+ RecordInUseFlag: 0xffff,
181
+ OffsetOfReferencedLowerLevelDirectoryEntity: 0,
182
+ DirectoryRecordType: recordType
183
+ };
184
+ }
185
+
186
+ /**
187
+ * Group the flat entries into the PATIENT -> STUDY -> SERIES -> leaf tree,
188
+ * preserving first-seen order at every level.
189
+ */
190
+ function groupEntries(entries, options) {
191
+ const patients = new Map();
192
+ entries.forEach((entry, index) => {
193
+ assertEntry(entry, index);
194
+ assertFileID(
195
+ entry.referencedFileID,
196
+ index,
197
+ options.allowNonConformingFileIDs
198
+ );
199
+
200
+ const patientKey = entry.patient.PatientID;
201
+ if (!patients.has(patientKey)) {
202
+ patients.set(patientKey, {
203
+ attributes: entry.patient,
204
+ studies: new Map()
205
+ });
206
+ }
207
+ const patient = patients.get(patientKey);
208
+
209
+ const studyKey = entry.study.StudyInstanceUID;
210
+ if (!patient.studies.has(studyKey)) {
211
+ patient.studies.set(studyKey, {
212
+ attributes: entry.study,
213
+ series: new Map()
214
+ });
215
+ }
216
+ const study = patient.studies.get(studyKey);
217
+
218
+ const seriesKey = entry.series.SeriesInstanceUID;
219
+ if (!study.series.has(seriesKey)) {
220
+ study.series.set(seriesKey, {
221
+ attributes: entry.series,
222
+ leaves: []
223
+ });
224
+ }
225
+ study.series.get(seriesKey).leaves.push(entry);
226
+ });
227
+ return patients;
228
+ }
229
+
230
+ /**
231
+ * Flatten the tree depth-first into naturalized record objects, tracking the
232
+ * flat index of each record's next sibling and first child so the offset
233
+ * pass can wire the chains. Depth-first order means every link points
234
+ * strictly forward in the file.
235
+ *
236
+ * @returns {{ records: Object[], links: Array<{next: number|null, child: number|null}> }}
237
+ */
238
+ function flattenRecords(patients) {
239
+ const records = [];
240
+ const links = [];
241
+
242
+ const push = record => {
243
+ records.push(record);
244
+ links.push({ next: null, child: null });
245
+ return records.length - 1;
246
+ };
247
+
248
+ const patientList = [...patients.values()];
249
+ let previousPatientIndex = null;
250
+
251
+ for (const patient of patientList) {
252
+ const patientIndex = push({
253
+ ...recordCommon("PATIENT"),
254
+ PatientName: patient.attributes.PatientName ?? "",
255
+ PatientID: patient.attributes.PatientID
256
+ });
257
+ if (previousPatientIndex !== null) {
258
+ links[previousPatientIndex].next = patientIndex;
259
+ }
260
+ previousPatientIndex = patientIndex;
261
+
262
+ const studyList = [...patient.studies.values()];
263
+ let previousStudyIndex = null;
264
+ for (const study of studyList) {
265
+ const studyIndex = push({
266
+ ...recordCommon("STUDY"),
267
+ StudyDate: study.attributes.StudyDate ?? "",
268
+ StudyTime: study.attributes.StudyTime ?? "",
269
+ StudyDescription: study.attributes.StudyDescription ?? "",
270
+ AccessionNumber: study.attributes.AccessionNumber ?? "",
271
+ StudyInstanceUID: study.attributes.StudyInstanceUID,
272
+ StudyID: study.attributes.StudyID ?? ""
273
+ });
274
+ if (previousStudyIndex === null) {
275
+ links[patientIndex].child = studyIndex;
276
+ } else {
277
+ links[previousStudyIndex].next = studyIndex;
278
+ }
279
+ previousStudyIndex = studyIndex;
280
+
281
+ const seriesList = [...study.series.values()];
282
+ let previousSeriesIndex = null;
283
+ for (const series of seriesList) {
284
+ const seriesIndex = push({
285
+ ...recordCommon("SERIES"),
286
+ Modality: series.attributes.Modality ?? "OT",
287
+ SeriesInstanceUID: series.attributes.SeriesInstanceUID,
288
+ SeriesNumber: series.attributes.SeriesNumber ?? 1
289
+ });
290
+ if (previousSeriesIndex === null) {
291
+ links[studyIndex].child = seriesIndex;
292
+ } else {
293
+ links[previousSeriesIndex].next = seriesIndex;
294
+ }
295
+ previousSeriesIndex = seriesIndex;
296
+
297
+ let previousLeafIndex = null;
298
+ for (const entry of series.leaves) {
299
+ const leafIndex = push({
300
+ ...recordCommon(entry.recordType || "IMAGE"),
301
+ ReferencedFileID: [...entry.referencedFileID],
302
+ ReferencedSOPClassUIDInFile: entry.sopClassUid,
303
+ ReferencedSOPInstanceUIDInFile: entry.sopInstanceUid,
304
+ ReferencedTransferSyntaxUIDInFile:
305
+ entry.transferSyntaxUid,
306
+ InstanceNumber: entry.instance?.InstanceNumber ?? 1,
307
+ ...entry.instance
308
+ });
309
+ if (previousLeafIndex === null) {
310
+ links[seriesIndex].child = leafIndex;
311
+ } else {
312
+ links[previousLeafIndex].next = leafIndex;
313
+ }
314
+ previousLeafIndex = leafIndex;
315
+ }
316
+ }
317
+ }
318
+ }
319
+
320
+ return { records, links };
321
+ }
322
+
323
+ /**
324
+ * Build the naturalized DICOMDIR dataset (all offsets zero) plus the link
325
+ * table the offset pass needs. Pure and inspectable — no serialization.
326
+ *
327
+ * @param {Array} entries - flat file-set entries; see module JSDoc/typedef
328
+ * @param {Object} [options]
329
+ * @param {string} [options.fileSetID=""]
330
+ * @param {boolean} [options.allowNonConformingFileIDs=false]
331
+ * @returns {{ dataset: Object, links: Array, rootIndices: number[] }}
332
+ */
333
+ function buildDicomDirDataset(entries = [], options = {}) {
334
+ const patients = groupEntries(entries, options);
335
+ const { records, links } = flattenRecords(patients);
336
+
337
+ const rootIndices = [];
338
+ records.forEach((record, index) => {
339
+ if (record.DirectoryRecordType === "PATIENT") {
340
+ rootIndices.push(index);
341
+ }
342
+ });
343
+
344
+ const dataset = {
345
+ FileSetID: options.fileSetID ?? "",
346
+ OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity: 0,
347
+ OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity: 0,
348
+ FileSetConsistencyFlag: 0,
349
+ DirectoryRecordSequence: records
350
+ };
351
+
352
+ return { dataset, links, rootIndices };
353
+ }
354
+
355
+ /** Mint the DICOMDIR file meta group (SOP identity lives here, not the body). */
356
+ function buildDicomDirMeta(options = {}) {
357
+ const fileMetaInformationVersion = new Uint8Array(2);
358
+ fileMetaInformationVersion[1] = 1;
359
+ return DicomMetaDictionary.denaturalizeDataset({
360
+ FileMetaInformationVersion: fileMetaInformationVersion.buffer,
361
+ MediaStorageSOPClassUID: MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID,
362
+ MediaStorageSOPInstanceUID:
363
+ options.fileSetUID || DicomMetaDictionary.uid(),
364
+ TransferSyntaxUID: EXPLICIT_LITTLE_ENDIAN,
365
+ ImplementationClassUID:
366
+ "2.25.80302813137786398554742050926734630921603366648225212145404",
367
+ ImplementationVersionName: "dcmjs-0.0"
368
+ });
369
+ }
370
+
371
+ /**
372
+ * Build and serialize a complete DICOMDIR: build the record tree,
373
+ * denaturalize it, measure the layout, wire the offset chains, write once.
374
+ *
375
+ * @param {Array} entries - flat file-set entries
376
+ * @param {Object} [options] - buildDicomDirDataset options plus
377
+ * {string} [options.fileSetUID] fixed MediaStorageSOPInstanceUID
378
+ * @returns {ArrayBuffer} the DICOMDIR file bytes
379
+ */
380
+ /**
381
+ * The DICOM data dictionary gives the directory offset attributes the
382
+ * special VR "up" (byte offset); the dcmjs writer has no "up" representation
383
+ * and would fall back to UN. They are four-byte unsigned offsets — pin them
384
+ * to UL so they serialize (and measure) as the fixed-width values the
385
+ * offset algorithm depends on.
386
+ */
387
+ function pinOffsetVRs(dict) {
388
+ for (const tag of ["00041200", "00041202"]) {
389
+ if (dict[tag]) {
390
+ dict[tag].vr = "UL";
391
+ }
392
+ }
393
+ const items = dict["00041220"]?.Value || [];
394
+ for (const item of items) {
395
+ for (const tag of ["00041400", "00041420"]) {
396
+ if (item[tag]) {
397
+ item[tag].vr = "UL";
398
+ }
399
+ }
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Serialize { meta, dict } as a Part 10 file. This is the body of
405
+ * DicomDict.write (packages/legacy) minus the deflate branch — a DICOMDIR
406
+ * is always Explicit VR Little Endian, never deflated — rebuilt on core's
407
+ * writeDataSet/writeTagObject so this package does not depend on
408
+ * @dcmjs-org/legacy. DicomMessage.write and DicomMessage.writeTagObject
409
+ * are one-line delegates to those same core functions, so the bytes this
410
+ * produces are identical to DicomDict.write's, which is what keeps the
411
+ * measured directory offsets valid.
412
+ */
413
+ function writePart10(meta, dict, writeOptions) {
414
+ const metaSyntax = EXPLICIT_LITTLE_ENDIAN;
415
+ const fileStream = new WriteBufferStream(4096, true);
416
+ fileStream.writeUint8Repeat(0, 128);
417
+ fileStream.writeAsciiString("DICM");
418
+
419
+ const metaStream = new WriteBufferStream(1024);
420
+ if (!meta[TagHex.TransferSyntaxUID]) {
421
+ meta[TagHex.TransferSyntaxUID] = {
422
+ vr: "UI",
423
+ Value: [EXPLICIT_LITTLE_ENDIAN]
424
+ };
425
+ }
426
+ writeDataSet(meta, metaStream, metaSyntax, writeOptions);
427
+ writeTagObject(
428
+ fileStream,
429
+ TagHex.FileMetaInformationGroupLength,
430
+ "UL",
431
+ metaStream.size,
432
+ metaSyntax,
433
+ writeOptions
434
+ );
435
+ fileStream.concat(metaStream);
436
+
437
+ const useSyntax = meta[TagHex.TransferSyntaxUID].Value[0];
438
+ writeDataSet(dict, fileStream, useSyntax, writeOptions);
439
+ return fileStream.getBuffer();
440
+ }
441
+
442
+ function writeDicomDir(entries = [], options = {}) {
443
+ const { dataset, links, rootIndices } = buildDicomDirDataset(
444
+ entries,
445
+ options
446
+ );
447
+
448
+ const meta = buildDicomDirMeta(options);
449
+ const dict = DicomMetaDictionary.denaturalizeDataset(dataset);
450
+ pinOffsetVRs(dict);
451
+
452
+ const writeOptions = { allowInvalidVRLength: false };
453
+ const recordOffsets = computeDirectoryOffsets({ meta, dict }, writeOptions);
454
+
455
+ const sequence = dict["00041220"];
456
+ const items = (sequence && sequence.Value) || [];
457
+ items.forEach((item, index) => {
458
+ const { next, child } = links[index];
459
+ item["00041400"].Value = [next === null ? 0 : recordOffsets[next]];
460
+ item["00041420"].Value = [child === null ? 0 : recordOffsets[child]];
461
+ });
462
+
463
+ const first = rootIndices.length ? recordOffsets[rootIndices[0]] : 0;
464
+ const last = rootIndices.length
465
+ ? recordOffsets[rootIndices[rootIndices.length - 1]]
466
+ : 0;
467
+ dict["00041200"].Value = [first];
468
+ dict["00041202"].Value = [last];
469
+
470
+ return writePart10(meta, dict, writeOptions);
471
+ }
472
+
473
+ var index = {
474
+ buildDicomDirDataset,
475
+ writeDicomDir,
476
+ MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID
477
+ };
478
+
479
+ export { MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID, buildDicomDirDataset, index as default, writeDicomDir };
480
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/directoryOffsets.js","../src/dicomdir.js","../src/index.js"],"sourcesContent":["// packages/dicomdir/src/directoryOffsets.js\n//\n// Byte-offset computation for DICOMDIR directory records.\n//\n// The load-bearing fact: every DICOMDIR offset attribute (0004,1200/1202/\n// 1400/1420) is VR UL — a fixed four-byte value — so the values NEVER affect\n// the byte layout. One measurement pass over the exact structures the final\n// write will serialize (same writer, same options, placeholder zeros)\n// therefore yields the exact offsets of the final file, and the file is\n// written once with the real values filled in.\n//\n// Layout being measured (mirrors the Part 10 envelope in dicomdir.js):\n// 128-byte preamble + \"DICM\"\n// FileMetaInformationGroupLength element\n// meta group (Explicit VR Little Endian)\n// body tags below (0004,1220), sorted ascending\n// (0004,1220) DirectoryRecordSequence: 12-byte SQ header (undefined\n// length), then per item: 8-byte item header (FFFE,E000, undefined\n// length) + item body + 8-byte item delimiter (FFFE,E00D) — see\n// SequenceOfItems.writeBytes — and a trailing 8-byte sequence delimiter.\n//\n// A directory-record offset points at the FFFE,E000 item tag of that record,\n// counted from byte 0 of the file (PS3.10 8.6).\n\nimport {\n WriteBufferStream,\n writeDataSet,\n writeTagObject,\n EXPLICIT_LITTLE_ENDIAN,\n TagHex\n} from \"@dcmjs-org/core\";\n\nconst DIRECTORY_RECORD_SEQUENCE = \"00041220\";\n\nconst ITEM_HEADER_BYTES = 8; // FFFE,E000 + 4-byte undefined length\nconst ITEM_DELIMITER_BYTES = 8; // FFFE,E00D + 4-byte zero length\n\n/** Bytes writeDataSet produces for one tag-keyed object. */\nfunction measure(jsonObject, writeOptions) {\n const stream = new WriteBufferStream(1024);\n writeDataSet(jsonObject, stream, EXPLICIT_LITTLE_ENDIAN, writeOptions);\n return stream.size;\n}\n\n/**\n * Compute the absolute byte offset of every directory record item in the\n * file the Part 10 envelope write will produce. Call with the offsets\n * still zero; patch the returned values in, then write — the layout is\n * guaranteed identical because offsets are fixed-width.\n *\n * @param {{ meta: Object, dict: Object }} dicomDict - denaturalized\n * DICOMDIR ({ meta, dict }) whose dict contains (0004,1220)\n * @param {Object} writeOptions - the SAME object later passed to write()\n * @returns {number[]} byte offset of each record's item tag, in item order\n */\nexport function computeDirectoryOffsets(dicomDict, writeOptions) {\n // Preamble + magic.\n let cursor = 128 + 4;\n\n // FileMetaInformationGroupLength + meta group. The group length element\n // is measured with the real meta size as its value — UL again, so the\n // element size is value-independent, but measuring keeps zero assumptions.\n const metaSize = measure(dicomDict.meta, writeOptions);\n const groupLengthStream = new WriteBufferStream(64);\n writeTagObject(\n groupLengthStream,\n TagHex.FileMetaInformationGroupLength,\n \"UL\",\n metaSize,\n EXPLICIT_LITTLE_ENDIAN,\n writeOptions\n );\n cursor += groupLengthStream.size + metaSize;\n\n // Body tags before the record sequence, in the writer's sorted order.\n const bodyTags = Object.keys(dicomDict.dict).sort();\n for (const tag of bodyTags) {\n if (tag >= DIRECTORY_RECORD_SEQUENCE) {\n break;\n }\n cursor += measure({ [tag]: dicomDict.dict[tag] }, writeOptions);\n }\n\n // SQ element header: measure an empty sequence (header + 8-byte\n // sequence delimiter) rather than assuming the 12-byte constant.\n const sequence = dicomDict.dict[DIRECTORY_RECORD_SEQUENCE];\n const emptySequenceSize = measure(\n { [DIRECTORY_RECORD_SEQUENCE]: { vr: \"SQ\", Value: [] } },\n writeOptions\n );\n cursor += emptySequenceSize - ITEM_DELIMITER_BYTES;\n\n const offsets = [];\n const items = (sequence && sequence.Value) || [];\n for (const item of items) {\n offsets.push(cursor);\n cursor +=\n ITEM_HEADER_BYTES +\n measure(item, writeOptions) +\n ITEM_DELIMITER_BYTES;\n }\n\n return offsets;\n}\n","// packages/dicomdir/src/dicomdir.js\n//\n// DICOMDIR (Media Storage Directory, PS3.10 / PS3.3 F) builder. Turns a flat\n// file-set description into the PATIENT -> STUDY -> SERIES -> leaf record\n// hierarchy and serializes it with real byte offsets in the three offset\n// attributes (OffsetOfTheNextDirectoryRecord, OffsetOfReferencedLowerLevel-\n// DirectoryEntity, and the root first/last record offsets).\n//\n// Offsets are computed by measure-then-write (see directoryOffsets.js): every\n// offset attribute is VR UL — fixed four bytes — so a measurement pass with\n// placeholder zeros produces the exact final layout, and the file is written\n// once. No patch-and-rewrite, no buffer scanning.\n\nimport {\n DicomMetaDictionary,\n WriteBufferStream,\n writeDataSet,\n writeTagObject,\n EXPLICIT_LITTLE_ENDIAN,\n TagHex\n} from \"@dcmjs-org/core\";\nimport { computeDirectoryOffsets } from \"./directoryOffsets.js\";\n\nconst MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID = \"1.2.840.10008.1.3.10\";\n\n// PS3.10 8.5: each File ID component is 1-8 characters from the ISO 9660\n// level 1 repertoire (A-Z, 0-9, underscore), at most 8 components deep.\nconst FILE_ID_COMPONENT = /^[A-Z0-9_]{1,8}$/;\n\nfunction assertEntry(entry, index) {\n const where = `buildDicomDirDataset: entries[${index}]`;\n if (!entry || typeof entry !== \"object\") {\n throw new Error(`${where} is not an object`);\n }\n if (\n !Array.isArray(entry.referencedFileID) ||\n !entry.referencedFileID.length\n ) {\n throw new Error(\n `${where}.referencedFileID must be a non-empty array of path components`\n );\n }\n for (const required of [\n \"sopClassUid\",\n \"sopInstanceUid\",\n \"transferSyntaxUid\"\n ]) {\n if (!entry[required]) {\n throw new Error(`${where}.${required} is required`);\n }\n }\n if (!entry.patient?.PatientID) {\n throw new Error(`${where}.patient.PatientID is required`);\n }\n if (!entry.study?.StudyInstanceUID) {\n throw new Error(`${where}.study.StudyInstanceUID is required`);\n }\n if (!entry.series?.SeriesInstanceUID) {\n throw new Error(`${where}.series.SeriesInstanceUID is required`);\n }\n}\n\nfunction assertFileID(components, index, allowNonConforming) {\n if (components.length > 8) {\n throw new Error(\n `buildDicomDirDataset: entries[${index}].referencedFileID has ` +\n `${components.length} components (max 8)`\n );\n }\n if (allowNonConforming) {\n return;\n }\n for (const component of components) {\n if (!FILE_ID_COMPONENT.test(component)) {\n throw new Error(\n `buildDicomDirDataset: entries[${index}].referencedFileID ` +\n `component \"${component}\" is not ISO 9660 level 1 ` +\n `conformant (A-Z 0-9 _, 1-8 chars) — rename the file or ` +\n `pass allowNonConformingFileIDs: true`\n );\n }\n }\n}\n\n/** The four keys every directory record starts with (PS3.3 F.3). */\nfunction recordCommon(recordType) {\n return {\n OffsetOfTheNextDirectoryRecord: 0,\n RecordInUseFlag: 0xffff,\n OffsetOfReferencedLowerLevelDirectoryEntity: 0,\n DirectoryRecordType: recordType\n };\n}\n\n/**\n * Group the flat entries into the PATIENT -> STUDY -> SERIES -> leaf tree,\n * preserving first-seen order at every level.\n */\nfunction groupEntries(entries, options) {\n const patients = new Map();\n entries.forEach((entry, index) => {\n assertEntry(entry, index);\n assertFileID(\n entry.referencedFileID,\n index,\n options.allowNonConformingFileIDs\n );\n\n const patientKey = entry.patient.PatientID;\n if (!patients.has(patientKey)) {\n patients.set(patientKey, {\n attributes: entry.patient,\n studies: new Map()\n });\n }\n const patient = patients.get(patientKey);\n\n const studyKey = entry.study.StudyInstanceUID;\n if (!patient.studies.has(studyKey)) {\n patient.studies.set(studyKey, {\n attributes: entry.study,\n series: new Map()\n });\n }\n const study = patient.studies.get(studyKey);\n\n const seriesKey = entry.series.SeriesInstanceUID;\n if (!study.series.has(seriesKey)) {\n study.series.set(seriesKey, {\n attributes: entry.series,\n leaves: []\n });\n }\n study.series.get(seriesKey).leaves.push(entry);\n });\n return patients;\n}\n\n/**\n * Flatten the tree depth-first into naturalized record objects, tracking the\n * flat index of each record's next sibling and first child so the offset\n * pass can wire the chains. Depth-first order means every link points\n * strictly forward in the file.\n *\n * @returns {{ records: Object[], links: Array<{next: number|null, child: number|null}> }}\n */\nfunction flattenRecords(patients) {\n const records = [];\n const links = [];\n\n const push = record => {\n records.push(record);\n links.push({ next: null, child: null });\n return records.length - 1;\n };\n\n const patientList = [...patients.values()];\n let previousPatientIndex = null;\n\n for (const patient of patientList) {\n const patientIndex = push({\n ...recordCommon(\"PATIENT\"),\n PatientName: patient.attributes.PatientName ?? \"\",\n PatientID: patient.attributes.PatientID\n });\n if (previousPatientIndex !== null) {\n links[previousPatientIndex].next = patientIndex;\n }\n previousPatientIndex = patientIndex;\n\n const studyList = [...patient.studies.values()];\n let previousStudyIndex = null;\n for (const study of studyList) {\n const studyIndex = push({\n ...recordCommon(\"STUDY\"),\n StudyDate: study.attributes.StudyDate ?? \"\",\n StudyTime: study.attributes.StudyTime ?? \"\",\n StudyDescription: study.attributes.StudyDescription ?? \"\",\n AccessionNumber: study.attributes.AccessionNumber ?? \"\",\n StudyInstanceUID: study.attributes.StudyInstanceUID,\n StudyID: study.attributes.StudyID ?? \"\"\n });\n if (previousStudyIndex === null) {\n links[patientIndex].child = studyIndex;\n } else {\n links[previousStudyIndex].next = studyIndex;\n }\n previousStudyIndex = studyIndex;\n\n const seriesList = [...study.series.values()];\n let previousSeriesIndex = null;\n for (const series of seriesList) {\n const seriesIndex = push({\n ...recordCommon(\"SERIES\"),\n Modality: series.attributes.Modality ?? \"OT\",\n SeriesInstanceUID: series.attributes.SeriesInstanceUID,\n SeriesNumber: series.attributes.SeriesNumber ?? 1\n });\n if (previousSeriesIndex === null) {\n links[studyIndex].child = seriesIndex;\n } else {\n links[previousSeriesIndex].next = seriesIndex;\n }\n previousSeriesIndex = seriesIndex;\n\n let previousLeafIndex = null;\n for (const entry of series.leaves) {\n const leafIndex = push({\n ...recordCommon(entry.recordType || \"IMAGE\"),\n ReferencedFileID: [...entry.referencedFileID],\n ReferencedSOPClassUIDInFile: entry.sopClassUid,\n ReferencedSOPInstanceUIDInFile: entry.sopInstanceUid,\n ReferencedTransferSyntaxUIDInFile:\n entry.transferSyntaxUid,\n InstanceNumber: entry.instance?.InstanceNumber ?? 1,\n ...entry.instance\n });\n if (previousLeafIndex === null) {\n links[seriesIndex].child = leafIndex;\n } else {\n links[previousLeafIndex].next = leafIndex;\n }\n previousLeafIndex = leafIndex;\n }\n }\n }\n }\n\n return { records, links };\n}\n\n/**\n * Build the naturalized DICOMDIR dataset (all offsets zero) plus the link\n * table the offset pass needs. Pure and inspectable — no serialization.\n *\n * @param {Array} entries - flat file-set entries; see module JSDoc/typedef\n * @param {Object} [options]\n * @param {string} [options.fileSetID=\"\"]\n * @param {boolean} [options.allowNonConformingFileIDs=false]\n * @returns {{ dataset: Object, links: Array, rootIndices: number[] }}\n */\nfunction buildDicomDirDataset(entries = [], options = {}) {\n const patients = groupEntries(entries, options);\n const { records, links } = flattenRecords(patients);\n\n const rootIndices = [];\n records.forEach((record, index) => {\n if (record.DirectoryRecordType === \"PATIENT\") {\n rootIndices.push(index);\n }\n });\n\n const dataset = {\n FileSetID: options.fileSetID ?? \"\",\n OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity: 0,\n OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity: 0,\n FileSetConsistencyFlag: 0,\n DirectoryRecordSequence: records\n };\n\n return { dataset, links, rootIndices };\n}\n\n/** Mint the DICOMDIR file meta group (SOP identity lives here, not the body). */\nfunction buildDicomDirMeta(options = {}) {\n const fileMetaInformationVersion = new Uint8Array(2);\n fileMetaInformationVersion[1] = 1;\n return DicomMetaDictionary.denaturalizeDataset({\n FileMetaInformationVersion: fileMetaInformationVersion.buffer,\n MediaStorageSOPClassUID: MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID,\n MediaStorageSOPInstanceUID:\n options.fileSetUID || DicomMetaDictionary.uid(),\n TransferSyntaxUID: EXPLICIT_LITTLE_ENDIAN,\n ImplementationClassUID:\n \"2.25.80302813137786398554742050926734630921603366648225212145404\",\n ImplementationVersionName: \"dcmjs-0.0\"\n });\n}\n\n/**\n * Build and serialize a complete DICOMDIR: build the record tree,\n * denaturalize it, measure the layout, wire the offset chains, write once.\n *\n * @param {Array} entries - flat file-set entries\n * @param {Object} [options] - buildDicomDirDataset options plus\n * {string} [options.fileSetUID] fixed MediaStorageSOPInstanceUID\n * @returns {ArrayBuffer} the DICOMDIR file bytes\n */\n/**\n * The DICOM data dictionary gives the directory offset attributes the\n * special VR \"up\" (byte offset); the dcmjs writer has no \"up\" representation\n * and would fall back to UN. They are four-byte unsigned offsets — pin them\n * to UL so they serialize (and measure) as the fixed-width values the\n * offset algorithm depends on.\n */\nfunction pinOffsetVRs(dict) {\n for (const tag of [\"00041200\", \"00041202\"]) {\n if (dict[tag]) {\n dict[tag].vr = \"UL\";\n }\n }\n const items = dict[\"00041220\"]?.Value || [];\n for (const item of items) {\n for (const tag of [\"00041400\", \"00041420\"]) {\n if (item[tag]) {\n item[tag].vr = \"UL\";\n }\n }\n }\n}\n\n/**\n * Serialize { meta, dict } as a Part 10 file. This is the body of\n * DicomDict.write (packages/legacy) minus the deflate branch — a DICOMDIR\n * is always Explicit VR Little Endian, never deflated — rebuilt on core's\n * writeDataSet/writeTagObject so this package does not depend on\n * @dcmjs-org/legacy. DicomMessage.write and DicomMessage.writeTagObject\n * are one-line delegates to those same core functions, so the bytes this\n * produces are identical to DicomDict.write's, which is what keeps the\n * measured directory offsets valid.\n */\nfunction writePart10(meta, dict, writeOptions) {\n const metaSyntax = EXPLICIT_LITTLE_ENDIAN;\n const fileStream = new WriteBufferStream(4096, true);\n fileStream.writeUint8Repeat(0, 128);\n fileStream.writeAsciiString(\"DICM\");\n\n const metaStream = new WriteBufferStream(1024);\n if (!meta[TagHex.TransferSyntaxUID]) {\n meta[TagHex.TransferSyntaxUID] = {\n vr: \"UI\",\n Value: [EXPLICIT_LITTLE_ENDIAN]\n };\n }\n writeDataSet(meta, metaStream, metaSyntax, writeOptions);\n writeTagObject(\n fileStream,\n TagHex.FileMetaInformationGroupLength,\n \"UL\",\n metaStream.size,\n metaSyntax,\n writeOptions\n );\n fileStream.concat(metaStream);\n\n const useSyntax = meta[TagHex.TransferSyntaxUID].Value[0];\n writeDataSet(dict, fileStream, useSyntax, writeOptions);\n return fileStream.getBuffer();\n}\n\nfunction writeDicomDir(entries = [], options = {}) {\n const { dataset, links, rootIndices } = buildDicomDirDataset(\n entries,\n options\n );\n\n const meta = buildDicomDirMeta(options);\n const dict = DicomMetaDictionary.denaturalizeDataset(dataset);\n pinOffsetVRs(dict);\n\n const writeOptions = { allowInvalidVRLength: false };\n const recordOffsets = computeDirectoryOffsets({ meta, dict }, writeOptions);\n\n const sequence = dict[\"00041220\"];\n const items = (sequence && sequence.Value) || [];\n items.forEach((item, index) => {\n const { next, child } = links[index];\n item[\"00041400\"].Value = [next === null ? 0 : recordOffsets[next]];\n item[\"00041420\"].Value = [child === null ? 0 : recordOffsets[child]];\n });\n\n const first = rootIndices.length ? recordOffsets[rootIndices[0]] : 0;\n const last = rootIndices.length\n ? recordOffsets[rootIndices[rootIndices.length - 1]]\n : 0;\n dict[\"00041200\"].Value = [first];\n dict[\"00041202\"].Value = [last];\n\n return writePart10(meta, dict, writeOptions);\n}\n\nexport {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n};\n","import {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n} from \"./dicomdir.js\";\n\nexport {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n};\n\nexport default {\n buildDicomDirDataset,\n writeDicomDir,\n MEDIA_STORAGE_DIRECTORY_SOP_CLASS_UID\n};\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAUA,MAAM,yBAAyB,GAAG,UAAU;;AAE5C,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,oBAAoB,GAAG,CAAC,CAAC;;AAE/B;AACA,SAAS,OAAO,CAAC,UAAU,EAAE,YAAY,EAAE;AAC3C,IAAI,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC;AAC9C,IAAI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AC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3D,UAAU,CAAC;AACX,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC;AACpC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC;;AAEnC,IAAI,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC;AAChD;;AC/WA,YAAe;AACf,IAAI,oBAAoB;AACxB,IAAI,aAAa;AACjB,IAAI;AACJ,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@dcmjs-org/dicomdir",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-beta.10",
4
+ "description": "DICOMDIR (Media Storage Directory, PS3.10) building and writing: turns a flat file-set description into the PATIENT/STUDY/SERIES/leaf record hierarchy with real byte offsets, serialized in one pass",
5
+ "main": "./dist/index.cjs",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.mjs",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md"
16
+ ],
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/dcmjs-org/dcmjs.git",
21
+ "directory": "packages/dicomdir"
22
+ },
23
+ "dependencies": {
24
+ "@dcmjs-org/core": "1.0.0-beta.10"
25
+ },
26
+ "devDependencies": {
27
+ "@dcmjs-org/legacy": "1.0.0-beta.10",
28
+ "@dcmjs-org/parser": "1.0.0-beta.10"
29
+ },
30
+ "scripts": {
31
+ "build": "rollup -c ../../rollup.packages.config.mjs"
32
+ },
33
+ "module": "./dist/index.mjs"
6
34
  }