annotate OrthancServer/OrthancRestApi.cpp @ 210:96b7918a6a18

start of the refactoring of the Orthanc REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Nov 2012 18:03:44 +0100
parents de640de989b8
children b7aea293b965
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"
208
de640de989b8 HttpFileSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
38 #include "../Core/HttpServer/FilesystemHttpSender.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>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
44 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 static void SendJson(HttpOutput& output,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 const Json::Value& value)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 Json::StyledWriter writer;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 std::string s = writer.write(value);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 output.AnswerBufferWithContentType(s, "application/json");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
54
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
55 static void SimplifyTagsRecursion(Json::Value& target,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
56 const Json::Value& source)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
57 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
58 assert(source.isObject());
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
59
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
60 target = Json::objectValue;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
61 Json::Value::Members members = source.getMemberNames();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
62
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
63 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
64 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
65 const Json::Value& v = source[members[i]];
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
66 const std::string& name = v["Name"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
67 const std::string& type = v["Type"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
68
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
69 if (type == "String")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
70 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
71 target[name] = v["Value"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
72 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
73 else if (type == "TooLong" ||
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
74 type == "Null")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
75 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
76 target[name] = Json::nullValue;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
77 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
78 else if (type == "Sequence")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
79 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
80 const Json::Value& array = v["Value"];
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
81 assert(array.isArray());
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
82
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
83 Json::Value children = Json::arrayValue;
126
52c7eb60bbc8 jsoncpp fixes
jodogne
parents: 85
diff changeset
84 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
85 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
86 Json::Value c;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
87 SimplifyTagsRecursion(c, array[i]);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
88 children.append(c);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
89 }
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 target[name] = children;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
92 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
93 else
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
94 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
95 assert(0);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
96 }
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 static void SimplifyTags(Json::Value& target,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
102 const FileStorage& storage,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
103 const std::string& fileUuid)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
104 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
105 std::string s;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
106 storage.ReadFile(s, fileUuid);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
107
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
108 Json::Value source;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
109 Json::Reader reader;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
110 if (!reader.parse(s, source))
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
111 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
112 throw OrthancException("Corrupted JSON file");
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
113 }
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 SimplifyTagsRecursion(target, source);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
116 }
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
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
119 bool OrthancRestApi::Store(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
120 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 // Prepare an input stream for the memory buffer
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 DcmInputBufferStream is;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 if (postData.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 is.setBuffer(&postData[0], postData.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 is.setEos();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
130 //printf("[%d]\n", postData.size());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 DcmFileFormat dicomFile;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 if (dicomFile.read(is).good())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 DicomMap dicomSummary;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset());
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
137
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
138 DicomInstanceHasher hasher(dicomSummary);
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
139
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 Json::Value dicomJson;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 StoreStatus status = StoreStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 if (postData.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 status = index_.Store
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
147 (storage_, reinterpret_cast<const char*>(&postData[0]),
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 postData.size(), dicomSummary, dicomJson, "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
151 result["ID"] = hasher.HashInstance();
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
152 result["Path"] = "/instances/" + hasher.HashInstance();
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
153
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 switch (status)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 case StoreStatus_Success:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 result["Status"] = "Success";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 case StoreStatus_AlreadyStored:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 result["Status"] = "AlreadyStored";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 default:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
172 void OrthancRestApi::ConnectToModality(DicomUserConnection& c,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
173 const std::string& name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 std::string aet, address;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 int port;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 GetDicomModality(name, aet, address, port);
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
178 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC"));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 c.SetDistantApplicationEntityTitle(aet);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 c.SetDistantHost(address);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 c.SetDistantPort(port);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 c.Open();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
185 bool OrthancRestApi::MergeQueryAndTemplate(DicomMap& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
186 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 Json::Value query;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 Json::Reader reader;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 if (!reader.parse(postData, query) ||
8
3a584803783e build with visual studio
jodogne
parents: 0
diff changeset
192 query.type() != Json::objectValue)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 Json::Value::Members members = query.getMemberNames();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 for (size_t i = 0; i < members.size(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 DicomTag t = FromDcmtkBridge::FindTag(members[i]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 result.SetValue(t, query[members[i]].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
207 bool OrthancRestApi::DicomFindPatient(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
208 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
209 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 DicomMap::SetupFindPatientTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 c.FindPatient(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
224 bool OrthancRestApi::DicomFindStudy(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
225 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
226 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 DicomMap::SetupFindStudyTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
235 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
236 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
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 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 c.FindStudy(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
247 bool OrthancRestApi::DicomFindSeries(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
248 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
249 const std::string& postData)
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 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 DicomMap::SetupFindSeriesTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 return false;
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
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
258 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
259 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) ||
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
260 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 return false;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 c.FindSeries(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
271 bool OrthancRestApi::DicomFind(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
272 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
273 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 DicomMap::SetupFindPatientTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 DicomFindAnswers patients;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 c.FindPatient(patients, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 // Loop over the found patients
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 result = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 for (size_t i = 0; i < patients.GetSize(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 Json::Value patient(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 DicomMap::SetupFindStudyTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
297 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 DicomFindAnswers studies;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 c.FindStudy(studies, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 patient["Studies"] = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 // Loop over the found studies
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 for (size_t j = 0; j < studies.GetSize(); j++)
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 study(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j));
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 DicomMap::SetupFindSeriesTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 if (!MergeQueryAndTemplate(m, postData))
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 }
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
315 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
316 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 DicomFindAnswers series;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 c.FindSeries(series, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 // Loop over the found series
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 study["Series"] = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 for (size_t k = 0; k < series.GetSize(); k++)
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 Json::Value series2(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 study["Series"].append(series2);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
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 patient["Studies"].append(study);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 result.append(patient);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
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 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
341 bool OrthancRestApi::DicomStore(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
342 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
343 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 Json::Value found(Json::objectValue);
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 if (!Toolbox::IsUuid(postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 // This is not a UUID, assume this is a DICOM instance
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 c.Store(postData);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 else if (index_.GetSeries(found, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 // The UUID corresponds to a series
126
52c7eb60bbc8 jsoncpp fixes
jodogne
parents: 85
diff changeset
355 for (Json::Value::ArrayIndex i = 0; i < found["Instances"].size(); i++)
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 std::string uuid = found["Instances"][i].asString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 Json::Value instance(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 if (index_.GetInstance(instance, uuid))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 std::string content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 storage_.ReadFile(content, instance["FileUuid"].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 c.Store(content);
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 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 }
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 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 else if (index_.GetInstance(found, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 // The UUID corresponds to an instance
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 std::string content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 storage_.ReadFile(content, found["FileUuid"].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 c.Store(content);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
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 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
387 OrthancRestApi::OrthancRestApi(ServerIndex& index,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
388 const std::string& path) :
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 index_(index),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 storage_(path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 GetListOfDicomModalities(modalities_);
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
396 void OrthancRestApi::Handle(
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 HttpOutput& output,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 const std::string& method,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 const UriComponents& uri,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 const Arguments& headers,
207
7f74209ea0f8 RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
401 const Arguments& getArguments,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 const std::string& postData)
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 if (uri.size() == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
85
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
408 output.Redirect("app/explorer.html");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 output.SendMethodNotAllowedError("GET");
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 }
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 bool existingResource = false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 Json::Value result(Json::objectValue);
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 // List all the instances ---------------------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 if (uri.size() == 1 && uri[0] == "instances")
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 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 result = Json::Value(Json::arrayValue);
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
429 index_.GetAllUuids(result, ResourceType_Instance);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 existingResource = true;
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 else if (method == "POST")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 // Add a new instance to the storage
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 if (Store(result, postData))
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 SendJson(output, result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 return;
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 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
442 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 else
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 output.SendMethodNotAllowedError("GET,POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 return;
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
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 // List all the patients, studies or series ---------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 if (uri.size() == 1 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 (uri[0] == "series" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 uri[0] == "studies" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 uri[0] == "patients"))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 if (uri[0] == "instances")
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
466 index_.GetAllUuids(result, ResourceType_Instance);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 else if (uri[0] == "series")
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
468 index_.GetAllUuids(result, ResourceType_Series);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 else if (uri[0] == "studies")
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
470 index_.GetAllUuids(result, ResourceType_Study);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 else if (uri[0] == "patients")
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
472 index_.GetAllUuids(result, ResourceType_Patient);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 existingResource = true;
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 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
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 // Information about a single object ----------------------------------------
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 else if (uri.size() == 2 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 (uri[0] == "instances" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 uri[0] == "series" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 uri[0] == "studies" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 uri[0] == "patients"))
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 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 existingResource = index_.GetPatient(result, uri[1]);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
497 assert(!existingResource || result["Type"] == "Patient");
0
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 else if (uri[0] == "studies")
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 existingResource = index_.GetStudy(result, uri[1]);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
502 assert(!existingResource || result["Type"] == "Study");
0
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 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 existingResource = index_.GetSeries(result, uri[1]);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
507 assert(!existingResource || result["Type"] == "Series");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 else if (uri[0] == "instances")
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 existingResource = index_.GetInstance(result, uri[1]);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
512 assert(!existingResource || result["Type"] == "Instance");
0
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 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 else if (method == "DELETE")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 existingResource = index_.DeletePatient(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 else if (uri[0] == "studies")
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 existingResource = index_.DeleteStudy(result, uri[1]);
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 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 existingResource = index_.DeleteSeries(result, uri[1]);
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 if (uri[0] == "instances")
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 existingResource = index_.DeleteInstance(result, uri[1]);
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 if (existingResource)
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 result["Status"] = "Success";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 output.SendMethodNotAllowedError("GET,DELETE");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 // Get the DICOM or the JSON file of one instance ---------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 else if (uri.size() == 3 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 uri[0] == "instances" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 (uri[2] == "file" ||
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
552 uri[2] == "tags" ||
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
553 uri[2] == "simplified-tags"))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 {
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
555 CompressionType compressionType;
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
556 std::string fileUuid, contentType, filename;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 if (uri[2] == "file")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
197
530a25320461 removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
559 existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Dicom);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 contentType = "application/dicom";
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
561 filename = fileUuid + ".dcm";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 }
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
563 else if (uri[2] == "tags" ||
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
564 uri[2] == "simplified-tags")
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 {
197
530a25320461 removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
566 existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Json);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 contentType = "application/json";
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
568 filename = fileUuid + ".json";
0
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
573 if (uri[2] == "simplified-tags")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
574 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
575 Json::Value v;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
576 SimplifyTags(v, storage_, fileUuid);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
577 SendJson(output, v);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
578 return;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
579 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
580 else
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
581 {
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
582 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
583 return;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
584 }
0
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 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
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 else if (uri.size() == 3 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 uri[0] == "instances" &&
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
591 uri[2] == "frames")
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
592 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
593 Json::Value instance(Json::objectValue);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
594 existingResource = index_.GetInstance(instance, uri[1]);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
595
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
596 if (existingResource)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
597 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
598 result = Json::arrayValue;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
599
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
600 unsigned int numberOfFrames = 1;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
601 try
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
602 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
603 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
604 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString());
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
605 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
606 catch (boost::bad_lexical_cast)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
607 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
608 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
609
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
610 for (unsigned int i = 0; i < numberOfFrames; i++)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
611 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
612 result.append(i);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
613 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
614 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
615 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
616
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
617
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
618 else if (uri[0] == "instances" &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
619 ((uri.size() == 3 &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
620 (uri[2] == "preview" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
621 uri[2] == "image-uint8" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
622 uri[2] == "image-uint16")) ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
623 (uri.size() == 5 &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
624 uri[2] == "frames" &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
625 (uri[4] == "preview" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
626 uri[4] == "image-uint8" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
627 uri[4] == "image-uint16"))))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 std::string uuid;
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
630 CompressionType compressionType;
197
530a25320461 removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
631 existingResource = index_.GetFile(uuid, compressionType, uri[1], AttachedFileType_Dicom);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
633 std::string action = uri[2];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
634
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
635 unsigned int frame = 0;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
636 if (existingResource &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
637 uri.size() == 5)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
638 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
639 // Access to multi-frame image
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
640 action = uri[4];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
641 try
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
642 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
643 frame = boost::lexical_cast<unsigned int>(uri[3]);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
644 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
645 catch (boost::bad_lexical_cast)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
646 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
647 existingResource = false;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
648 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
649 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
650
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 if (existingResource)
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 std::string dicomContent, png;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 storage_.ReadFile(dicomContent, uuid);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
657 if (action == "preview")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
658 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
659 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_Preview);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
660 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
661 else if (action == "image-uint8")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
662 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
663 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt8);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
664 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
665 else if (action == "image-uint16")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
666 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
667 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
668 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
669 else
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
670 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
671 throw OrthancException(ErrorCode_InternalError);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
672 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
673
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 output.AnswerBufferWithContentType(png, "image/png");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 }
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
677 catch (OrthancException&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 {
85
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
679 std::string root = "";
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
680 for (size_t i = 1; i < uri.size(); i++)
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
681 {
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
682 root += "../";
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
683 }
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
684
129
5133cfc8db86 fix standalone build
jodogne
parents: 127
diff changeset
685 output.Redirect(root + "app/images/unsupported.png");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690
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 // DICOM bridge -------------------------------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 if ((uri.size() == 2 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 uri.size() == 3) &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 uri[0] == "modalities")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 if (modalities_.find(uri[1]) == modalities_.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 // Unknown modality
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 else if (uri.size() == 2)
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 (method != "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 output.SendMethodNotAllowedError("POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 result = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 result.append("find-patient");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 result.append("find-study");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 result.append("find-series");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 result.append("find");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 result.append("store");
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 else if (uri.size() == 3)
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 if (uri[2] != "find-patient" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 uri[2] != "find-study" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 uri[2] != "find-series" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 uri[2] != "find" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 uri[2] != "store")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 // Unknown request
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 else if (method != "POST")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 output.SendMethodNotAllowedError("POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 DicomUserConnection connection;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 ConnectToModality(connection, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 if ((uri[2] == "find-patient" && !DicomFindPatient(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 (uri[2] == "find" && !DicomFind(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 (uri[2] == "store" && !DicomStore(result, connection, postData)))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
747 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 SendJson(output, result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
761 output.SendHeader(Orthanc_HttpStatus_404_NotFound);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 }