-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathdataSetToJS.js
62 lines (49 loc) · 1.88 KB
/
dataSetToJS.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
var dicomParser = (function (dicomParser) {
"use strict";
if (dicomParser === undefined) {
dicomParser = {};
}
/**
* converts an explicit dataSet to a javascript object
* @param dataSet
* @param options
*/
dicomParser.explicitDataSetToJS = function (dataSet, options) {
if(dataSet === undefined) {
throw 'dicomParser.explicitDataSetToJS: missing required parameter dataSet';
}
options = options || {
omitPrivateAttibutes: true, // true if private elements should be omitted
maxElementLength : 128 // maximum element length to try and convert to string format
};
var result = {};
for(var tag in dataSet.elements) {
var element = dataSet.elements[tag];
// skip this element if it a private element and our options specify that we should
if(options.omitPrivateAttibutes === true && dicomParser.isPrivateTag(tag))
{
continue;
}
if(element.items) {
// handle sequences
var sequenceItems = [];
for(var i=0; i < element.items.length; i++) {
sequenceItems.push(dicomParser.explicitDataSetToJS(element.items[i].dataSet, options));
}
result[tag] = sequenceItems;
} else {
if(element.length < options.maxElementLength) {
result[tag] = dicomParser.explicitElementToString(dataSet, element);
if (result[tag] === undefined){
result[tag] = {
dataOffset: element.dataOffset,
length : element.length
};
}
}
}
}
return result;
};
return dicomParser;
}(dicomParser));