-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathparseDicomDataSet_test.js
113 lines (90 loc) · 3.39 KB
/
parseDicomDataSet_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { expect } from 'chai';
import DataSet from '../src/dataSet';
import ByteStream from '../src/byteStream';
import littleEndianByteArrayParser from '../src/littleEndianByteArrayParser';
import * as dicomDataSetParsers from '../src/parseDicomDataSet';
describe('parseDicomDataSet', () => {
describe('#parseDicomDataSetExplicit', () => {
function makeTestData() {
const byteArray = new Uint8Array(26);
byteArray[0] = 0x11;
byteArray[1] = 0x22;
byteArray[2] = 0x33;
byteArray[3] = 0x44;
byteArray[4] = 0x4F; // OB
byteArray[5] = 0x42;
byteArray[6] = 0x00;
byteArray[7] = 0x00;
byteArray[8] = 0x00; // length = 0
byteArray[9] = 0x00;
byteArray[10] = 0x00;
byteArray[11] = 0x00;
byteArray[12] = 0x10;
byteArray[13] = 0x22;
byteArray[14] = 0x33;
byteArray[15] = 0x44;
byteArray[16] = 0x4F; // OB
byteArray[17] = 0x42;
byteArray[18] = 0x00; // OB
byteArray[19] = 0x00;
byteArray[20] = 0x02; // length = 2
byteArray[21] = 0x00;
byteArray[22] = 0x00;
byteArray[23] = 0x00;
byteArray[24] = 0x00;
byteArray[25] = 0x00;
return byteArray;
}
it('should create and return a dataset', () => {
// Arrange
const byteArray = makeTestData();
const byteStream = new ByteStream(littleEndianByteArrayParser, byteArray);
// Act
const dataSet = new DataSet(byteStream.byteArrayParser, byteArray, {});
dicomDataSetParsers.parseDicomDataSetExplicit(dataSet, byteStream);
// Assert
expect(dataSet).to.be.ok;
});
it('should return a dataset with two elements', () => {
// Arrange
const byteArray = makeTestData();
const byteStream = new ByteStream(littleEndianByteArrayParser, byteArray);
// Act
const dataSet = new DataSet(byteStream.byteArrayParser, byteArray, {});
dicomDataSetParsers.parseDicomDataSetExplicit(dataSet, byteStream);
// Assert
expect(dataSet.elements.x22104433).to.be.ok;
expect(dataSet.elements.x22114433).to.be.ok;
});
});
describe('#parseDicomDataSetImplicit', () => {
function convertToByteArray(bytes) {
const byteArray = new Uint8Array(bytes.length);
let i = 0;
bytes.forEach((byte) => { byteArray[i++] = byte; });
return byteArray;
}
it('bytes resembling an item tag are not treated like an SQ item when using a callback', () => {
// Arrange
// (7fe0,0010) 8
const bytes = [0xe0, 0x7f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
// Looks like an item tag, but isn't since it's within pixel data
0xfe, 0xff, 0x00, 0xe0, 0x0A, 0x00, 0x00, 0x00,
];
const callback = (tag) => {
return (tag === 'x7fe00010') ? 'OW' : undefined;
};
const byteArray = convertToByteArray(bytes);
const byteStream = new ByteStream(littleEndianByteArrayParser, byteArray);
const dataSet = new DataSet(byteStream.byteArrayParser, byteArray, {});
// Act
dicomDataSetParsers.parseDicomDataSetImplicit(dataSet, byteStream, byteStream.byteArray.length, {vrCallback: callback});
// Assert
const element = dataSet.elements['x7fe00010'];
expect(element).to.be.ok;
expect(element.items).to.be.undefined;
expect(element.vr).to.equal('OW');
expect(element.length).to.equal(8);
});
});
});