Mercurial > hg > orthanc
comparison Resources/Samples/WebApplications/NodeToolbox.js @ 1120:009dce4ea2f6
/tools/create-dicom now accepts PatientID
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Sep 2014 16:49:26 +0200 |
parents | 56a813a4714d |
children | 6e7e5ed91c2d |
comparison
equal
deleted
inserted
replaced
1119:af8628ea91b3 | 1120:009dce4ea2f6 |
---|---|
33 var opts = orthanc; | 33 var opts = orthanc; |
34 opts.path = path; | 34 opts.path = path; |
35 opts.method = 'GET'; | 35 opts.method = 'GET'; |
36 | 36 |
37 http.get(opts, function(response) { | 37 http.get(opts, function(response) { |
38 response.setEncoding('utf-8'); | 38 if (response.statusCode == 200) { |
39 response.on('data', function(chunk) { | 39 response.setEncoding('utf-8'); |
40 res.write(chunk); | 40 response.on('data', function(chunk) { |
41 }); | 41 res.write(chunk); |
42 response.on('end', function() { | 42 }); |
43 response.on('end', function() { | |
44 res.end(); | |
45 }); | |
46 } else { | |
47 console.log('Got error on GET forwarding: ' + | |
48 response.statusCode + ' (' + path + ')'); | |
49 res.writeHead(response.statusCode); | |
43 res.end(); | 50 res.end(); |
44 }); | 51 } |
45 }).on('error', function(e) { | 52 }).on('error', function(e) { |
46 console.log('Got error on GET forwarding: ' + e.message + ' (' + path + ')'); | 53 console.log('Unable to contact Orthanc: ' + e.message); |
54 res.writeHead(503); // Service Unavailable | |
55 res.end(); | |
47 }); | 56 }); |
48 } | 57 } |
49 | 58 |
50 | 59 |
51 function ForwardPostRequest(orthanc, path, body, res) { | 60 function ForwardPostRequest(orthanc, path, body, res) { |
55 opts.headers = { | 64 opts.headers = { |
56 'Content-Length': body.length | 65 'Content-Length': body.length |
57 } | 66 } |
58 | 67 |
59 var req = http.request(opts, function(response) { | 68 var req = http.request(opts, function(response) { |
60 response.setEncoding('utf-8'); | 69 if (response.statusCode == 200) { |
61 response.on('data', function(chunk) { | 70 response.setEncoding('utf-8'); |
62 res.write(chunk); | 71 response.on('data', function(chunk) { |
63 }); | 72 res.write(chunk); |
64 response.on('end', function() { | 73 }); |
74 response.on('end', function() { | |
75 res.end(); | |
76 }); | |
77 } else { | |
78 console.log('Got error on POST forwarding: ' + | |
79 response.statusCode + ' (' + path + ')'); | |
80 res.writeHead(response.statusCode); | |
65 res.end(); | 81 res.end(); |
66 }); | 82 } |
67 }).on('error', function(e) { | 83 }).on('error', function(e) { |
68 console.log('Got error on POST forwarding: ' + e.message + ' (' + path + ')'); | 84 console.log('Unable to contact Orthanc: ' + e.message); |
85 res.writeHead(503); // Service Unavailable | |
86 res.end(); | |
69 }); | 87 }); |
70 | 88 |
71 req.write(body); | 89 req.write(body); |
72 req.end(); | 90 req.end(); |
73 } | 91 } |