@abasb75/dicom-parser 0.0.2-test → 0.0.3-a
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/README.md +14 -58
- package/dist/index.d.mts +138 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +25 -25
- package/Dataset.d.ts +0 -35
- package/Dataset.js +0 -241
- package/Loader.d.ts +0 -8
- package/Loader.js +0 -65
- package/Parser.d.ts +0 -29
- package/Parser.js +0 -225
- package/Tag.d.ts +0 -17
- package/Tag.js +0 -99
- package/Value.d.ts +0 -11
- package/Value.js +0 -96
- package/enums/TagsDictionary.d.ts +0 -8
- package/enums/TagsDictionary.js +0 -3612
- package/enums/TransferSyntax.d.ts +0 -17
- package/enums/TransferSyntax.js +0 -19
- package/enums/ValueRepresentations.d.ts +0 -2
- package/enums/ValueRepresentations.js +0 -4
- package/enums/index.d.ts +0 -12
- package/enums/index.js +0 -11
- package/index.d.ts +0 -10
- package/index.js +0 -53
- package/tsconfig.tsbuildinfo +0 -1
- package/types.d.ts +0 -5
- package/types.js +0 -2
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
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
|
-
|
|
2
|
+
"name": "@abasb75/dicom-parser",
|
|
3
|
+
"version": "0.0.3a",
|
|
4
|
+
"description": "A lightweight DICOM parser.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"pako": "^2.1.0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"dicom",
|
|
19
|
+
"parser",
|
|
20
|
+
"medical",
|
|
21
|
+
"radiology"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.5.1"
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
}
|
package/Dataset.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Tags } from "./types";
|
|
2
|
-
declare class Dataset {
|
|
3
|
-
tags: Tags;
|
|
4
|
-
transferSyntaxUID: string;
|
|
5
|
-
dataView: DataView;
|
|
6
|
-
studyInstanceUID: string;
|
|
7
|
-
studyID: string;
|
|
8
|
-
numberOfFrames: number | undefined;
|
|
9
|
-
windowWidth: number | string | undefined;
|
|
10
|
-
windowCenter: number | string | undefined;
|
|
11
|
-
seriesInstanceUID: string;
|
|
12
|
-
seriesNumber: number | string | undefined;
|
|
13
|
-
studyDate: string;
|
|
14
|
-
studyTime: number | string | undefined;
|
|
15
|
-
pixelRepresentation: number | string | undefined;
|
|
16
|
-
littleEndian: boolean;
|
|
17
|
-
pixeSpacing: number | number[] | string | undefined;
|
|
18
|
-
accessionNumber: string;
|
|
19
|
-
bitsAllocated: number | string | undefined;
|
|
20
|
-
imageType: number | string | number[] | string[] | undefined;
|
|
21
|
-
modality: number | string | number[] | string[] | undefined;
|
|
22
|
-
seriesDescription: string;
|
|
23
|
-
rows: string | number | undefined;
|
|
24
|
-
columns: string | number | undefined;
|
|
25
|
-
patientSex: any;
|
|
26
|
-
patientAge: string;
|
|
27
|
-
constructor(tags: Tags, dataView: DataView, littleEndian: boolean);
|
|
28
|
-
int(group: number, element: number): number | undefined;
|
|
29
|
-
get(group: number, element: number): string;
|
|
30
|
-
string(group: number, element: number): string;
|
|
31
|
-
getValue(element: number | string, elementId?: number | string, vr?: string): string | number | (string | number)[] | undefined;
|
|
32
|
-
private _getValue;
|
|
33
|
-
private _reformatToString;
|
|
34
|
-
}
|
|
35
|
-
export default Dataset;
|
package/Dataset.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Tag_1 = require("./Tag");
|
|
4
|
-
const Value_1 = require("./Value");
|
|
5
|
-
class Dataset {
|
|
6
|
-
constructor(tags, dataView, littleEndian) {
|
|
7
|
-
Object.defineProperty(this, "tags", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
value: void 0
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(this, "transferSyntaxUID", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: "1.2.840.10008.1.2"
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "dataView", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: void 0
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, "studyInstanceUID", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: ""
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, "studyID", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: ""
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(this, "numberOfFrames", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
configurable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
value: void 0
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(this, "windowWidth", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
configurable: true,
|
|
46
|
-
writable: true,
|
|
47
|
-
value: void 0
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(this, "windowCenter", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: void 0
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, "seriesInstanceUID", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(this, "seriesNumber", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
configurable: true,
|
|
64
|
-
writable: true,
|
|
65
|
-
value: void 0
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(this, "studyDate", {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: void 0
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(this, "studyTime", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: void 0
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(this, "pixelRepresentation", {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: true,
|
|
83
|
-
value: void 0
|
|
84
|
-
});
|
|
85
|
-
Object.defineProperty(this, "littleEndian", {
|
|
86
|
-
enumerable: true,
|
|
87
|
-
configurable: true,
|
|
88
|
-
writable: true,
|
|
89
|
-
value: void 0
|
|
90
|
-
});
|
|
91
|
-
Object.defineProperty(this, "pixeSpacing", {
|
|
92
|
-
enumerable: true,
|
|
93
|
-
configurable: true,
|
|
94
|
-
writable: true,
|
|
95
|
-
value: void 0
|
|
96
|
-
});
|
|
97
|
-
Object.defineProperty(this, "accessionNumber", {
|
|
98
|
-
enumerable: true,
|
|
99
|
-
configurable: true,
|
|
100
|
-
writable: true,
|
|
101
|
-
value: void 0
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperty(this, "bitsAllocated", {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
configurable: true,
|
|
106
|
-
writable: true,
|
|
107
|
-
value: void 0
|
|
108
|
-
});
|
|
109
|
-
Object.defineProperty(this, "imageType", {
|
|
110
|
-
enumerable: true,
|
|
111
|
-
configurable: true,
|
|
112
|
-
writable: true,
|
|
113
|
-
value: void 0
|
|
114
|
-
});
|
|
115
|
-
Object.defineProperty(this, "modality", {
|
|
116
|
-
enumerable: true,
|
|
117
|
-
configurable: true,
|
|
118
|
-
writable: true,
|
|
119
|
-
value: void 0
|
|
120
|
-
});
|
|
121
|
-
Object.defineProperty(this, "seriesDescription", {
|
|
122
|
-
enumerable: true,
|
|
123
|
-
configurable: true,
|
|
124
|
-
writable: true,
|
|
125
|
-
value: void 0
|
|
126
|
-
});
|
|
127
|
-
Object.defineProperty(this, "rows", {
|
|
128
|
-
enumerable: true,
|
|
129
|
-
configurable: true,
|
|
130
|
-
writable: true,
|
|
131
|
-
value: void 0
|
|
132
|
-
});
|
|
133
|
-
Object.defineProperty(this, "columns", {
|
|
134
|
-
enumerable: true,
|
|
135
|
-
configurable: true,
|
|
136
|
-
writable: true,
|
|
137
|
-
value: void 0
|
|
138
|
-
});
|
|
139
|
-
Object.defineProperty(this, "patientSex", {
|
|
140
|
-
enumerable: true,
|
|
141
|
-
configurable: true,
|
|
142
|
-
writable: true,
|
|
143
|
-
value: void 0
|
|
144
|
-
});
|
|
145
|
-
Object.defineProperty(this, "patientAge", {
|
|
146
|
-
enumerable: true,
|
|
147
|
-
configurable: true,
|
|
148
|
-
writable: true,
|
|
149
|
-
value: void 0
|
|
150
|
-
});
|
|
151
|
-
this.tags = tags;
|
|
152
|
-
this.dataView = dataView;
|
|
153
|
-
this.littleEndian = littleEndian;
|
|
154
|
-
this.studyID = this.get(0x0020, 0x0010);
|
|
155
|
-
this.studyInstanceUID = this.string(0x0020, 0x000D);
|
|
156
|
-
this.numberOfFrames = this.int(0x0028, 0x0008);
|
|
157
|
-
this.windowWidth = this.get(0x0028, 0x1050);
|
|
158
|
-
this.windowCenter = this.get(0x0028, 0x1051);
|
|
159
|
-
this.seriesInstanceUID = this.get(0x0020, 0x000E);
|
|
160
|
-
this.seriesNumber = this.get(0x0020, 0x0011);
|
|
161
|
-
this.studyDate = this.get(0x0008, 0x0020);
|
|
162
|
-
this.studyTime = this.get(0x0008, 0x0030);
|
|
163
|
-
this.pixelRepresentation = this.get(0x0028, 0x0103);
|
|
164
|
-
this.pixeSpacing = this.get(0x0028, 0x0030);
|
|
165
|
-
this.accessionNumber = this.string(0x0008, 0x0050);
|
|
166
|
-
this.bitsAllocated = this.get(0x0028, 0x0100);
|
|
167
|
-
this.imageType = this.get(0x0008, 0x0008);
|
|
168
|
-
this.modality = this.get(0x0008, 0x0060);
|
|
169
|
-
this.seriesDescription = this.string(0x0008, 0x103E);
|
|
170
|
-
this.patientSex = this.get(0x0010, 0x0040);
|
|
171
|
-
this.rows = this.get(0x0028, 0x0010);
|
|
172
|
-
this.columns = this.get(0x0028, 0x0011);
|
|
173
|
-
this.patientAge = this.get(0x0010, 0x1010);
|
|
174
|
-
}
|
|
175
|
-
int(group, element) {
|
|
176
|
-
const is = this.getValue(group, element, "IS");
|
|
177
|
-
if (typeof is === "number") {
|
|
178
|
-
return is;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
get(group, element) {
|
|
185
|
-
const value = this.getValue(group, element);
|
|
186
|
-
return value;
|
|
187
|
-
}
|
|
188
|
-
string(group, element) {
|
|
189
|
-
return this.getValue(group, element) + "";
|
|
190
|
-
}
|
|
191
|
-
getValue(element, elementId, vr) {
|
|
192
|
-
var _a;
|
|
193
|
-
if (!element && !elementId) {
|
|
194
|
-
return "";
|
|
195
|
-
}
|
|
196
|
-
let _group, _element = "";
|
|
197
|
-
if (typeof element === 'string' && element.length >= 8) {
|
|
198
|
-
const el = element.replace(/^0[xX]/, '');
|
|
199
|
-
if (el.length !== 8) {
|
|
200
|
-
return "";
|
|
201
|
-
}
|
|
202
|
-
_group = el.slice(0, 3);
|
|
203
|
-
_element = el.slice(4, 7);
|
|
204
|
-
}
|
|
205
|
-
else if (typeof element === 'number' && element > 0xffff) {
|
|
206
|
-
const el = Tag_1.default.intTo4digitString(element);
|
|
207
|
-
_group = el.slice(0, 3);
|
|
208
|
-
_element = el.slice(4, 7);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
_group = this._reformatToString(element);
|
|
212
|
-
_element = this._reformatToString(elementId);
|
|
213
|
-
if (!_group || !_element)
|
|
214
|
-
return "";
|
|
215
|
-
}
|
|
216
|
-
const key = `0x${_group}${_element}`;
|
|
217
|
-
if (!this.tags[key]) {
|
|
218
|
-
return "";
|
|
219
|
-
}
|
|
220
|
-
const _vr = vr || ((_a = this.tags[key]) === null || _a === void 0 ? void 0 : _a.vr) || Tag_1.default.getTagVRFromDictionary(_group, _element) || "AA";
|
|
221
|
-
return this._getValue(this.tags[key], _vr);
|
|
222
|
-
}
|
|
223
|
-
_getValue(tag, vr = "AA") {
|
|
224
|
-
const offset = tag.offset;
|
|
225
|
-
if (!offset)
|
|
226
|
-
return "";
|
|
227
|
-
const len = tag.valueLength;
|
|
228
|
-
const value = Value_1.default.byVr(this.dataView, offset, len, vr, this.littleEndian);
|
|
229
|
-
tag.value = value;
|
|
230
|
-
return value;
|
|
231
|
-
}
|
|
232
|
-
_reformatToString(input) {
|
|
233
|
-
if (!input)
|
|
234
|
-
return "";
|
|
235
|
-
if (typeof input === "string") {
|
|
236
|
-
return input.replace(/^0[xX]/, '');
|
|
237
|
-
}
|
|
238
|
-
return Tag_1.default.intTo4digitString(input);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.default = Dataset;
|
package/Loader.d.ts
DELETED
package/Loader.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
class Loader {
|
|
13
|
-
constructor(dicomSrc) {
|
|
14
|
-
Object.defineProperty(this, "dicomSrc", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: void 0
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(this, "xhr", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: void 0
|
|
25
|
-
});
|
|
26
|
-
this.dicomSrc = dicomSrc;
|
|
27
|
-
this.xhr = new XMLHttpRequest();
|
|
28
|
-
}
|
|
29
|
-
load(dicomSrc) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
if (typeof dicomSrc === "string") {
|
|
32
|
-
const dicom = dicomSrc || this.dicomSrc;
|
|
33
|
-
if (!dicom)
|
|
34
|
-
return;
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
this.xhr.onload = () => {
|
|
37
|
-
resolve(this.xhr.response);
|
|
38
|
-
};
|
|
39
|
-
this.xhr.onerror = () => {
|
|
40
|
-
reject(this.xhr);
|
|
41
|
-
};
|
|
42
|
-
this.xhr.responseType = 'arraybuffer';
|
|
43
|
-
this.xhr.open('GET', dicom, true);
|
|
44
|
-
this.xhr.send();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else if (dicomSrc instanceof File) {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
dicomSrc.arrayBuffer().then((arrayBuffer) => {
|
|
50
|
-
resolve(arrayBuffer);
|
|
51
|
-
}).catch(reason => reject(reason));
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
if (false)
|
|
56
|
-
resolve(new ArrayBuffer(1));
|
|
57
|
-
reject("dicom source is not valid");
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
cancel() {
|
|
62
|
-
this.xhr.abort();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.default = Loader;
|
package/Parser.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Dataset from "./Dataset";
|
|
2
|
-
declare class Parser {
|
|
3
|
-
private arrayBuffer;
|
|
4
|
-
private offset;
|
|
5
|
-
private dataView;
|
|
6
|
-
private tags;
|
|
7
|
-
private dataSet;
|
|
8
|
-
private EXEPTED;
|
|
9
|
-
private VRS;
|
|
10
|
-
private IMPLICT_TRANSFER_SYNTAXES;
|
|
11
|
-
private BIG_ENDIAN_TRANSFER_SYNTAXES;
|
|
12
|
-
private DEFLATED_TRANSFER_SYNTAXES;
|
|
13
|
-
private littleEndian;
|
|
14
|
-
private implicit;
|
|
15
|
-
private transferSyntaxUID;
|
|
16
|
-
private inflated;
|
|
17
|
-
constructor(arrayBuffer: ArrayBuffer);
|
|
18
|
-
parse(): Dataset;
|
|
19
|
-
getDataset(): Dataset | undefined;
|
|
20
|
-
getNextTag(): void;
|
|
21
|
-
getValue(len: number): ArrayBuffer;
|
|
22
|
-
getNextGroupAndElement(): {
|
|
23
|
-
group: number;
|
|
24
|
-
element: number;
|
|
25
|
-
};
|
|
26
|
-
getNextVR(groupInt: number, elementInt: number): string;
|
|
27
|
-
concatArrayBuffers: (buffer1: ArrayBuffer, buffer2: ArrayBuffer) => ArrayBufferLike;
|
|
28
|
-
}
|
|
29
|
-
export default Parser;
|
package/Parser.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Dataset_1 = require("./Dataset");
|
|
4
|
-
const Tag_1 = require("./Tag");
|
|
5
|
-
const Value_1 = require("./Value");
|
|
6
|
-
const pako = require("pako");
|
|
7
|
-
class Parser {
|
|
8
|
-
constructor(arrayBuffer) {
|
|
9
|
-
Object.defineProperty(this, "arrayBuffer", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: void 0
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "offset", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: void 0
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "dataView", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "tags", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: {}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "dataSet", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: void 0
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(this, "EXEPTED", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: ["OB", "OW", "SQ", "UN"]
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(this, "VRS", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: ["AE", "AS", "AT", "CS", "DA", "DS", "DT", "FL", "FD", "IS", "LO", "LT", "OB", "OD", "OF", "OW", "PN", "SH", "SL", "SS", "ST", "TM", "UI", "UL", "UN", "US", "UT", "UC"]
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, "IMPLICT_TRANSFER_SYNTAXES", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: ["1.2.840.10008.1.2"]
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, "BIG_ENDIAN_TRANSFER_SYNTAXES", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: ["1.2.840.10008.1.2.2"]
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "DEFLATED_TRANSFER_SYNTAXES", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: ["1.2.840.10008.1.2.1.99"]
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(this, "littleEndian", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true,
|
|
73
|
-
value: true
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(this, "implicit", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: false
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(this, "transferSyntaxUID", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: ""
|
|
86
|
-
});
|
|
87
|
-
// private UNDEFIENED_LEN:number = 0xffffffff;
|
|
88
|
-
Object.defineProperty(this, "inflated", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: false
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(this, "concatArrayBuffers", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
configurable: true,
|
|
97
|
-
writable: true,
|
|
98
|
-
value: function (buffer1, buffer2) {
|
|
99
|
-
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
|
|
100
|
-
tmp.set(new Uint8Array(buffer1), 0);
|
|
101
|
-
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
|
|
102
|
-
return tmp.buffer;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
this.offset = 0;
|
|
106
|
-
this.arrayBuffer = arrayBuffer;
|
|
107
|
-
this.dataView = new DataView(arrayBuffer);
|
|
108
|
-
if (this.arrayBuffer.byteLength < 132) {
|
|
109
|
-
console.error("is not valid dicom file");
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const prefix = Value_1.default.getString(new Uint8Array(arrayBuffer, 128, 4));
|
|
113
|
-
if (prefix !== 'DICM') {
|
|
114
|
-
console.error("is not valid dicom file");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
this.offset = 132;
|
|
118
|
-
this.parse();
|
|
119
|
-
}
|
|
120
|
-
parse() {
|
|
121
|
-
this.getNextTag();
|
|
122
|
-
this.dataSet = new Dataset_1.default(this.tags, this.dataView, this.littleEndian);
|
|
123
|
-
console.log(this.dataSet);
|
|
124
|
-
this.dataSet.transferSyntaxUID = this.transferSyntaxUID;
|
|
125
|
-
return this.dataSet;
|
|
126
|
-
}
|
|
127
|
-
getDataset() {
|
|
128
|
-
return this.dataSet;
|
|
129
|
-
}
|
|
130
|
-
getNextTag() {
|
|
131
|
-
if (this.offset >= this.arrayBuffer.byteLength) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const { group, element } = this.getNextGroupAndElement();
|
|
135
|
-
if (!group && !element) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (group === 0xFFFE && (element === 0xE0DD || element === 0xE00D || element === 0xE000)) {
|
|
139
|
-
this.offset += 4;
|
|
140
|
-
return this.getNextTag();
|
|
141
|
-
}
|
|
142
|
-
if (!this.implicit && group !== 0x0002 && this.IMPLICT_TRANSFER_SYNTAXES.includes(this.transferSyntaxUID)) {
|
|
143
|
-
this.implicit = true;
|
|
144
|
-
}
|
|
145
|
-
if (this.littleEndian && group !== 0x0002 && this.BIG_ENDIAN_TRANSFER_SYNTAXES.includes(this.transferSyntaxUID)) {
|
|
146
|
-
this.littleEndian = false;
|
|
147
|
-
}
|
|
148
|
-
if (!this.inflated && group !== 0x0002 && this.DEFLATED_TRANSFER_SYNTAXES.includes(this.transferSyntaxUID)) {
|
|
149
|
-
this.offset -= 4;
|
|
150
|
-
const meta = this.dataView.buffer.slice(0, this.offset);
|
|
151
|
-
const body = this.dataView.buffer.slice(this.offset);
|
|
152
|
-
const infaltedBody = pako.inflateRaw(body);
|
|
153
|
-
this.arrayBuffer = this.concatArrayBuffers(meta, infaltedBody);
|
|
154
|
-
this.dataView = new DataView(this.arrayBuffer);
|
|
155
|
-
this.inflated = true;
|
|
156
|
-
return this.getNextTag();
|
|
157
|
-
}
|
|
158
|
-
const vr = this.getNextVR(group, element);
|
|
159
|
-
let len = 0;
|
|
160
|
-
if (this.implicit) {
|
|
161
|
-
len = this.dataView.getUint32(this.offset, this.littleEndian);
|
|
162
|
-
this.offset += 4;
|
|
163
|
-
}
|
|
164
|
-
else if (this.EXEPTED.includes(vr)) {
|
|
165
|
-
this.offset += 2; // skip 2 byte reserved
|
|
166
|
-
len = this.dataView.getUint32(this.offset, this.littleEndian);
|
|
167
|
-
this.offset += 4;
|
|
168
|
-
}
|
|
169
|
-
else if (this.VRS.includes(vr)) {
|
|
170
|
-
len = this.dataView.getUint16(this.offset, this.littleEndian);
|
|
171
|
-
this.offset += 2;
|
|
172
|
-
}
|
|
173
|
-
else if ((!vr || !vr.match(/^[A-Z]{2}$/)) && group === 0x0002 && element === 0x0000) {
|
|
174
|
-
console.log("pyz");
|
|
175
|
-
this.offset = 132;
|
|
176
|
-
this.tags = {};
|
|
177
|
-
this.implicit = true;
|
|
178
|
-
return this.getNextTag();
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
console.log("ended", vr);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (group === 0x0002 && element === 0x0010) {
|
|
185
|
-
console.log("transfer syntax uid", this.transferSyntaxUID);
|
|
186
|
-
this.transferSyntaxUID = (Value_1.default.getString(new Uint8Array(this.arrayBuffer, this.offset, len))).replace('\0', '');
|
|
187
|
-
}
|
|
188
|
-
const tag = new Tag_1.default(group, element, vr, len, this.offset);
|
|
189
|
-
const key = tag.generateKey();
|
|
190
|
-
this.tags[key] = tag;
|
|
191
|
-
if (vr === "SQ") {
|
|
192
|
-
this.getNextTag();
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
this.offset += len;
|
|
196
|
-
this.getNextTag();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
getValue(len) {
|
|
200
|
-
const value = this.arrayBuffer.slice(this.offset, len);
|
|
201
|
-
this.offset += len;
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
getNextGroupAndElement() {
|
|
205
|
-
try {
|
|
206
|
-
const group = this.dataView.getUint16(this.offset, this.littleEndian);
|
|
207
|
-
this.offset += 2;
|
|
208
|
-
const element = this.dataView.getUint16(this.offset, this.littleEndian);
|
|
209
|
-
this.offset += 2;
|
|
210
|
-
return { group, element };
|
|
211
|
-
}
|
|
212
|
-
catch (_a) {
|
|
213
|
-
return { group: 0, element: 0 };
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
getNextVR(groupInt, elementInt) {
|
|
217
|
-
if (this.implicit) {
|
|
218
|
-
return Tag_1.default.getTagVRFromDictionary(groupInt, elementInt) || "AA";
|
|
219
|
-
}
|
|
220
|
-
const vr = Value_1.default.getString(new Uint8Array(this.arrayBuffer, this.offset, 2));
|
|
221
|
-
this.offset += 2;
|
|
222
|
-
return vr;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.default = Parser;
|
package/Tag.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare class Tag {
|
|
2
|
-
name: string;
|
|
3
|
-
vr: string;
|
|
4
|
-
group: number;
|
|
5
|
-
element: number;
|
|
6
|
-
value: unknown;
|
|
7
|
-
valueLength: number;
|
|
8
|
-
offset: number;
|
|
9
|
-
constructor(group: number, element: number, vr: string, valueLength: number, offset: number, value?: ArrayBuffer, name?: string | null);
|
|
10
|
-
generateKey(): string;
|
|
11
|
-
static getTagNameFromDictionary(groupInt: number, elementInt: number): string;
|
|
12
|
-
static getTagVRFromDictionary(group: number | string, element: number | string): string;
|
|
13
|
-
static intTo4digitString(int: number): string;
|
|
14
|
-
static int8digitString(int: number): string;
|
|
15
|
-
getValue(): void;
|
|
16
|
-
}
|
|
17
|
-
export default Tag;
|