annotate OrthancServer/OrthancRestApi.cpp @ 171:da7e915202c7 Orthanc-0.2.3-Paulus

quick and dirty access to raw tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Nov 2012 13:45:36 +0100
parents 93e1b0e3b83a
children 68dae290d5fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
33 #include "OrthancRestApi.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
35 #include "OrthancInitialization.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "FromDcmtkBridge.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/Uuid.h"
171
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
38 #include "../Core/DicomFormat/DicomArray.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <dcmtk/dcmdata/dcistrmb.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <dcmtk/dcmdata/dcfilefo.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <boost/lexical_cast.hpp>
171
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
43 #include <glog/logging.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
45 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 static void SendJson(HttpOutput& output,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const Json::Value& value)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 Json::StyledWriter writer;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 std::string s = writer.write(value);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 output.AnswerBufferWithContentType(s, "application/json");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
55
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
56 static void SimplifyTagsRecursion(Json::Value& target,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
57 const Json::Value& source)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
58 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
59 assert(source.isObject());
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
60
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
61 target = Json::objectValue;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
62 Json::Value::Members members = source.getMemberNames();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
63
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
64 for (size_t i = 0; i < members.size(); i++)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
65 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
66 const Json::Value& v = source[members[i]];
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
67 const std::string& name = v["Name"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
68 const std::string& type = v["Type"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
69
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
70 if (type == "String")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
71 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
72 target[name] = v["Value"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
73 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
74 else if (type == "TooLong" ||
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
75 type == "Null")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
76 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
77 target[name] = Json::nullValue;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
78 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
79 else if (type == "Sequence")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
80 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
81 const Json::Value& array = v["Value"];
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
82 assert(array.isArray());
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
83
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
84 Json::Value children = Json::arrayValue;
126
52c7eb60bbc8 jsoncpp fixes
jodogne
parents: 85
diff changeset
85 for (Json::Value::ArrayIndex i = 0; i < array.size(); i++)
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
86 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
87 Json::Value c;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
88 SimplifyTagsRecursion(c, array[i]);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
89 children.append(c);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
90 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
91
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
92 target[name] = children;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
93 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
94 else
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
95 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
96 assert(0);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
97 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
98 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
99 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
100
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
101
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
102 static void SimplifyTags(Json::Value& target,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
103 const FileStorage& storage,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
104 const std::string& fileUuid)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
105 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
106 std::string s;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
107 storage.ReadFile(s, fileUuid);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
108
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
109 Json::Value source;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
110 Json::Reader reader;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
111 if (!reader.parse(s, source))
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
112 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
113 throw OrthancException("Corrupted JSON file");
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
114 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
115
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
116 SimplifyTagsRecursion(target, source);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
117 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
118
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
119
171
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
120 static bool GetTagContent(HttpOutput& output,
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
121 const FileStorage& storage,
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
122 const std::string& fileUuid,
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
123 const UriComponents& uri)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
124 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
125 // TODO: Implement a true caching mechanism!
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
126 static boost::mutex mutex_;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
127 static std::string lastFileUuid_;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
128 static DcmFileFormat dicomFile_;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
129
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
130 boost::mutex::scoped_lock lock(mutex_);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
131
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
132 if (fileUuid != lastFileUuid_)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
133 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
134 LOG(INFO) << "Parsing file " << fileUuid;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
135 std::string content;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
136 storage.ReadFile(content, fileUuid);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
137
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
138 DcmInputBufferStream is;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
139 if (content.size() > 0)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
140 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
141 is.setBuffer(&content[0], content.size());
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
142 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
143 is.setEos();
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
144
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
145 if (!dicomFile_.read(is).good())
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
146 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
147 return false;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
148 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
149
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
150 lastFileUuid_ = fileUuid;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
151 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
152 else
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
153 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
154 LOG(INFO) << "Already parsed file " << fileUuid;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
155 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
156
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
157 if (uri.size() == 3)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
158 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
159 DicomMap dicomSummary;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
160 FromDcmtkBridge::Convert(dicomSummary, *dicomFile_.getDataset());
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
161
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
162 DicomArray a(dicomSummary);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
163
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
164 Json::Value target = Json::arrayValue;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
165 for (size_t i = 0; i < a.GetSize(); i++)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
166 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
167 char b[16];
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
168 sprintf(b, "%04x-%04x", a.GetElement(i).GetTagGroup(),
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
169 a.GetElement(i).GetTagElement());
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
170 target.append(b);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
171 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
172
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
173 SendJson(output, target);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
174 return true;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
175 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
176
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
177 if (uri.size() == 4)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
178 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
179 if (uri[3].size() != 9 ||
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
180 uri[3][4] != '-')
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
181 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
182 return false;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
183 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
184
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
185 unsigned int group, element;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
186 if (sscanf(uri[3].c_str(), "%04x-%04x", &group, &element) != 2)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
187 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
188 return false;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
189 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
190
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
191 DcmTagKey tag(group, element);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
192 DcmElement* item = NULL;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
193
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
194 if (dicomFile_.getDataset()->findAndGetElement(tag, item).good() &&
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
195 item != NULL)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
196 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
197 std::string buffer;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
198 buffer.resize(65536);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
199 Uint32 length = item->getLength();
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
200 Uint32 offset = 0;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
201
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
202 while (offset < length)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
203 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
204 Uint32 nbytes;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
205 if (length - offset < buffer.size())
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
206 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
207 nbytes = length - offset;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
208 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
209 else
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
210 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
211 nbytes = buffer.size();
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
212 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
213
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
214 output.SendOkHeader("application/octet-stream");
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
215 if (item->getPartialValue(&buffer[0], offset, nbytes).good())
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
216 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
217 output.Send(&buffer[0], nbytes);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
218 offset += nbytes;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
219 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
220 else
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
221 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
222 return true;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
223 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
224 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
225
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
226 return true;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
227 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
228 else
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
229 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
230 return false;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
231 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
232 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
233
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
234 return false;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
235 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
236
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
237
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
238 bool OrthancRestApi::Store(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
239 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 // Prepare an input stream for the memory buffer
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 DcmInputBufferStream is;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 if (postData.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 is.setBuffer(&postData[0], postData.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 is.setEos();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
249 //printf("[%d]\n", postData.size());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 DcmFileFormat dicomFile;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (dicomFile.read(is).good())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 DicomMap dicomSummary;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 Json::Value dicomJson;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 std::string instanceUuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 StoreStatus status = StoreStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 if (postData.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 status = index_.Store
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 (instanceUuid, storage_, reinterpret_cast<const char*>(&postData[0]),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 postData.size(), dicomSummary, dicomJson, "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 switch (status)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 case StoreStatus_Success:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 result["ID"] = instanceUuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 result["Path"] = "/instances/" + instanceUuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 result["Status"] = "Success";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 case StoreStatus_AlreadyStored:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 result["ID"] = instanceUuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 result["Path"] = "/instances/" + instanceUuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 result["Status"] = "AlreadyStored";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 default:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
291 void OrthancRestApi::ConnectToModality(DicomUserConnection& c,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
292 const std::string& name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 std::string aet, address;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 int port;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 GetDicomModality(name, aet, address, port);
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
297 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC"));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 c.SetDistantApplicationEntityTitle(aet);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 c.SetDistantHost(address);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 c.SetDistantPort(port);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 c.Open();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
304 bool OrthancRestApi::MergeQueryAndTemplate(DicomMap& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
305 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 Json::Value query;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 Json::Reader reader;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 if (!reader.parse(postData, query) ||
8
3a584803783e build with visual studio
jodogne
parents: 0
diff changeset
311 query.type() != Json::objectValue)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 Json::Value::Members members = query.getMemberNames();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 for (size_t i = 0; i < members.size(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 DicomTag t = FromDcmtkBridge::FindTag(members[i]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 result.SetValue(t, query[members[i]].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
326 bool OrthancRestApi::DicomFindPatient(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
327 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
328 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 DicomMap::SetupFindPatientTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 c.FindPatient(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
343 bool OrthancRestApi::DicomFindStudy(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
344 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
345 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 DicomMap::SetupFindStudyTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
354 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
355 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 c.FindStudy(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
366 bool OrthancRestApi::DicomFindSeries(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
367 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
368 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 DicomMap::SetupFindSeriesTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
377 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
378 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) ||
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
379 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 c.FindSeries(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
390 bool OrthancRestApi::DicomFind(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
391 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
392 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 DicomMap::SetupFindPatientTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 DicomFindAnswers patients;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 c.FindPatient(patients, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 // Loop over the found patients
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 result = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 for (size_t i = 0; i < patients.GetSize(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 Json::Value patient(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 DicomMap::SetupFindStudyTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
416 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 DicomFindAnswers studies;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 c.FindStudy(studies, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 patient["Studies"] = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 // Loop over the found studies
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 for (size_t j = 0; j < studies.GetSize(); j++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 Json::Value study(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 DicomMap::SetupFindSeriesTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
434 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
435 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 DicomFindAnswers series;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 c.FindSeries(series, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 // Loop over the found series
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 study["Series"] = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 for (size_t k = 0; k < series.GetSize(); k++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 Json::Value series2(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 study["Series"].append(series2);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 patient["Studies"].append(study);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 result.append(patient);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
460 bool OrthancRestApi::DicomStore(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
461 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
462 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 Json::Value found(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 if (!Toolbox::IsUuid(postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 // This is not a UUID, assume this is a DICOM instance
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 c.Store(postData);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 else if (index_.GetSeries(found, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 // The UUID corresponds to a series
126
52c7eb60bbc8 jsoncpp fixes
jodogne
parents: 85
diff changeset
474 for (Json::Value::ArrayIndex i = 0; i < found["Instances"].size(); i++)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 std::string uuid = found["Instances"][i].asString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 Json::Value instance(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 if (index_.GetInstance(instance, uuid))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 std::string content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 storage_.ReadFile(content, instance["FileUuid"].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 c.Store(content);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 else if (index_.GetInstance(found, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 // The UUID corresponds to an instance
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 std::string content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 storage_.ReadFile(content, found["FileUuid"].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 c.Store(content);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
506 OrthancRestApi::OrthancRestApi(ServerIndex& index,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
507 const std::string& path) :
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 index_(index),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 storage_(path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 GetListOfDicomModalities(modalities_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
515 void OrthancRestApi::Handle(
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 HttpOutput& output,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 const std::string& method,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 const UriComponents& uri,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 const Arguments& headers,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 const Arguments& arguments,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 const std::string& postData)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 if (uri.size() == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 {
85
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
527 output.Redirect("app/explorer.html");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 bool existingResource = false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 Json::Value result(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
151
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
541 // Version information ------------------------------------------------------
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
542
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
543 if (uri.size() == 1 && uri[0] == "system")
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
544 {
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
545 if (method == "GET")
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
546 {
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
547 result = Json::Value(Json::objectValue);
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
548 result["Version"] = ORTHANC_VERSION;
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
549 result["Name"] = GetGlobalStringParameter("Name", "");
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
550 existingResource = true;
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
551 }
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
552 else
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
553 {
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
554 output.SendMethodNotAllowedError("GET,POST");
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
555 return;
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
556 }
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
557 }
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
558
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
559
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 // List all the instances ---------------------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 if (uri.size() == 1 && uri[0] == "instances")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 index_.GetAllUuids(result, "Instances");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 else if (method == "POST")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 // Add a new instance to the storage
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 if (Store(result, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 SendJson(output, result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
580 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 output.SendMethodNotAllowedError("GET,POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 // List all the patients, studies or series ---------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 if (uri.size() == 1 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 (uri[0] == "series" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 uri[0] == "studies" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 uri[0] == "patients"))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 if (uri[0] == "instances")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 index_.GetAllUuids(result, "Instances");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 index_.GetAllUuids(result, "Series");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 else if (uri[0] == "studies")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 index_.GetAllUuids(result, "Studies");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 else if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 index_.GetAllUuids(result, "Patients");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 // Information about a single object ----------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 else if (uri.size() == 2 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 (uri[0] == "instances" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 uri[0] == "series" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 uri[0] == "studies" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 uri[0] == "patients"))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 existingResource = index_.GetPatient(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 else if (uri[0] == "studies")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 existingResource = index_.GetStudy(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 existingResource = index_.GetSeries(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 else if (uri[0] == "instances")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 existingResource = index_.GetInstance(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 else if (method == "DELETE")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 existingResource = index_.DeletePatient(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 else if (uri[0] == "studies")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 existingResource = index_.DeleteStudy(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 existingResource = index_.DeleteSeries(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 else if (uri[0] == "instances")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 existingResource = index_.DeleteInstance(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 result["Status"] = "Success";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 output.SendMethodNotAllowedError("GET,DELETE");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 // Get the DICOM or the JSON file of one instance ---------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 else if (uri.size() == 3 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 uri[0] == "instances" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 (uri[2] == "file" ||
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
686 uri[2] == "tags" ||
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
687 uri[2] == "simplified-tags"))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 {
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
689 std::string fileUuid, contentType, filename;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 if (uri[2] == "file")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 existingResource = index_.GetDicomFile(fileUuid, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 contentType = "application/dicom";
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
694 filename = fileUuid + ".dcm";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 }
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
696 else if (uri[2] == "tags" ||
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
697 uri[2] == "simplified-tags")
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 existingResource = index_.GetJsonFile(fileUuid, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 contentType = "application/json";
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
701 filename = fileUuid + ".json";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
706 if (uri[2] == "simplified-tags")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
707 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
708 Json::Value v;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
709 SimplifyTags(v, storage_, fileUuid);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
710 SendJson(output, v);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
711 return;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
712 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
713 else
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
714 {
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
715 output.AnswerFile(storage_, fileUuid, contentType, filename.c_str());
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
716 return;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
717 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 else if (uri.size() == 3 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 uri[0] == "instances" &&
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
724 uri[2] == "frames")
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
725 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
726 Json::Value instance(Json::objectValue);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
727 existingResource = index_.GetInstance(instance, uri[1]);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
728
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
729 if (existingResource)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
730 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
731 result = Json::arrayValue;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
732
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
733 unsigned int numberOfFrames = 1;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
734 try
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
735 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
736 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
737 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString());
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
738 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
739 catch (boost::bad_lexical_cast)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
740 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
741 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
742
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
743 for (unsigned int i = 0; i < numberOfFrames; i++)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
744 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
745 result.append(i);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
746 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
747 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
748 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
749
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
750
171
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
751 else if (uri.size() >= 3 &&
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
752 uri[0] == "instances" &&
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
753 uri[2] == "content")
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
754 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
755 Json::Value instance(Json::objectValue);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
756 std::string fileUuid;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
757 existingResource = index_.GetDicomFile(fileUuid, uri[1]);
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
758
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
759 if (existingResource)
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
760 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
761 if (GetTagContent(output, storage_, fileUuid, uri))
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
762 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
763 return;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
764 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
765 else
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
766 {
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
767 existingResource = false;
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
768 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
769 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
770 }
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
771
da7e915202c7 quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
772
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
773 else if (uri[0] == "instances" &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
774 ((uri.size() == 3 &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
775 (uri[2] == "preview" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
776 uri[2] == "image-uint8" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
777 uri[2] == "image-uint16")) ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
778 (uri.size() == 5 &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
779 uri[2] == "frames" &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
780 (uri[4] == "preview" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
781 uri[4] == "image-uint8" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
782 uri[4] == "image-uint16"))))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 std::string uuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 existingResource = index_.GetDicomFile(uuid, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
787 std::string action = uri[2];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
788
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
789 unsigned int frame = 0;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
790 if (existingResource &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
791 uri.size() == 5)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
792 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
793 // Access to multi-frame image
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
794 action = uri[4];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
795 try
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
796 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
797 frame = boost::lexical_cast<unsigned int>(uri[3]);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
798 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
799 catch (boost::bad_lexical_cast)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
800 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
801 existingResource = false;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
802 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
803 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
804
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 std::string dicomContent, png;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 storage_.ReadFile(dicomContent, uuid);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
811 if (action == "preview")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
812 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
813 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_Preview);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
814 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
815 else if (action == "image-uint8")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
816 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
817 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt8);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
818 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
819 else if (action == "image-uint16")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
820 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
821 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
822 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
823 else
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
824 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
825 throw OrthancException(ErrorCode_InternalError);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
826 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
827
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 output.AnswerBufferWithContentType(png, "image/png");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
831 catch (OrthancException&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 {
85
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
833 std::string root = "";
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
834 for (size_t i = 1; i < uri.size(); i++)
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
835 {
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
836 root += "../";
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
837 }
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
838
129
5133cfc8db86 fix standalone build
jodogne
parents: 127
diff changeset
839 output.Redirect(root + "app/images/unsupported.png");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 // Changes API --------------------------------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 if (uri.size() == 1 && uri[0] == "changes")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 const static unsigned int MAX_RESULTS = 100;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 std::string filter = GetArgument(arguments, "filter", "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 int64_t since;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 unsigned int limit;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 since = boost::lexical_cast<int64_t>(GetArgument(arguments, "since", "0"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 limit = boost::lexical_cast<unsigned int>(GetArgument(arguments, "limit", "0"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
865 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 if (limit == 0 || limit > MAX_RESULTS)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 limit = MAX_RESULTS;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 if (!index_.GetChanges(result, since, filter, limit))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
876 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 // DICOM bridge -------------------------------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 if (uri.size() == 1 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 uri[0] == "modalities")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 for (Modalities::const_iterator it = modalities_.begin();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 it != modalities_.end(); it++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 result.append(*it);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 if ((uri.size() == 2 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 uri.size() == 3) &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 uri[0] == "modalities")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 if (modalities_.find(uri[1]) == modalities_.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 // Unknown modality
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 else if (uri.size() == 2)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 if (method != "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 output.SendMethodNotAllowedError("POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 result = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 result.append("find-patient");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 result.append("find-study");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 result.append("find-series");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 result.append("find");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 result.append("store");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 else if (uri.size() == 3)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 if (uri[2] != "find-patient" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 uri[2] != "find-study" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 uri[2] != "find-series" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 uri[2] != "find" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 uri[2] != "store")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 // Unknown request
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 else if (method != "POST")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 output.SendMethodNotAllowedError("POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 DicomUserConnection connection;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 ConnectToModality(connection, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 if ((uri[2] == "find-patient" && !DicomFindPatient(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 (uri[2] == "find" && !DicomFind(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 (uri[2] == "store" && !DicomStore(result, connection, postData)))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
966 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 SendJson(output, result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
980 output.SendHeader(Orthanc_HttpStatus_404_NotFound);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 }