-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlookup.js
55 lines (49 loc) · 1.58 KB
/
lookup.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
let axios = require('axios');
var readStudyIuid = function (req, cb) {
var iuid = '';
req.on('data', function (data) {
iuid += data;
// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (iuid.length > 1e6) {
req.connection.destroy();
cb(null);
}
});
req.on('end', function () {
cb(iuid);
});
}
function response(res, obj) {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.end(JSON.stringify(obj));
}
module.exports = function(server, req, res) {
readStudyIuid(req, function(iuid) {
if (iuid) {
axios.post(server.proxy + 'dicom/find/studies', {
studyIuid: [iuid]
}).then(proteus => {
if (proteus.data.status === 'done') {
let ret = new Array();
for (let i=0;i<proteus.data.studies.length;i++) {
ret.push({
"ID": proteus.data.studies[i].studyDbId,
"Path": "/studies/"+proteus.data.studies[i].studyDbId,
"Type": "Study"
});
}
response(res, ret);
} else {
console.log('Invalid response!');
response(res, []);
}
}).catch(error => {
console.log(error);
response(res, []);
});
} else {
response(res, []);
}
});
};