annotate OrthancServer/OrthancRestApi2.cpp @ 213:4ce7fdcc8879

access to tags, simplified-tags and file of an instance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Nov 2012 10:59:40 +0100
parents f276b175dcaf
children 03817919169b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
96b7918a6a18 start of the refactoring of the Orthanc REST API
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
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "OrthancRestApi2.h"
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "OrthancInitialization.h"
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "FromDcmtkBridge.h"
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/Uuid.h"
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../Core/HttpServer/FilesystemHttpSender.h"
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
39 #include "ServerToolbox.h"
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <dcmtk/dcmdata/dcistrmb.h>
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <dcmtk/dcmdata/dcfilefo.h>
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <boost/lexical_cast.hpp>
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #define RETRIEVE_CONTEXT(call) \
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 OrthancRestApi2& context = dynamic_cast<OrthancRestApi2&>(call.GetContext())
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 namespace Orthanc
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 // System information -------------------------------------------------------
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
53
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
54 static void ServeRoot(RestApi::GetCall& call)
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
55 {
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
56 call.GetOutput().Redirect("app/explorer.html");
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
57 }
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 static void GetSystemInformation(RestApi::GetCall& call)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 RETRIEVE_CONTEXT(call);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 Json::Value result = Json::objectValue;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 result["Version"] = ORTHANC_VERSION;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 result["Name"] = GetGlobalStringParameter("Name", "");
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 result["TotalCompressedSize"] = boost::lexical_cast<std::string>(context.GetIndex().GetTotalCompressedSize());
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 result["TotalUncompressedSize"] = boost::lexical_cast<std::string>(context.GetIndex().GetTotalUncompressedSize());
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
72 // List all the patients, studies, series or instances ----------------------
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
73
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
74 template <enum ResourceType resourceType>
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
75 static void ListResources(RestApi::GetCall& call)
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
76 {
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
77 RETRIEVE_CONTEXT(call);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
78
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
79 Json::Value result;
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
80 context.GetIndex().GetAllUuids(result, resourceType);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
81 call.GetOutput().AnswerJson(result);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
82 }
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
83
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
84 template <enum ResourceType resourceType>
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
85 static void GetSingleResource(RestApi::GetCall& call)
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
86 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
87 RETRIEVE_CONTEXT(call);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
88
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
89 Json::Value result;
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
90 if (context.GetIndex().LookupResource(result, call.GetUriComponent("id", ""), resourceType))
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
91 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
92 call.GetOutput().AnswerJson(result);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
93 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
94 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
95
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
96 template <enum ResourceType resourceType>
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
97 static void DeleteSingleResource(RestApi::DeleteCall& call)
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
98 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
99 RETRIEVE_CONTEXT(call);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
100
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
101 Json::Value result;
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
102 if (context.GetIndex().DeleteResource(result, call.GetUriComponent("id", ""), resourceType))
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
103 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
104 call.GetOutput().AnswerJson(result);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
105 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
106 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
107
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
108
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 // Changes API --------------------------------------------------------------
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 static void GetChanges(RestApi::GetCall& call)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 RETRIEVE_CONTEXT(call);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 static const unsigned int MAX_RESULTS = 100;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ServerIndex& index = context.GetIndex();
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 //std::string filter = GetArgument(getArguments, "filter", "");
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 int64_t since;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 unsigned int limit;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 try
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 since = boost::lexical_cast<int64_t>(call.GetArgument("since", "0"));
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 limit = boost::lexical_cast<unsigned int>(call.GetArgument("limit", "0"));
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 catch (boost::bad_lexical_cast)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 return;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 if (limit == 0 || limit > MAX_RESULTS)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 limit = MAX_RESULTS;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 Json::Value result;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 if (index.GetChanges(result, since, limit))
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
145 // Get information about a single instance ----------------------------------
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
146
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
147 static void GetInstanceFile(RestApi::GetCall& call)
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
148 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
149 RETRIEVE_CONTEXT(call);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
150
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
151 CompressionType compressionType;
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
152 std::string fileUuid;
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
153 std::string publicId = call.GetUriComponent("id", "");
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
154
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
155 if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Dicom))
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
156 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
157 assert(compressionType == CompressionType_None);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
158
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
159 FilesystemHttpSender sender(context.GetFileStorage(), fileUuid);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
160 sender.SetFilename(fileUuid + ".dcm");
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
161 sender.SetContentType("application/dicom");
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
162 call.GetOutput().AnswerFile(sender);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
163 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
164 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
165
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
166
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
167 template <bool simplify>
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
168 static void GetInstanceTags(RestApi::GetCall& call)
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
169 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
170 RETRIEVE_CONTEXT(call);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
171
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
172 CompressionType compressionType;
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
173 std::string fileUuid;
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
174 std::string publicId = call.GetUriComponent("id", "");
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
175
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
176 if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Json))
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
177 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
178 assert(compressionType == CompressionType_None);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
179
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
180 Json::Value full;
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
181 ReadJson(full, context.GetFileStorage(), fileUuid);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
182
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
183 if (simplify)
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
184 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
185 Json::Value simplified;
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
186 SimplifyTags(simplified, full);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
187 call.GetOutput().AnswerJson(simplified);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
188 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
189 else
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
190 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
191 call.GetOutput().AnswerJson(full);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
192 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
193 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
194 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
195
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
196
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 // DICOM bridge -------------------------------------------------------------
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 static void ListModalities(RestApi::GetCall& call)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 RETRIEVE_CONTEXT(call);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 Json::Value result = Json::arrayValue;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 for (OrthancRestApi2::Modalities::const_iterator
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 it = context.GetModalities().begin();
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 it != context.GetModalities().end(); it++)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 result.append(*it);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
217
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
218 // Registration of the various REST handlers --------------------------------
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
219
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 OrthancRestApi2::OrthancRestApi2(ServerIndex& index,
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 const std::string& path) :
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 index_(index),
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 storage_(path)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 GetListOfDicomModalities(modalities_);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
227 Register("/", ServeRoot);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 Register("/system", GetSystemInformation);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 Register("/changes", GetChanges);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 Register("/modalities", ListModalities);
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
231
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
232 Register("/instances", ListResources<ResourceType_Instance>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
233 Register("/patients", ListResources<ResourceType_Patient>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
234 Register("/series", ListResources<ResourceType_Series>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
235 Register("/studies", ListResources<ResourceType_Study>);
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
236
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
237 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
238 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
239 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
240 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
241 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
242 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
243 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
244 Register("/studies/{id}", GetSingleResource<ResourceType_Study>);
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
245
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
246 Register("/instances/{id}/file", GetInstanceFile);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
247 Register("/instances/{id}/tags", GetInstanceTags<false>);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
248 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
249
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
250 // TODO : "content", "frames"
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }