@abasb75/dicom-parser 0.0.6-test → 0.0.20

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/package.json CHANGED
@@ -1,35 +1,27 @@
1
1
  {
2
- "name": "@abasb75/dicom-parser",
3
- "version": "0.0.6-test",
4
- "description": "a javascript powerfull dicom parser",
5
- "main": "index.js",
6
- "type": "module",
7
- "types": "index.d.ts",
8
- "keywords": [
9
- "dicom",
10
- "dcm",
11
- "dcmjs",
12
- "dicom-parser",
13
- "pacs"
14
- ],
15
- "author": "Abbas Bagheri <abasbagheria@gmail.com>",
16
- "license": "ISC",
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/abasb75/dicom-parser/raction.git"
20
- },
21
- "bugs": {
22
- "url": "https://github.com/abasb75/dicom-parser/issues"
23
- },
24
- "homepage": "https://github.com/abasb75/dicom-parser#readme",
25
- "dependencies": {
26
- "pako": "^2.1.0"
27
- },
28
- "peerDependencies": {
29
- "pako": "^2.1.0"
30
- },
31
- "devDependencies": {
32
- "pako": "^2.1.0",
33
- "@types/pako": "^2.0.3"
34
- }
2
+ "name": "@abasb75/dicom-parser",
3
+ "version": "0.0.20",
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
+ }
35
27
  }
