annotate OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1172:059391d3f8df db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Sep 2014 13:44:08 +0200
parents 1ea4094d077c a921e3b5e763
children 09aa7c126be9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../ServerToolbox.h"
795
d466b3606aca refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
37 #include "../FromDcmtkBridge.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <glog/logging.h>
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 // List all the patients, studies, series or instances ----------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
46 static void ListResources(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 OrthancRestApi::GetIndex(call).GetAllUuids(result, resourceType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
54 static void GetSingleResource(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
64 static void DeleteSingleResource(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Json::Value result;
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1140
diff changeset
67 if (OrthancRestApi::GetContext(call).DeleteResource(result, call.GetUriComponent("id", ""), resourceType))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 // Get information about a single patient -----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
76 static void IsProtectedPatient(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
84 static void SetPatientProtection(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 std::string s = Toolbox::StripSpaces(call.GetPutBody());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if (s == "0")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 context.GetIndex().SetProtectedPatient(publicId, false);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 call.GetOutput().AnswerBuffer("", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 else if (s == "1")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 context.GetIndex().SetProtectedPatient(publicId, true);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 call.GetOutput().AnswerBuffer("", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 // Bad request
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 // Get information about a single instance ----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
110 static void GetInstanceFile(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 std::string publicId = call.GetUriComponent("id", "");
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
115 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
119 static void ExportInstanceFile(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 std::string dicom;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 context.ReadFile(dicom, publicId, FileContentType_Dicom);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 Toolbox::WriteFile(dicom, call.GetPostBody());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 call.GetOutput().AnswerBuffer("{}", "application/json");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 template <bool simplify>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
135 static void GetInstanceTags(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (simplify)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
143 Json::Value full;
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
144 context.ReadJson(full, publicId);
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
145
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 Json::Value simplified;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 SimplifyTags(simplified, full);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 call.GetOutput().AnswerJson(simplified);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
152 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_DicomAsJson);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
156
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
157 static void GetInstanceTagsBis(RestApiGetCall& call)
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
158 {
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
159 bool simplify = call.HasArgument("simplify");
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
160
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
161 if (simplify)
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
162 {
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
163 GetInstanceTags<true>(call);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
164 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
165 else
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
166 {
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
167 GetInstanceTags<false>(call);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
168 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
169 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
170
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
172 static void ListFrames(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 Json::Value instance;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 if (OrthancRestApi::GetIndex(call).LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 unsigned int numberOfFrames = 1;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 try
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"];
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 catch (...)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 for (unsigned int i = 0; i < numberOfFrames; i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 result.append(i);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 template <enum ImageExtractionMode mode>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
200 static void GetImage(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 std::string frameId = call.GetUriComponent("frame", "0");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 unsigned int frame;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 try
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 frame = boost::lexical_cast<unsigned int>(frameId);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 catch (boost::bad_lexical_cast)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 std::string dicomContent, png;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 context.ReadFile(dicomContent, publicId, FileContentType_Dicom);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
220 ParsedDicomFile dicom(dicomContent);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
221
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 try
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
224 dicom.ExtractPngImage(png, frame, mode);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 call.GetOutput().AnswerBuffer(png, "image/png");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 catch (OrthancException& e)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 // The frame number is out of the range for this DICOM
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 // instance, the resource is not existent
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 std::string root = "";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 for (size_t i = 1; i < call.GetFullUri().size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 root += "../";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 call.GetOutput().Redirect(root + "app/images/unsupported.png");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
248 static void GetMatlabImage(RestApiGetCall& call)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
249 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
250 ServerContext& context = OrthancRestApi::GetContext(call);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
251
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
252 std::string frameId = call.GetUriComponent("frame", "0");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
253
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
254 unsigned int frame;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
255 try
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
256 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
257 frame = boost::lexical_cast<unsigned int>(frameId);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
258 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
259 catch (boost::bad_lexical_cast)
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
260 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
261 return;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
262 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
263
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
264 std::string publicId = call.GetUriComponent("id", "");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
265 std::string dicomContent;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
266 context.ReadFile(dicomContent, publicId, FileContentType_Dicom);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
267
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
268 ParsedDicomFile dicom(dicomContent);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
269 ImageBuffer buffer;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
270 dicom.ExtractImage(buffer, frame);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
271
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
272 ImageAccessor accessor(buffer.GetConstAccessor());
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
273
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
274 std::string result;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
275 accessor.ToMatlabString(result);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
276
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
277 call.GetOutput().AnswerBuffer(result, "text/plain");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
278 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
279
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
280
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
282 static void GetResourceStatistics(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 OrthancRestApi::GetIndex(call).GetStatistics(result, publicId);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 // Handling of metadata -----------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
294 static void CheckValidResourceType(RestApiCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 std::string resourceType = call.GetUriComponent("resourceType", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 StringToResourceType(resourceType.c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
301 static void ListMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 std::list<MetadataType> metadata;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 OrthancRestApi::GetIndex(call).ListAvailableMetadata(metadata, publicId);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 for (std::list<MetadataType>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 it = metadata.begin(); it != metadata.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 result.append(EnumerationToString(*it));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
321 static void GetMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 std::string value;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, publicId, metadata))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 call.GetOutput().AnswerBuffer(value, "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
337 static void DeleteMetadata(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 if (metadata >= MetadataType_StartUser &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 metadata <= MetadataType_EndUser)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 // It is forbidden to modify internal metadata
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 call.GetOutput().AnswerBuffer("", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
355 static void SetMetadata(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 std::string value = call.GetPutBody();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 if (metadata >= MetadataType_StartUser &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 metadata <= MetadataType_EndUser)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 // It is forbidden to modify internal metadata
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 OrthancRestApi::GetIndex(call).SetMetadata(publicId, metadata, value);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 call.GetOutput().AnswerBuffer("", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 // Handling of attached files -----------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
378 static void ListAttachments(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 std::string resourceType = call.GetUriComponent("resourceType", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 std::list<FileContentType> attachments;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str()));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 for (std::list<FileContentType>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 it = attachments.begin(); it != attachments.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 result.append(EnumerationToString(*it));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
397 static bool GetAttachmentInfo(FileInfo& info, RestApiCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 return OrthancRestApi::GetIndex(call).LookupAttachment(info, publicId, contentType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
409 static void GetAttachmentOperations(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 Json::Value operations = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 operations.append("compressed-data");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 if (info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 operations.append("compressed-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 operations.append("compressed-size");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 operations.append("data");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 if (info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 operations.append("md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 operations.append("size");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 if (info.GetCompressedMD5() != "" &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 operations.append("verify-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 call.GetOutput().AnswerJson(operations);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 template <int uncompress>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
445 static void GetAttachmentData(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 std::string publicId = call.GetUriComponent("id", "");
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
452 FileContentType type = StringToContentType(call.GetUriComponent("name", ""));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
454 if (uncompress)
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
455 {
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
456 context.AnswerAttachment(call.GetOutput(), publicId, type);
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
457 }
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
458 else
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
459 {
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
460 // Return the raw data (possibly compressed), as stored on the filesystem
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
461 std::string content;
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
462 context.ReadFile(content, publicId, type, false);
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
463 call.GetOutput().AnswerBuffer(content, "application/octet-stream");
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
464 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
468 static void GetAttachmentSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedSize()), "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
478 static void GetAttachmentCompressedSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedSize()), "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
488 static void GetAttachmentMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedMD5()), "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
499 static void GetAttachmentCompressedMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedMD5()), "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
510 static void VerifyAttachment(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 if (!GetAttachmentInfo(info, call) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 info.GetCompressedMD5() == "" ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 info.GetUncompressedMD5() == "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 // Inexistent resource, or no MD5 available
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 bool ok = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 // First check whether the compressed data is correctly stored in the disk
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 std::string data;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 context.ReadFile(data, publicId, StringToContentType(name), false);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 std::string actualMD5;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 if (actualMD5 == info.GetCompressedMD5())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 // The compressed data is OK. If a compression algorithm was
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 // applied to it, now check the MD5 of the uncompressed data.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 if (info.GetCompressionType() == CompressionType_None)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 ok = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 context.ReadFile(data, publicId, StringToContentType(name), true);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 ok = (actualMD5 == info.GetUncompressedMD5());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 if (ok)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has the right MD5";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 call.GetOutput().AnswerBuffer("{}", "application/json");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has bad MD5!";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
564 static void UploadAttachment(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 const void* data = call.GetPutBody().size() ? &call.GetPutBody()[0] : NULL;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 if (contentType >= FileContentType_StartUser && // It is forbidden to modify internal attachments
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 contentType <= FileContentType_EndUser &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 call.GetOutput().AnswerBuffer("{}", "application/json");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
584 static void DeleteAttachment(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 if (contentType >= FileContentType_StartUser &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 contentType <= FileContentType_EndUser)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 // It is forbidden to delete internal attachments
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 call.GetOutput().AnswerBuffer("{}", "application/json");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
602 // Raw access to the DICOM tags of an instance ------------------------------
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
603
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
604 static void GetRawContent(RestApiGetCall& call)
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
605 {
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
606 std::string id = call.GetUriComponent("id", "");
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
607
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
608 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
609
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
610 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
611 }
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
612
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
615 static bool ExtractSharedTags(Json::Value& shared,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
616 ServerContext& context,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
617 const std::string& publicId)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
618 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
619 // Retrieve all the instances of this patient/study/series
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
620 typedef std::list<std::string> Instances;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
621 Instances instances;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
622 context.GetIndex().GetChildInstances(instances, publicId); // (*)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
623
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
624 // Loop over the instances
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
625 bool isFirst = true;
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
626 shared = Json::objectValue;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
627
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
628 for (Instances::const_iterator it = instances.begin();
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
629 it != instances.end(); it++)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
630 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
631 // Get the tags of the current instance, in the simplified format
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
632 Json::Value tags;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
633
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
634 try
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
635 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
636 context.ReadJson(tags, *it);
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
637 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
638 catch (OrthancException&)
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
639 {
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
640 // Race condition: This instance has been removed since
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
641 // (*). Ignore this instance.
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
642 continue;
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
643 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
644
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
645 if (tags.type() != Json::objectValue)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
646 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
647 return false; // Error
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
648 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
649
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
650 // Only keep the tags that are mapped to a string
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
651 Json::Value::Members members = tags.getMemberNames();
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
652 for (size_t i = 0; i < members.size(); i++)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
653 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
654 const Json::Value& tag = tags[members[i]];
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
655 if (tag.type() != Json::objectValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
656 tag["Type"].type() != Json::stringValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
657 tag["Type"].asString() != "String")
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
658 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
659 tags.removeMember(members[i]);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
660 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
661 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
662
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
663 if (isFirst)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
664 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
665 // This is the first instance, keep its tags as such
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
666 shared = tags;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
667 isFirst = false;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
668 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
669 else
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
670 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
671 // Loop over all the members of the shared tags extracted so
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
672 // far. If the value of one of these tags does not match its
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
673 // value in the current instance, remove it.
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
674 members = shared.getMemberNames();
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
675 for (size_t i = 0; i < members.size(); i++)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
676 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
677 if (!tags.isMember(members[i]) ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
678 tags[members[i]]["Value"].asString() != shared[members[i]]["Value"].asString())
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
679 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
680 shared.removeMember(members[i]);
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
681 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
682 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
683 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
684 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
685
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
686 return true;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
687 }
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
688
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
689
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
690 static void GetSharedTags(RestApiGetCall& call)
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
691 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
692 ServerContext& context = OrthancRestApi::GetContext(call);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
693 std::string publicId = call.GetUriComponent("id", "");
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
694 bool simplify = call.HasArgument("simplify");
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
695
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
696 Json::Value sharedTags;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
697 if (ExtractSharedTags(sharedTags, context, publicId))
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
698 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
699 // Success: Send the value of the shared tags
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
700 if (simplify)
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
701 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
702 Json::Value simplified;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
703 SimplifyTags(simplified, sharedTags);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
704 call.GetOutput().AnswerJson(simplified);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
705 }
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
706 else
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
707 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
708 call.GetOutput().AnswerJson(sharedTags);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
709 }
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
710 }
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
711 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
712
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
713
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
714 static void GetModuleInternal(RestApiGetCall& call,
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
715 ResourceType resourceType,
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
716 ResourceType queryLevel)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
717 {
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
718 if (resourceType != queryLevel &&
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
719 !(resourceType == ResourceType_Study && queryLevel == ResourceType_Patient))
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
720 {
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
721 throw OrthancException(ErrorCode_NotImplemented);
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
722 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
723
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
724 ServerContext& context = OrthancRestApi::GetContext(call);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
725 std::string publicId = call.GetUriComponent("id", "");
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
726 bool simplify = call.HasArgument("simplify");
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
727
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
728 typedef std::set<DicomTag> Module;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
729 Module module;
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
730 DicomTag::GetTagsForModule(module, queryLevel);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
731
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
732 Json::Value tags;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
733
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
734 if (resourceType != ResourceType_Instance)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
735 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
736 // Retrieve all the instances of this patient/study/series
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
737 typedef std::list<std::string> Instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
738 Instances instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
739 context.GetIndex().GetChildInstances(instances, publicId);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
740
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
741 if (instances.empty())
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
742 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
743 return; // Error: No instance (should never happen)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
744 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
745
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
746 // Select one child instance
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
747 publicId = instances.front();
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
748 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
749
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
750 context.ReadJson(tags, publicId);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
751
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
752 // Filter the tags of the instance according to the module
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
753 Json::Value result = Json::objectValue;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
754 for (Module::const_iterator it = module.begin(); it != module.end(); it++)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
755 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
756 std::string s = it->Format();
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
757 if (tags.isMember(s))
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
758 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
759 result[s] = tags[s];
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
760 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
761 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
762
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
763 if (simplify)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
764 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
765 Json::Value simplified;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
766 SimplifyTags(simplified, result);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
767 call.GetOutput().AnswerJson(simplified);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
768 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
769 else
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
770 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
771 call.GetOutput().AnswerJson(result);
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
772 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
773 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
774
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
775
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
776
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
777 template <enum ResourceType resourceType>
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
778 static void GetModule(RestApiGetCall& call)
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
779 {
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
780 GetModuleInternal(call, resourceType, resourceType);
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
781 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
782
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
783
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
784 static void GetPatientModuleForStudy(RestApiGetCall& call)
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
785 {
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
786 GetModuleInternal(call, ResourceType_Study, ResourceType_Patient);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
787 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
788
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
789
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
790 static void Lookup(RestApiPostCall& call)
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
791 {
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
792 typedef std::list< std::pair<ResourceType, std::string> > Resources;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
793
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
794 std::string tag = call.GetPostBody();
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
795 Resources resources;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
796
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
797 OrthancRestApi::GetIndex(call).LookupIdentifier(resources, tag);
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
798
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
799 Json::Value result = Json::arrayValue;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
800
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
801 for (Resources::const_iterator it = resources.begin();
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
802 it != resources.end(); it++)
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
803 {
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
804 ResourceType type = it->first;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
805 const std::string& id = it->second;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
806
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
807 Json::Value item = Json::objectValue;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
808 item["Type"] = EnumerationToString(type);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
809 item["ID"] = id;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
810 item["Path"] = GetBasePath(type, id);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
811
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
812 result.append(item);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
813 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
814
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
815 call.GetOutput().AnswerJson(result);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
816 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
817
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
818
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
819 template <enum ResourceType start,
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
820 enum ResourceType end>
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
821 static void GetChildResources(RestApiGetCall& call)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
822 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
823 ServerIndex& index = OrthancRestApi::GetIndex(call);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
824
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
825 std::list<std::string> a, b, c;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
826 a.push_back(call.GetUriComponent("id", ""));
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
827
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
828 ResourceType type = start;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
829 while (type != end)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
830 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
831 b.clear();
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
832
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
833 for (std::list<std::string>::const_iterator
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
834 it = a.begin(); it != a.end(); it++)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
835 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
836 index.GetChildren(c, *it);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
837 b.splice(b.begin(), c);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
838 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
839
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
840 switch (type)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
841 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
842 case ResourceType_Patient:
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
843 type = ResourceType_Study;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
844 break;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
845
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
846 case ResourceType_Study:
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
847 type = ResourceType_Series;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
848 break;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
849
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
850 case ResourceType_Series:
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
851 type = ResourceType_Instance;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
852 break;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
853
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
854 default:
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
855 throw OrthancException(ErrorCode_InternalError);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
856 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
857
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
858 a.clear();
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
859 a.splice(a.begin(), b);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
860 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
861
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
862 Json::Value result = Json::arrayValue;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
863
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
864 for (std::list<std::string>::const_iterator
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
865 it = a.begin(); it != a.end(); it++)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
866 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
867 Json::Value item;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
868
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
869 if (OrthancRestApi::GetIndex(call).LookupResource(item, *it, end))
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
870 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
871 result.append(item);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
872 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
873 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
874
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
875 call.GetOutput().AnswerJson(result);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
876 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
877
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
878
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
879 static void GetChildInstancesTags(RestApiGetCall& call)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
880 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
881 ServerContext& context = OrthancRestApi::GetContext(call);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
882 std::string publicId = call.GetUriComponent("id", "");
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
883 bool simplify = call.HasArgument("simplify");
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
884
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
885 // Retrieve all the instances of this patient/study/series
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
886 typedef std::list<std::string> Instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
887 Instances instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
888
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
889 context.GetIndex().GetChildInstances(instances, publicId); // (*)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
890
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
891 Json::Value result = Json::arrayValue;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
892
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
893 for (Instances::const_iterator it = instances.begin();
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
894 it != instances.end(); it++)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
895 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
896 Json::Value full;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
897 context.ReadJson(full, *it);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
898
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
899 if (simplify)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
900 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
901 Json::Value simplified;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
902 SimplifyTags(simplified, full);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
903 result.append(simplified);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
904 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
905 else
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
906 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
907 result.append(full);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
908 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
909 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
910
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
911 call.GetOutput().AnswerJson(result);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
912 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
913
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
914
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
915
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 void OrthancRestApi::RegisterResources()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 Register("/instances", ListResources<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 Register("/patients", ListResources<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 Register("/series", ListResources<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 Register("/studies", ListResources<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 Register("/studies/{id}", GetSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 Register("/instances/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 Register("/patients/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 Register("/studies/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 Register("/series/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
937 Register("/patients/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
938 Register("/series/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
939 Register("/studies/{id}/shared-tags", GetSharedTags);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
940
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
941 Register("/instances/{id}/module", GetModule<ResourceType_Instance>);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
942 Register("/patients/{id}/module", GetModule<ResourceType_Patient>);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
943 Register("/series/{id}/module", GetModule<ResourceType_Series>);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
944 Register("/studies/{id}/module", GetModule<ResourceType_Study>);
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
945 Register("/studies/{id}/module-patient", GetPatientModuleForStudy);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
946
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 Register("/instances/{id}/file", GetInstanceFile);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 Register("/instances/{id}/export", ExportInstanceFile);
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
949 Register("/instances/{id}/tags", GetInstanceTagsBis);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 Register("/instances/{id}/frames", ListFrames);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 Register("/instances/{id}/frames/{frame}/image-int16", GetImage<ImageExtractionMode_Int16>);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
957 Register("/instances/{id}/frames/{frame}/matlab", GetMatlabImage);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 Register("/instances/{id}/preview", GetImage<ImageExtractionMode_Preview>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
962 Register("/instances/{id}/matlab", GetMatlabImage);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 Register("/patients/{id}/protected", IsProtectedPatient);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 Register("/patients/{id}/protected", SetPatientProtection);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 Register("/{resourceType}/{id}/metadata", ListMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 Register("/{resourceType}/{id}/metadata/{name}", GetMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 Register("/{resourceType}/{id}/attachments", ListAttachments);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 Register("/{resourceType}/{id}/attachments/{name}", DeleteAttachment);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 Register("/{resourceType}/{id}/attachments/{name}/size", GetAttachmentSize);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
983
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
984 Register("/tools/lookup", Lookup);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
985
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
986 Register("/patients/{id}/studies", GetChildResources<ResourceType_Patient, ResourceType_Study>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
987 Register("/patients/{id}/series", GetChildResources<ResourceType_Patient, ResourceType_Series>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
988 Register("/patients/{id}/instances", GetChildResources<ResourceType_Patient, ResourceType_Instance>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
989 Register("/studies/{id}/series", GetChildResources<ResourceType_Study, ResourceType_Series>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
990 Register("/studies/{id}/instances", GetChildResources<ResourceType_Study, ResourceType_Instance>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
991 Register("/series/{id}/instances", GetChildResources<ResourceType_Series, ResourceType_Instance>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
992
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
993 Register("/patients/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
994 Register("/studies/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
995 Register("/series/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
996
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
997 Register("/instances/{id}/content/*", GetRawContent);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 }