forked from dcmjs-org/dcmjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DicomDict.js
50 lines (43 loc) · 1.42 KB
/
DicomDict.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { WriteBufferStream } from "./BufferStream";
import { DicomMessage } from "./DicomMessage";
const EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
class DicomDict {
constructor(meta) {
this.meta = meta;
this.dict = {};
}
upsertTag(tag, vr, values) {
if (this.dict[tag]) {
this.dict[tag].Value = values;
} else {
this.dict[tag] = { vr: vr, Value: values };
}
}
write(writeOptions = { allowInvalidVRLength: false }) {
var metaSyntax = EXPLICIT_LITTLE_ENDIAN;
var fileStream = new WriteBufferStream(4096, true);
fileStream.writeUint8Repeat(0, 128);
fileStream.writeAsciiString("DICM");
var metaStream = new WriteBufferStream(1024);
if (!this.meta["00020010"]) {
this.meta["00020010"] = {
vr: "UI",
Value: [EXPLICIT_LITTLE_ENDIAN]
};
}
DicomMessage.write(this.meta, metaStream, metaSyntax, writeOptions);
DicomMessage.writeTagObject(
fileStream,
"00020000",
"UL",
metaStream.size,
metaSyntax,
writeOptions
);
fileStream.concat(metaStream);
var useSyntax = this.meta["00020010"].Value[0];
DicomMessage.write(this.dict, fileStream, useSyntax, writeOptions);
return fileStream.getBuffer();
}
}
export { DicomDict };