package/Dataset.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { DicomDate, DicomPatientModule, DicomPixelModule, DicomTime, DicomVOILutModule, Tags } from "./types";
2
- declare class Dataset {
3
- tags: Tags;
4
- transferSyntaxUID: string;
5
- dataView: DataView;
6
- studyInstanceUID: string;
7
- studyID: string;
8
- seriesInstanceUID: string;
9
- seriesNumber: number | string | undefined;
10
- studyDate: string | DicomDate;
11
- studyTime: number | DicomTime | string | undefined;
12
- pixelRepresentation: number | string | undefined;
13
- littleEndian: boolean;
14
- pixeSpacing: number | number[] | string | undefined;
15
- accessionNumber: string;
16
- bitsAllocated: number | string | undefined;
17
- bitsStored: number | string | undefined;
18
- highBit: number | string | undefined;
19
- imageType: number | string | number[] | string[] | undefined;
20
- modality: number | string | number[] | string[] | undefined;
21
- seriesDescription: string;
22
- rows: string | number | undefined;
23
- columns: string | number | undefined;
24
- patientSex: any;
25
- /** modules */
26
- voiLUTModule: DicomVOILutModule;
27
- patientModule: DicomPatientModule;
28
- pixelModule: DicomPixelModule;
29
- constructor(tags: Tags, dataView: DataView, littleEndian: boolean);
30
- getPixelData(): import("./types").PixelArray[];
31
- getVOILutModule(): DicomVOILutModule;
32
- getPatientModule(): DicomPatientModule;
33
- getPixelModule(): DicomPixelModule;
34
- date(group: number, element: number): string | {
35
- year: string;
36
- month: string;
37
- day: string;
38
- };
39
- time(group: number, element: number): string | {
40
- hour: string;
41
- minute: string;
42
- second: string;
43
- };
44
- int(group: number, element: number): number | undefined;
45
- get(group: number, element: number): string;
46
- string(group: number, element: number): string;
47
- getValue(element: number | string, elementId?: number | string, vr?: string): string | number | DataView | (string | number)[] | undefined;
48
- private _getValue;
49
- private _reformatToString;
50
- draw(canvas: HTMLCanvasElement): void;
51
- }
52
- export default Dataset;
package/Dataset.js DELETED
@@ -1,320 +0,0 @@
1
- import Draw from "./Draw";
2
- import PixelData from "./PixelData";
3
- import Tag from "./Tag";
4
- import Value from "./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, "seriesInstanceUID", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- Object.defineProperty(this, "seriesNumber", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: void 0
48
- });
49
- Object.defineProperty(this, "studyDate", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- Object.defineProperty(this, "studyTime", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: void 0
60
- });
61
- Object.defineProperty(this, "pixelRepresentation", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
67
- Object.defineProperty(this, "littleEndian", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: void 0
72
- });
73
- Object.defineProperty(this, "pixeSpacing", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: void 0
78
- });
79
- Object.defineProperty(this, "accessionNumber", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: void 0
84
- });
85
- Object.defineProperty(this, "bitsAllocated", {
86
- enumerable: true,
87
- configurable: true,
88
- writable: true,
89
- value: void 0
90
- });
91
- Object.defineProperty(this, "bitsStored", {
92
- enumerable: true,
93
- configurable: true,
94
- writable: true,
95
- value: void 0
96
- });
97
- Object.defineProperty(this, "highBit", {
98
- enumerable: true,
99
- configurable: true,
100
- writable: true,
101
- value: void 0
102
- });
103
- Object.defineProperty(this, "imageType", {
104
- enumerable: true,
105
- configurable: true,
106
- writable: true,
107
- value: void 0
108
- });
109
- Object.defineProperty(this, "modality", {
110
- enumerable: true,
111
- configurable: true,
112
- writable: true,
113
- value: void 0
114
- });
115
- Object.defineProperty(this, "seriesDescription", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: void 0
120
- });
121
- Object.defineProperty(this, "rows", {
122
- enumerable: true,
123
- configurable: true,
124
- writable: true,
125
- value: void 0
126
- });
127
- Object.defineProperty(this, "columns", {
128
- enumerable: true,
129
- configurable: true,
130
- writable: true,
131
- value: void 0
132
- });
133
- Object.defineProperty(this, "patientSex", {
134
- enumerable: true,
135
- configurable: true,
136
- writable: true,
137
- value: void 0
138
- });
139
- /** modules */
140
- Object.defineProperty(this, "voiLUTModule", {
141
- enumerable: true,
142
- configurable: true,
143
- writable: true,
144
- value: void 0
145
- });
146
- Object.defineProperty(this, "patientModule", {
147
- enumerable: true,
148
- configurable: true,
149
- writable: true,
150
- value: void 0
151
- });
152
- Object.defineProperty(this, "pixelModule", {
153
- enumerable: true,
154
- configurable: true,
155
- writable: true,
156
- value: void 0
157
- });
158
- this.tags = tags;
159
- this.dataView = dataView;
160
- this.littleEndian = littleEndian;
161
- this.studyID = this.get(0x0020, 0x0010);
162
- this.studyInstanceUID = this.string(0x0020, 0x000D);
163
- this.seriesInstanceUID = this.get(0x0020, 0x000E);
164
- this.seriesNumber = this.get(0x0020, 0x0011);
165
- this.studyDate = this.date(0x0008, 0x0020);
166
- this.studyTime = this.time(0x0008, 0x0030);
167
- this.accessionNumber = this.string(0x0008, 0x0050);
168
- this.imageType = this.get(0x0008, 0x0008);
169
- this.modality = this.get(0x0008, 0x0060);
170
- this.seriesDescription = this.string(0x0008, 0x103E);
171
- this.patientSex = this.get(0x0010, 0x0040);
172
- this.voiLUTModule = this.getVOILutModule();
173
- this.patientModule = this.getPatientModule();
174
- this.pixelModule = this.getPixelModule();
175
- }
176
- getPixelData() {
177
- return PixelData.get(this);
178
- }
179
- getVOILutModule() {
180
- return {
181
- voiLUTFunction: this.get(0x0028, 0x1056),
182
- windowWidth: this.int(0x0028, 0x1050),
183
- windowCenter: this.int(0x0028, 0x1051),
184
- voiLUTSequence: this.get(0x0028, 0x3010),
185
- lutDescriptor: this.get(0x0028, 0x3002),
186
- lutExplanation: this.get(0x0028, 0x3003),
187
- lutData: this.get(0x0028, 0x3006),
188
- windowCenterAndWidthExplanation: this.get(0x0028, 0x1055),
189
- };
190
- }
191
- getPatientModule() {
192
- return {
193
- patientName: this.get(0x0010, 0x0010),
194
- patientID: this.get(0x0010, 0x0020),
195
- typeofPatientID: this.get(0x0010, 0x0022),
196
- patientSex: this.get(0x0010, 0x0040),
197
- patientBirthDate: this.get(0x0010, 0x0030),
198
- patientAge: this.get(0x0010, 0x1010),
199
- patientSize: this.get(0x0010, 0x1020),
200
- otherPatientIDs: this.get(0x0010, 0x1000),
201
- otherPatientNames: this.get(0x0010, 0x1001),
202
- patientWeight: this.get(0x0010, 0x1030),
203
- };
204
- }
205
- getPixelModule() {
206
- return {
207
- photometricInterpretation: this.get(0x0028, 0x0004),
208
- numberOfFrames: this.int(0x0028, 0x0008),
209
- pixelRepresentation: this.int(0x0028, 0x0103),
210
- pixeSpacing: this.get(0x0028, 0x0030),
211
- rows: this.int(0x0028, 0x0010),
212
- columns: this.int(0x0028, 0x0011),
213
- bitsAllocated: this.int(0x0028, 0x0100),
214
- highBit: this.int(0x0028, 0x0102),
215
- bitsStored: this.int(0x0028, 0x0101),
216
- samplesPerPixel: this.int(0x0028, 0x0002)
217
- };
218
- }
219
- date(group, element) {
220
- const dateValue = this.get(group, element);
221
- if (/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/.exec(dateValue)) {
222
- console.log('dateValue1', dateValue);
223
- const dateVaues = dateValue.split('-');
224
- return {
225
- year: dateVaues[0],
226
- month: dateVaues[1],
227
- day: dateVaues[2],
228
- };
229
- }
230
- console.log('dateValue', dateValue);
231
- return dateValue;
232
- }
233
- time(group, element) {
234
- const dateValue = this.get(group, element);
235
- if (/^[0-9]{2}\:[0-9]{2}\:[0-9]{2}$/.exec(dateValue)) {
236
- console.log('dateValue1', dateValue);
237
- const dateVaues = dateValue.split(':');
238
- return {
239
- hour: dateVaues[0],
240
- minute: dateVaues[1],
241
- second: dateVaues[2],
242
- };
243
- }
244
- console.log('dateValue', dateValue);
245
- return dateValue;
246
- }
247
- int(group, element) {
248
- const is = this.get(group, element);
249
- if (typeof is === "number") {
250
- return is;
251
- }
252
- else {
253
- return undefined;
254
- }
255
- }
256
- get(group, element) {
257
- const value = this.getValue(group, element);
258
- return value;
259
- }
260
- string(group, element) {
261
- return this.getValue(group, element) + "";
262
- }
263
- getValue(element, elementId, vr) {
264
- var _a;
265
- if (!element && !elementId) {
266
- return "";
267
- }
268
- let _group, _element = "";
269
- if (typeof element === 'string' && element.length >= 8) {
270
- const el = element.replace(/^0[xX]/, '');
271
- if (el.length !== 8) {
272
- return "";
273
- }
274
- _group = el.slice(0, 3);
275
- _element = el.slice(4, 7);
276
- }
277
- else if (typeof element === 'number' && element > 0xffff) {
278
- const el = Tag.intTo4digitString(element);
279
- _group = el.slice(0, 3);
280
- _element = el.slice(4, 7);
281
- }
282
- else {
283
- _group = this._reformatToString(element);
284
- _element = this._reformatToString(elementId);
285
- if (!_group || !_element)
286
- return "";
287
- }
288
- const key = `0x${_group}${_element}`;
289
- if (!this.tags[key]) {
290
- return "";
291
- }
292
- const _vr = vr || ((_a = this.tags[key]) === null || _a === void 0 ? void 0 : _a.vr) || Tag.getTagVRFromDictionary(_group, _element) || "AA";
293
- return this._getValue(this.tags[key], _vr);
294
- }
295
- _getValue(tag, vr = "AA") {
296
- const offset = tag.offset;
297
- if (!offset)
298
- return "";
299
- const len = tag.valueLength;
300
- const value = Value.byVr(this.dataView, offset, len, vr, this.littleEndian);
301
- tag.value = value;
302
- return value;
303
- }
304
- _reformatToString(input) {
305
- if (!input)
306
- return "";
307
- if (typeof input === "string") {
308
- return input.replace(/^0[xX]/, '');
309
- }
310
- return Tag.intTo4digitString(input);
311
- }
312
- draw(canvas) {
313
- const pixelDatas = this.getPixelData();
314
- if (pixelDatas) {
315
- //@ts-ignore
316
- Draw.draw(canvas, pixelDatas, this);
317
- }
318
- }
319
- }
320
- export default Dataset;
package/Draw.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import Dataset from "./Dataset";
2
- import { PixelArray } from "./types";
3
- declare class Draw {
4
- static draw(canvas: HTMLCanvasElement, pixelDatas: PixelArray[], dataset: Dataset): void;
5
- private static _getLUT;
6
- private static _calcPixel;
7
- }
8
- export default Draw;
package/Draw.js DELETED
@@ -1,54 +0,0 @@
1
- import Utilities from "./Utitlities";
2
- class Draw {
3
- static draw(canvas, pixelDatas, dataset) {
4
- if (!pixelDatas.length)
5
- return;
6
- const pixelData = pixelDatas[0];
7
- const { min, max, windowCenter, windowWidth } = Draw._getLUT(pixelData, dataset);
8
- console.log('lut', min, max, windowCenter, windowWidth);
9
- canvas.width = dataset.pixelModule.columns || 0;
10
- canvas.height = dataset.pixelModule.rows || 0;
11
- console.log(canvas.width * canvas.height, pixelData.length);
12
- const context = canvas.getContext('2d');
13
- const imageData = context === null || context === void 0 ? void 0 : context.createImageData(canvas.width, canvas.height);
14
- if (imageData) {
15
- for (var i = 0; i < pixelData.length; i++) {
16
- imageData.data[4 * i] = Draw._calcPixel(pixelData[i], min, max, windowWidth, windowCenter);
17
- imageData.data[4 * i + 1] = Draw._calcPixel(pixelData[i], min, max, windowWidth, windowCenter);
18
- imageData.data[4 * i + 2] = Draw._calcPixel(pixelData[i], min, max, windowWidth, windowCenter);
19
- imageData.data[4 * i + 3] = 255;
20
- }
21
- context === null || context === void 0 ? void 0 : context.putImageData(imageData, 0, 0);
22
- }
23
- }
24
- static _getLUT(pixelData, dataset) {
25
- if (dataset.voiLUTModule.windowCenter && dataset.voiLUTModule.windowWidth) {
26
- const windowWidth = dataset.voiLUTModule.windowWidth;
27
- const windowCenter = dataset.voiLUTModule.windowCenter;
28
- return {
29
- windowWidth,
30
- windowCenter,
31
- max: windowCenter - 0.5 + windowWidth / 2,
32
- min: windowCenter - 0.5 - windowWidth / 2,
33
- };
34
- }
35
- const { min, max } = Utilities.getMinMax(pixelData);
36
- const windowWidth = max - min;
37
- const windowCenter = min + windowWidth / 2 - 0.5;
38
- return {
39
- min,
40
- max,
41
- windowWidth,
42
- windowCenter,
43
- };
44
- }
45
- static _calcPixel(pixel, min, max, windowWidth, windowCenter) {
46
- if (max <= pixel)
47
- return 255;
48
- else if (min >= pixel)
49
- return 0;
50
- else
51
- return (Math.round(pixel - windowCenter - 0.5) / (windowWidth - 1) + 0.5) * 255;
52
- }
53
- }
54
- export default Draw;
package/Loader.d.ts DELETED
@@ -1,8 +0,0 @@
1
- declare class Loader {
2
- private dicomSrc;
3
- private xhr;
4
- constructor(dicomSrc?: string);
5
- load(dicomSrc?: string | File): Promise<ArrayBuffer | undefined>;
6
- cancel(): void;
7
- }
8
- export default Loader;
package/Loader.js DELETED
@@ -1,63 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- class Loader {
11
- constructor(dicomSrc) {
12
- Object.defineProperty(this, "dicomSrc", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: void 0
17
- });
18
- Object.defineProperty(this, "xhr", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: void 0
23
- });
24
- this.dicomSrc = dicomSrc;
25
- this.xhr = new XMLHttpRequest();
26
- }
27
- load(dicomSrc) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- if (typeof dicomSrc === "string") {
30
- const dicom = dicomSrc || this.dicomSrc;
31
- if (!dicom)
32
- return;
33
- return new Promise((resolve, reject) => {
34
- this.xhr.onload = () => {
35
- resolve(this.xhr.response);
36
- };
37
- this.xhr.onerror = () => {
38
- reject(this.xhr);
39
- };
40
- this.xhr.responseType = 'arraybuffer';
41
- this.xhr.open('GET', dicom, true);
42
- this.xhr.send();
43
- });
44
- }
45
- else if (dicomSrc instanceof File) {
46
- return new Promise((resolve, reject) => {
47
- dicomSrc.arrayBuffer().then((arrayBuffer) => {
48
- resolve(arrayBuffer);
49
- }).catch(reason => reject(reason));
50
- });
51
- }
52
- return new Promise((resolve, reject) => {
53
- if (false)
54
- resolve(new ArrayBuffer(1));
55
- reject("dicom source is not valid");
56
- });
57
- });
58
- }
59
- cancel() {
60
- this.xhr.abort();
61
- }
62
- }
63
- export 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
- getNextElement(): 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;