annotate OrthancServer/OrthancRestApi2.cpp @ 226:8a26a8e85edf

refactoring to read files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Nov 2012 09:45:29 +0100
parents 03aa59ecf6d8
children 209ca3f6db62
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>
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
44 #include <glog/logging.h>
210
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
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #define RETRIEVE_CONTEXT(call) \
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
48 OrthancRestApi2& contextApi = \
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
49 dynamic_cast<OrthancRestApi2&>(call.GetContext()); \
225
03aa59ecf6d8 fix for mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
50 ServerContext& context = contextApi.GetContext()
210
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
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 namespace Orthanc
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 // System information -------------------------------------------------------
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
56
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
57 static void ServeRoot(RestApi::GetCall& call)
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
58 {
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
59 call.GetOutput().Redirect("app/explorer.html");
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
60 }
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 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
63 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 RETRIEVE_CONTEXT(call);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Json::Value result = Json::objectValue;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 result["Version"] = ORTHANC_VERSION;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 result["Name"] = GetGlobalStringParameter("Name", "");
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 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
70 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
71 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
75 // List all the patients, studies, series or instances ----------------------
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 template <enum ResourceType resourceType>
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
78 static void ListResources(RestApi::GetCall& call)
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
79 {
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
80 RETRIEVE_CONTEXT(call);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
81
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
82 Json::Value result;
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
83 context.GetIndex().GetAllUuids(result, resourceType);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
84 call.GetOutput().AnswerJson(result);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
85 }
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
86
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
87 template <enum ResourceType resourceType>
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
88 static void GetSingleResource(RestApi::GetCall& call)
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
89 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
90 RETRIEVE_CONTEXT(call);
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 Json::Value result;
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
93 if (context.GetIndex().LookupResource(result, call.GetUriComponent("id", ""), resourceType))
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 call.GetOutput().AnswerJson(result);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
96 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
97 }
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 template <enum ResourceType resourceType>
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
100 static void DeleteSingleResource(RestApi::DeleteCall& call)
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
101 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
102 RETRIEVE_CONTEXT(call);
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 Json::Value result;
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
105 if (context.GetIndex().DeleteResource(result, call.GetUriComponent("id", ""), resourceType))
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 call.GetOutput().AnswerJson(result);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
108 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
109 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
110
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
111
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 // Changes API --------------------------------------------------------------
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 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
115 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 RETRIEVE_CONTEXT(call);
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 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
119 ServerIndex& index = context.GetIndex();
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 //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
122 int64_t since;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 unsigned int limit;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 try
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 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
127 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
128 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 catch (boost::bad_lexical_cast)
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 return;
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
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 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
135 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 limit = MAX_RESULTS;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
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 Json::Value result;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 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
141 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 call.GetOutput().AnswerJson(result);
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 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
148 // 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
149
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
150 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
151 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
152 RETRIEVE_CONTEXT(call);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
153
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
154 std::string publicId = call.GetUriComponent("id", "");
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
155 context.AnswerFile(call.GetOutput(), publicId, AttachedFileType_Dicom);
213
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
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 template <bool simplify>
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
160 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
161 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
162 RETRIEVE_CONTEXT(call);
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 std::string publicId = call.GetUriComponent("id", "");
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
165
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
166 Json::Value full;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
167 context.ReadJson(full, publicId);
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
168
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
169 if (simplify)
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
170 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
171 Json::Value simplified;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
172 SimplifyTags(simplified, full);
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
173 call.GetOutput().AnswerJson(simplified);
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
174 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
175 else
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
176 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
177 call.GetOutput().AnswerJson(full);
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
178 }
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
214
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
181
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
182 static void ListFrames(RestApi::GetCall& call)
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
183 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
184 RETRIEVE_CONTEXT(call);
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
185
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
186 Json::Value instance;
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
187 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance))
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
188 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
189 unsigned int numberOfFrames = 1;
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
190
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
191 try
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
192 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
193 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"];
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
194 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString());
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
195 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
196 catch (...)
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
197 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
198 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
199
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
200 Json::Value result = Json::arrayValue;
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
201 for (unsigned int i = 0; i < numberOfFrames; i++)
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
202 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
203 result.append(i);
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
204 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
205
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
206 call.GetOutput().AnswerJson(result);
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
207 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
208 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
209
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
210
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
211 template <enum ImageExtractionMode mode>
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
212 static void GetImage(RestApi::GetCall& call)
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
213 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
214 RETRIEVE_CONTEXT(call);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
216 CompressionType compressionType;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
217 std::string fileUuid;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
218 std::string publicId = call.GetUriComponent("id", "");
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
219 std::string frameId = call.GetUriComponent("frame", "0");
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
220
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
221 unsigned int frame;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
222 try
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
223 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
224 frame = boost::lexical_cast<unsigned int>(frameId);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
225 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
226 catch (boost::bad_lexical_cast)
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
227 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
228 return;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
229 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
230
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
231 if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Dicom))
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
232 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
233 assert(compressionType == CompressionType_None);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
234
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
235 std::string dicomContent, png;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
236 context.GetFileStorage().ReadFile(dicomContent, fileUuid);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
237
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
238 try
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
239 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
240 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, mode);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
241 call.GetOutput().AnswerBuffer(png, "image/png");
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
242 }
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
243 catch (OrthancException& e)
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
244 {
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
245 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange)
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
246 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
247 // The frame number is out of the range for this DICOM
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
248 // instance, the resource is not existent
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
249 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
250 else
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
251 {
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
252 std::string root = "";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
253 for (size_t i = 1; i < call.GetFullUri().size(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
254 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
255 root += "../";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
256 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
257
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
258 call.GetOutput().Redirect(root + "app/images/unsupported.png");
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
259 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
260 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
261 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
262 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
263
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
264
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
265 // Upload of DICOM files through HTTP ---------------------------------------
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
266
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
267 static void UploadDicomFile(RestApi::PostCall& call)
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
268 {
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
269 RETRIEVE_CONTEXT(call);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
270
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
271 const std::string& postData = call.GetPostBody();
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
272
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
273 LOG(INFO) << "Receiving a DICOM file of " << postData.size() << " bytes through HTTP";
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
274
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
275 // Prepare an input stream for the memory buffer
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
276 DcmInputBufferStream is;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
277 if (postData.size() > 0)
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
278 {
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
279 is.setBuffer(&postData[0], postData.size());
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
280 }
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
281 is.setEos();
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
282
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
283 DcmFileFormat dicomFile;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
284 if (!dicomFile.read(is).good())
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
285 {
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
286 call.GetOutput().SignalError(Orthanc_HttpStatus_415_UnsupportedMediaType);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
287 return;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
288 }
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
289
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
290 DicomMap dicomSummary;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
291 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset());
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
292
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
293 DicomInstanceHasher hasher(dicomSummary);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
294
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
295 Json::Value dicomJson;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
296 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset());
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
297
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
298 StoreStatus status = StoreStatus_Failure;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
299 if (postData.size() > 0)
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
300 {
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
301 status = context.Store
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
302 (reinterpret_cast<const char*>(&postData[0]),
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
303 postData.size(), dicomSummary, dicomJson, "");
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
304 }
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
305
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
306 Json::Value result = Json::objectValue;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
307
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
308 if (status != StoreStatus_Failure)
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
309 {
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
310 result["ID"] = hasher.HashInstance();
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
311 result["Path"] = GetBasePath(ResourceType_Instance, hasher.HashInstance());
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
312 }
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
313
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
314 result["Status"] = ToString(status);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
315 call.GetOutput().AnswerJson(result);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
316 }
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
317
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 // DICOM bridge -------------------------------------------------------------
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 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
322 {
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
323 const OrthancRestApi2::Modalities& m =
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
324 dynamic_cast<OrthancRestApi2&>(call.GetContext()).GetModalities();
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 Json::Value result = Json::arrayValue;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 for (OrthancRestApi2::Modalities::const_iterator
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
329 it = m.begin(); it != m.end(); it++)
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 result.append(*it);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
338
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
339 // 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
340
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
341 OrthancRestApi2::OrthancRestApi2(ServerContext& context) :
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
342 context_(context)
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 GetListOfDicomModalities(modalities_);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
346 Register("/", ServeRoot);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 Register("/system", GetSystemInformation);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 Register("/changes", GetChanges);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 Register("/modalities", ListModalities);
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
350
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
351 Register("/instances", UploadDicomFile);
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
352 Register("/instances", ListResources<ResourceType_Instance>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
353 Register("/patients", ListResources<ResourceType_Patient>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
354 Register("/series", ListResources<ResourceType_Series>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
355 Register("/studies", ListResources<ResourceType_Study>);
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
356
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
357 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
358 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
359 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
360 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
361 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
362 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
363 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
364 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
365
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
366 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
367 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
368 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);
214
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
369 Register("/instances/{id}/frames", ListFrames);
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
370
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
371 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
372 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
373 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
374 Register("/instances/{id}/preview", GetImage<ImageExtractionMode_Preview>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
375 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
376 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
377
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
378 // TODO : "content"
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }