Mercurial > hg > orthanc
annotate Resources/Samples/WebApplications/NodeToolbox.js @ 4041:ffd20cdfa82c
news
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 14:55:26 +0200 |
parents | 94f4a18a79cc |
children |
rev | line source |
---|---|
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1120
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
1375
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
10 * License, or (at your option) any later version. |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
11 * |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
15 * General Public License for more details. |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
1375
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 var fs = require('fs'); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 var http = require('http'); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 function ForwardGetRequest(orthanc, path, res) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 var opts = orthanc; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 opts.path = path; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 opts.method = 'GET'; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 http.get(opts, function(response) { |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
32 if (response.statusCode == 200) { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
33 response.setEncoding('utf-8'); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
34 response.on('data', function(chunk) { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
35 res.write(chunk); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
36 }); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
37 response.on('end', function() { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
38 res.end(); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
39 }); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
40 } else { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
41 console.log('Got error on GET forwarding: ' + |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
42 response.statusCode + ' (' + path + ')'); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
43 res.writeHead(response.statusCode); |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 res.end(); |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
45 } |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 }).on('error', function(e) { |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
47 console.log('Unable to contact Orthanc: ' + e.message); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
48 res.writeHead(503); // Service Unavailable |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
49 res.end(); |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 }); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 function ForwardPostRequest(orthanc, path, body, res) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 var opts = orthanc; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 opts.path = path; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 opts.method = 'POST'; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 opts.headers = { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 'Content-Length': body.length |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 var req = http.request(opts, function(response) { |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
63 if (response.statusCode == 200) { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
64 response.setEncoding('utf-8'); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
65 response.on('data', function(chunk) { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
66 res.write(chunk); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
67 }); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
68 response.on('end', function() { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
69 res.end(); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
70 }); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
71 } else { |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
72 console.log('Got error on POST forwarding: ' + |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
73 response.statusCode + ' (' + path + ')'); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
74 res.writeHead(response.statusCode); |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 res.end(); |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
76 } |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 }).on('error', function(e) { |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
78 console.log('Unable to contact Orthanc: ' + e.message); |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
79 res.writeHead(503); // Service Unavailable |
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
805
diff
changeset
|
80 res.end(); |
805
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 }); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 req.write(body); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 req.end(); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 function ServeFile(filename, res) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 fs.readFile(filename, function(r, c) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 res.end(c.toString()); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 }); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 function NotFound(res) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 res.writeHead(404, {'Content-Type': 'text/plain'}); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 res.end(); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 function Redirect(path, res) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 res.writeHead(301, { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 'Content-Type': 'text/plain', |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 'Location': path |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 }); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 res.end(); |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 String.prototype.startsWith = function(prefix) { |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 return this.indexOf(prefix) === 0; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 module.exports.ForwardGetRequest = ForwardGetRequest; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 module.exports.ForwardPostRequest = ForwardPostRequest; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 module.exports.NotFound = NotFound; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 module.exports.Redirect = Redirect; |
56a813a4714d
drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 module.exports.ServeFile = ServeFile; |