-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (98 loc) · 3.44 KB
/
index.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
114
115
116
117
118
119
120
121
122
import { readdirSync, readFileSync } from 'fs';
import { resolve, join } from 'path';
let tagReleases = new Map();
let uidReleases = new Map();
let tagActiveName = 'current';
let uidActiveName = 'current';
function loadTagReleaseNames() {
if (tagReleases.size > 0) {
return;
}
readdirSync(resolve('./data'), { withFileTypes: true })
.filter(ent => ent.isDirectory())
.forEach(ent => {
tagReleases.set(ent.name, null)
});
}
function loadUidReleaseNames() {
if (uidReleases.size > 0) {
return;
}
readdirSync(resolve('./data'), { withFileTypes: true })
.filter(ent => ent.isDirectory())
.forEach(ent => {
uidReleases.set(ent.name, null)
});
}
function loadTagRegistryForReleaseName(releaseName) {
loadTagReleaseNames();
if (!tagReleases.has(releaseName)) {
throw new Error('DICOM release name "' + releaseName + '" not recognized.');
}
let jsondata = readFileSync(resolve(join('./data', releaseName, 'tagRegistry.json')));
let data = JSON.parse(jsondata);
let registry = new Map(data.tags.map(each => [each.tag, each]));
tagReleases.set(releaseName, registry);
// For most releases, directory name matches release name in metainfo.
// However, the current release uses the "current" directory.
// List the registry under both names.
if(releaseName != data.metadata.release) {
tagReleases.set(data.metadata.release, registry);
}
return registry;
}
function loadUidRegistryForReleaseName(releaseName) {
loadUidReleaseNames();
if (!uidReleases.has(releaseName)) {
throw new Error('DICOM release name "' + releaseName + '" not recognized.');
}
let jsondata = readFileSync(resolve(join('./data', releaseName, 'uidRegistry.json')));
let data = JSON.parse(jsondata);
let registry = new Map(data.uids.map(each => [each.value, each]));
uidReleases.set(releaseName, registry);
// For most releases, directory name matches release name in metainfo.
// However, the current release uses the "current" directory.
// List the registry under both names.
if(releaseName != data.metadata.release) {
uidReleases.set(data.metadata.release, registry);
}
return registry;
}
export function tagReleaseNames() {
loadTagReleaseNames();
return tagReleases.keys();
}
export function uidReleaseNames() {
loadUidReleaseNames();
return uidReleases.keys();
}
export function tagRegistryForReleaseName(releaseName) {
return tagReleases.get(releaseName) || loadTagRegistryForReleaseName(releaseName);
}
export function uidRegistryForReleaseName(releaseName) {
return uidReleases.get(releaseName) || loadUidRegistryForReleaseName(releaseName);
}
export function activeTagRegistry() {
return tagRegistryForReleaseName(activeTagReleaseName());
}
export function activeUidRegistry() {
return uidRegistryForReleaseName(activeUidReleaseName());
}
export function activateTagReleaseName(releaseName) {
loadTagRegistryForReleaseName(releaseName)
var oldName = tagActiveName;
tagActiveName = releaseName;
return oldName;
}
export function activateUidReleaseName(releaseName) {
loadUidRegistryForReleaseName(releaseName)
var oldName = uidActiveName;
uidActiveName = releaseName;
return oldName;
}
export function activeTagReleaseName() {
return tagActiveName;
}
export function activeUidReleaseName() {
return uidActiveName;
}