-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
97 lines (76 loc) · 2.63 KB
/
server.js
File metadata and controls
97 lines (76 loc) · 2.63 KB
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
/* eslint no-console: ["error", { allow: ["info", "warn", "error"] }] */
const http = require('http');
const hostname = '0.0.0.0';
const port = 8080;
const irdbbToken = process.env.IRDBB_TOKEN;
if (!irdbbToken) {
console.error('Environment variable IRDBB_TOKEN not set');
return;
}
const semanticTranslator = 'semantictranslator';
const semanticTranslatorPort = 8090;
const semanticTranslatorPath = '/importKheopsSR';
const pacs = 'pacsarc';
const pacsPort = 8080;
const pacsDICOMwebPath = '/dcm4chee-arc/aets/DCM4CHEE/rs';
const server = http.createServer((request, res) => {
if (request.method === 'POST') {
console.info(`request for ${request.url}`);
const bodyData = [];
request.on('data', (chunk) => {
bodyData.push(chunk);
});
request.on('end', () => {
const requestBody = JSON.parse(bodyData);
if (requestBody.source.capability_token !== undefined
&& requestBody.source.capability_token.id === irdbbToken) {
console.info('Skipping series sent by the IRDBB token');
return;
}
const updatedStudy = requestBody.updated_study;
const updatedSeries = updatedStudy.series;
const studyIntanceUID = updatedStudy.study_uid;
updatedSeries.forEach((series) => {
if (series.modality !== 'SR') {
console.info(`Skipping modality ${series.modality}`);
return;
}
const seriesIntanceUID = series.series_uid;
const requestOptions = {
hostname: semanticTranslator,
port: semanticTranslatorPort,
path: semanticTranslatorPath,
method: 'POST',
headers: {
'Content-Type': 'text/plain',
},
};
const sendRequest = http.request(requestOptions, (response) => {
let data = '';
response.on('data', (chunk) => {
data += chunk;
});
response.on('end', () => {
console.info(`Called Semantic Translator to import DICOM series. (${response.statusCode})`);
console.info();
console.info(data);
});
}).on('error', (err) => {
console.info(`Error: ${err.message}`);
});
const seriesURL = `http://${pacs}:${pacsPort}${pacsDICOMwebPath}/studies/${studyIntanceUID}/series/${seriesIntanceUID}`;
console.info(`seriesURL: ${seriesURL}`);
sendRequest.write(seriesURL);
sendRequest.end();
});
});
res.statusCode = 204;
res.end();
} else {
res.statusCode = 405;
res.end();
}
});
server.listen(port, hostname, () => {
console.info(`Server running at http://${hostname}:${port}/`);
});