annotate Resources/Samples/WebApplications/NodeToolbox.js @ 1119:af8628ea91b3

Typo: C-MOVE SCU is not supported yet
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Sep 2014 14:08:15 +0200
parents 56a813a4714d
children 009dce4ea2f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Permission is hereby granted, free of charge, to any person
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * obtaining a copy of this software and associated documentation
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * files (the "Software"), to deal in the Software without
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * restriction, including without limitation the rights to use, copy,
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * of the Software, and to permit persons to whom the Software is
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * included in all copies or substantial portions of the Software.
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * SOFTWARE.
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
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 var fs = require('fs');
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 var http = require('http');
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
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 function ForwardGetRequest(orthanc, path, res) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 var opts = orthanc;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 opts.path = path;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 opts.method = 'GET';
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 http.get(opts, function(response) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 response.setEncoding('utf-8');
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 response.on('data', function(chunk) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 res.write(chunk);
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 response.on('end', function() {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 res.end();
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }).on('error', function(e) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 console.log('Got error on GET forwarding: ' + e.message + ' (' + path + ')');
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
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 function ForwardPostRequest(orthanc, path, body, res) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 var opts = orthanc;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 opts.path = path;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 opts.method = 'POST';
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 opts.headers = {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 'Content-Length': body.length
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 var req = http.request(opts, function(response) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 response.setEncoding('utf-8');
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 response.on('data', function(chunk) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 res.write(chunk);
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 response.on('end', function() {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 res.end();
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }).on('error', function(e) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 console.log('Got error on POST forwarding: ' + e.message + ' (' + path + ')');
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 req.write(body);
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 req.end();
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 function ServeFile(filename, res) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 fs.readFile(filename, function(r, c) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 res.end(c.toString());
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 });
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
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 function NotFound(res) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 res.writeHead(404, {'Content-Type': 'text/plain'});
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 res.end();
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
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 function Redirect(path, res) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 res.writeHead(301, {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 'Content-Type': 'text/plain',
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 'Location': path
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 res.end();
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 String.prototype.startsWith = function(prefix) {
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return this.indexOf(prefix) === 0;
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
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 module.exports.ForwardGetRequest = ForwardGetRequest;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 module.exports.ForwardPostRequest = ForwardPostRequest;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 module.exports.NotFound = NotFound;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 module.exports.Redirect = Redirect;
56a813a4714d drawing dicomizer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 module.exports.ServeFile = ServeFile;