annotate OrthancServer/OrthancRestApi.cpp @ 187:8e673a65564d

refactoring of storing new instances
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Nov 2012 17:29:11 +0100
parents 93e1b0e3b83a
children b6cef9d45cc3
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"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <dcmtk/dcmdata/dcistrmb.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <dcmtk/dcmdata/dcfilefo.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
43 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 static void SendJson(HttpOutput& output,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 const Json::Value& value)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 Json::StyledWriter writer;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 std::string s = writer.write(value);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 output.AnswerBufferWithContentType(s, "application/json");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
53
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
54 static void SimplifyTagsRecursion(Json::Value& target,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
55 const Json::Value& source)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
56 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
57 assert(source.isObject());
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
58
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
59 target = Json::objectValue;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
60 Json::Value::Members members = source.getMemberNames();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
61
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
62 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
63 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
64 const Json::Value& v = source[members[i]];
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
65 const std::string& name = v["Name"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
66 const std::string& type = v["Type"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
67
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
68 if (type == "String")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
69 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
70 target[name] = v["Value"].asString();
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
71 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
72 else if (type == "TooLong" ||
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
73 type == "Null")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
74 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
75 target[name] = Json::nullValue;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
76 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
77 else if (type == "Sequence")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
78 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
79 const Json::Value& array = v["Value"];
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
80 assert(array.isArray());
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
81
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
82 Json::Value children = Json::arrayValue;
126
52c7eb60bbc8 jsoncpp fixes
jodogne
parents: 85
diff changeset
83 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
84 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
85 Json::Value c;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
86 SimplifyTagsRecursion(c, array[i]);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
87 children.append(c);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
88 }
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 target[name] = children;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
91 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
92 else
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
93 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
94 assert(0);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
95 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
96 }
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 static void SimplifyTags(Json::Value& target,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
101 const FileStorage& storage,
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
102 const std::string& fileUuid)
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
103 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
104 std::string s;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
105 storage.ReadFile(s, fileUuid);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
106
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
107 Json::Value source;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
108 Json::Reader reader;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
109 if (!reader.parse(s, source))
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
110 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
111 throw OrthancException("Corrupted JSON file");
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
112 }
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 SimplifyTagsRecursion(target, source);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
115 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
116
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
117
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
118 bool OrthancRestApi::Store(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
119 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 // Prepare an input stream for the memory buffer
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 DcmInputBufferStream is;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (postData.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 is.setBuffer(&postData[0], postData.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 is.setEos();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
129 //printf("[%d]\n", postData.size());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 DcmFileFormat dicomFile;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 if (dicomFile.read(is).good())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 DicomMap dicomSummary;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset());
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
136
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
137 DicomInstanceHasher hasher(dicomSummary);
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
138
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 Json::Value dicomJson;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 StoreStatus status = StoreStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 if (postData.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 status = index_.Store
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
146 (storage_, reinterpret_cast<const char*>(&postData[0]),
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 postData.size(), dicomSummary, dicomJson, "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
150 result["ID"] = hasher.HashInstance();
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
151 result["Path"] = "/instances/" + hasher.HashInstance();
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
152
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 switch (status)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 case StoreStatus_Success:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 result["Status"] = "Success";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 case StoreStatus_AlreadyStored:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 result["Status"] = "AlreadyStored";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 default:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
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 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
171 void OrthancRestApi::ConnectToModality(DicomUserConnection& c,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
172 const std::string& name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 std::string aet, address;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 int port;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 GetDicomModality(name, aet, address, port);
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
177 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC"));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 c.SetDistantApplicationEntityTitle(aet);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 c.SetDistantHost(address);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 c.SetDistantPort(port);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 c.Open();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
184 bool OrthancRestApi::MergeQueryAndTemplate(DicomMap& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
185 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 Json::Value query;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 Json::Reader reader;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 if (!reader.parse(postData, query) ||
8
3a584803783e build with visual studio
jodogne
parents: 0
diff changeset
191 query.type() != Json::objectValue)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
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 Json::Value::Members members = query.getMemberNames();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 for (size_t i = 0; i < members.size(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 DicomTag t = FromDcmtkBridge::FindTag(members[i]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 result.SetValue(t, query[members[i]].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
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 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
206 bool OrthancRestApi::DicomFindPatient(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
207 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
208 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 DicomMap::SetupFindPatientTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
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 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 c.FindPatient(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
223 bool OrthancRestApi::DicomFindStudy(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
224 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
225 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 DicomMap::SetupFindStudyTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
234 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
235 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
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 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 c.FindStudy(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
246 bool OrthancRestApi::DicomFindSeries(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
247 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
248 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 DicomMap::SetupFindSeriesTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
257 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
258 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) ||
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
259 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
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 DicomFindAnswers answers;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 c.FindSeries(answers, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 answers.ToJson(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
270 bool OrthancRestApi::DicomFind(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
271 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
272 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 DicomMap m;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 DicomMap::SetupFindPatientTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
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 DicomFindAnswers patients;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 c.FindPatient(patients, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 // Loop over the found patients
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 result = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 for (size_t i = 0; i < patients.GetSize(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 Json::Value patient(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 DicomMap::SetupFindStudyTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
296 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 DicomFindAnswers studies;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 c.FindStudy(studies, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 patient["Studies"] = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 // Loop over the found studies
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 for (size_t j = 0; j < studies.GetSize(); j++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 Json::Value study(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 DicomMap::SetupFindSeriesTemplate(m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 if (!MergeQueryAndTemplate(m, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 }
80
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
314 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
315 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 DicomFindAnswers series;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 c.FindSeries(series, m);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 // Loop over the found series
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 study["Series"] = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 for (size_t k = 0; k < series.GetSize(); k++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 Json::Value series2(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 study["Series"].append(series2);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
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 patient["Studies"].append(study);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
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 result.append(patient);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
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
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
340 bool OrthancRestApi::DicomStore(Json::Value& result,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
341 DicomUserConnection& c,
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
342 const std::string& postData)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 Json::Value found(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 if (!Toolbox::IsUuid(postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 // This is not a UUID, assume this is a DICOM instance
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 c.Store(postData);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 else if (index_.GetSeries(found, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 // The UUID corresponds to a series
126
52c7eb60bbc8 jsoncpp fixes
jodogne
parents: 85
diff changeset
354 for (Json::Value::ArrayIndex i = 0; i < found["Instances"].size(); i++)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 std::string uuid = found["Instances"][i].asString();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 Json::Value instance(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 if (index_.GetInstance(instance, uuid))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 std::string content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 storage_.ReadFile(content, instance["FileUuid"].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 c.Store(content);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 }
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 else if (index_.GetInstance(found, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 // The UUID corresponds to an instance
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 std::string content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 storage_.ReadFile(content, found["FileUuid"].asString());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 c.Store(content);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
386 OrthancRestApi::OrthancRestApi(ServerIndex& index,
50
a15e90e5d6fc rename in code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
387 const std::string& path) :
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 index_(index),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 storage_(path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 GetListOfDicomModalities(modalities_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 }
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
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
395 void OrthancRestApi::Handle(
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 HttpOutput& output,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 const std::string& method,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 const UriComponents& uri,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 const Arguments& headers,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 const Arguments& arguments,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 const std::string& postData)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 if (uri.size() == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
85
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
407 output.Redirect("app/explorer.html");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
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 bool existingResource = false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 Json::Value result(Json::objectValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
151
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
421 // Version information ------------------------------------------------------
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
422
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
423 if (uri.size() == 1 && uri[0] == "system")
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
424 {
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
425 if (method == "GET")
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
426 {
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
427 result = Json::Value(Json::objectValue);
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
428 result["Version"] = ORTHANC_VERSION;
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
429 result["Name"] = GetGlobalStringParameter("Name", "");
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
430 result["TotalCompressedSize"] = boost::lexical_cast<std::string>(index_.GetTotalCompressedSize());
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
431 result["TotalUncompressedSize"] = boost::lexical_cast<std::string>(index_.GetTotalUncompressedSize());
151
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
432 existingResource = true;
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
433 }
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
434 else
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
435 {
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
436 output.SendMethodNotAllowedError("GET,POST");
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
437 return;
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
438 }
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
439 }
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
440
11e48e70c039 instance naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
441
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 // List all the instances ---------------------------------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 if (uri.size() == 1 && uri[0] == "instances")
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 if (method == "GET")
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 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 index_.GetAllUuids(result, "Instances");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 existingResource = true;
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 else if (method == "POST")
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 // Add a new instance to the storage
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 if (Store(result, postData))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 SendJson(output, result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
462 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 return;
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 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 output.SendMethodNotAllowedError("GET,POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 // List all the patients, studies or series ---------------------------------
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 if (uri.size() == 1 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 (uri[0] == "series" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 uri[0] == "studies" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 uri[0] == "patients"))
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 if (method == "GET")
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 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 if (uri[0] == "instances")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 index_.GetAllUuids(result, "Instances");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 index_.GetAllUuids(result, "Series");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 else if (uri[0] == "studies")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 index_.GetAllUuids(result, "Studies");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 else if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 index_.GetAllUuids(result, "Patients");
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 existingResource = true;
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 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502
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 // Information about a single object ----------------------------------------
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 else if (uri.size() == 2 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 (uri[0] == "instances" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 uri[0] == "series" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 uri[0] == "studies" ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 uri[0] == "patients"))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 if (method == "GET")
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 if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 existingResource = index_.GetPatient(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 else if (uri[0] == "studies")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 existingResource = index_.GetStudy(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 existingResource = index_.GetSeries(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 else if (uri[0] == "instances")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 existingResource = index_.GetInstance(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 }
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 else if (method == "DELETE")
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 if (uri[0] == "patients")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 existingResource = index_.DeletePatient(result, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 else if (uri[0] == "studies")
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 existingResource = index_.DeleteStudy(result, uri[1]);
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 else if (uri[0] == "series")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 existingResource = index_.DeleteSeries(result, uri[1]);
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 else if (uri[0] == "instances")
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 existingResource = index_.DeleteInstance(result, uri[1]);
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 result["Status"] = "Success";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 output.SendMethodNotAllowedError("GET,DELETE");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 // Get the DICOM or the JSON file of one instance ---------------------------
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 else if (uri.size() == 3 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 uri[0] == "instances" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 (uri[2] == "file" ||
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
568 uri[2] == "tags" ||
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
569 uri[2] == "simplified-tags"))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 {
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
571 std::string fileUuid, contentType, filename;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 if (uri[2] == "file")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 existingResource = index_.GetDicomFile(fileUuid, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 contentType = "application/dicom";
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
576 filename = fileUuid + ".dcm";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 }
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
578 else if (uri[2] == "tags" ||
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
579 uri[2] == "simplified-tags")
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 existingResource = index_.GetJsonFile(fileUuid, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 contentType = "application/json";
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
583 filename = fileUuid + ".json";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 }
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 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 {
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
588 if (uri[2] == "simplified-tags")
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
589 {
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
590 Json::Value v;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
591 SimplifyTags(v, storage_, fileUuid);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
592 SendJson(output, v);
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
593 return;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
594 }
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
595 else
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
596 {
155
93e1b0e3b83a filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
597 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
598 return;
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
599 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 else if (uri.size() == 3 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 uri[0] == "instances" &&
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
606 uri[2] == "frames")
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 Json::Value instance(Json::objectValue);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
609 existingResource = index_.GetInstance(instance, uri[1]);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
610
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
611 if (existingResource)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
612 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
613 result = Json::arrayValue;
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 unsigned int numberOfFrames = 1;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
616 try
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 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
619 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString());
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
620 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
621 catch (boost::bad_lexical_cast)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
622 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
623 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
624
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
625 for (unsigned int i = 0; i < numberOfFrames; i++)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
626 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
627 result.append(i);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
628 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
629 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
630 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
631
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
632
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
633 else if (uri[0] == "instances" &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
634 ((uri.size() == 3 &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
635 (uri[2] == "preview" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
636 uri[2] == "image-uint8" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
637 uri[2] == "image-uint16")) ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
638 (uri.size() == 5 &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
639 uri[2] == "frames" &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
640 (uri[4] == "preview" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
641 uri[4] == "image-uint8" ||
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
642 uri[4] == "image-uint16"))))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 std::string uuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 existingResource = index_.GetDicomFile(uuid, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
647 std::string action = uri[2];
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 unsigned int frame = 0;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
650 if (existingResource &&
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
651 uri.size() == 5)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
652 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
653 // Access to multi-frame image
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
654 action = uri[4];
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
655 try
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
656 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
657 frame = boost::lexical_cast<unsigned int>(uri[3]);
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
658 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
659 catch (boost::bad_lexical_cast)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
660 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
661 existingResource = false;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
662 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
663 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
664
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 std::string dicomContent, png;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 storage_.ReadFile(dicomContent, uuid);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
671 if (action == "preview")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
672 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
673 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_Preview);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
674 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
675 else if (action == "image-uint8")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
676 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
677 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt8);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
678 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
679 else if (action == "image-uint16")
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
680 {
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
681 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
682 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
683 else
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
684 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
685 throw OrthancException(ErrorCode_InternalError);
42
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
686 }
ea48f38afe5f access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 41
diff changeset
687
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 output.AnswerBufferWithContentType(png, "image/png");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 }
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
691 catch (OrthancException&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 {
85
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
693 std::string root = "";
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
694 for (size_t i = 1; i < uri.size(); i++)
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
695 {
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
696 root += "../";
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
697 }
ebce15865cce relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
698
129
5133cfc8db86 fix standalone build
jodogne
parents: 127
diff changeset
699 output.Redirect(root + "app/images/unsupported.png");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 return;
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 }
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
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 // Changes API --------------------------------------------------------------
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 if (uri.size() == 1 && uri[0] == "changes")
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 if (method == "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 const static unsigned int MAX_RESULTS = 100;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 std::string filter = GetArgument(arguments, "filter", "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 int64_t since;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 unsigned int limit;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 try
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 since = boost::lexical_cast<int64_t>(GetArgument(arguments, "since", "0"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 limit = boost::lexical_cast<unsigned int>(GetArgument(arguments, "limit", "0"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
725 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 return;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 if (limit == 0 || limit > MAX_RESULTS)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 limit = MAX_RESULTS;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 if (!index_.GetChanges(result, since, filter, limit))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
736 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748
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 // DICOM bridge -------------------------------------------------------------
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 if (uri.size() == 1 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 uri[0] == "modalities")
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 (method == "GET")
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 result = Json::Value(Json::arrayValue);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 for (Modalities::const_iterator it = modalities_.begin();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 it != modalities_.end(); it++)
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 result.append(*it);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 output.SendMethodNotAllowedError("GET");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 if ((uri.size() == 2 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 uri.size() == 3) &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 uri[0] == "modalities")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 if (modalities_.find(uri[1]) == modalities_.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 // Unknown modality
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 else if (uri.size() == 2)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 if (method != "GET")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 output.SendMethodNotAllowedError("POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 result = Json::arrayValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 result.append("find-patient");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 result.append("find-study");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 result.append("find-series");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 result.append("find");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 result.append("store");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 else if (uri.size() == 3)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 if (uri[2] != "find-patient" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 uri[2] != "find-study" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 uri[2] != "find-series" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 uri[2] != "find" &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 uri[2] != "store")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 // Unknown request
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 else if (method != "POST")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 output.SendMethodNotAllowedError("POST");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 DicomUserConnection connection;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 ConnectToModality(connection, uri[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 existingResource = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 if ((uri[2] == "find-patient" && !DicomFindPatient(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 (uri[2] == "find" && !DicomFind(result, connection, postData)) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 (uri[2] == "store" && !DicomStore(result, connection, postData)))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
826 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 if (existingResource)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 SendJson(output, result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 58
diff changeset
840 output.SendHeader(Orthanc_HttpStatus_404_NotFound);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 }