annotate OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 1160:80671157d051

generalization of create-dicom
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Sep 2014 11:57:28 +0200
parents 952cf9b6be83
children 0561f2087cc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../OrthancInitialization.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Core/HttpClient.h"
795
d466b3606aca refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
38 #include "../FromDcmtkBridge.h"
999
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
39 #include "../Scheduler/ServerJob.h"
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
40 #include "../Scheduler/StoreScuCommand.h"
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
41 #include "../Scheduler/StorePeerCommand.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <glog/logging.h>
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 // DICOM SCU ----------------------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 static bool MergeQueryAndTemplate(DicomMap& result,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 const std::string& postData)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 Json::Value query;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 Json::Reader reader;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (!reader.parse(postData, query) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 query.type() != Json::objectValue)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 Json::Value::Members members = query.getMemberNames();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 for (size_t i = 0; i < members.size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 DicomTag t = FromDcmtkBridge::ParseTag(members[i]);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 result.SetValue(t, query[members[i]].asString());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
1049
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
71
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
72 static void DicomEcho(RestApiPostCall& call)
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
73 {
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
74 ServerContext& context = OrthancRestApi::GetContext(call);
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
75
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
76 RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
77 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), remote);
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
78
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
79 try
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
80 {
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
81 if (locker.GetConnection().Echo())
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
82 {
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
83 call.GetOutput().AnswerBuffer("{}", "application/json");
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
84 }
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
85 }
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
86 catch (OrthancException&)
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
87 {
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
88 }
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
89 }
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
90
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
91
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
92 static void DicomFindPatient(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
94 ServerContext& context = OrthancRestApi::GetContext(call);
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
95
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 DicomMap m;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 DicomMap::SetupFindPatientTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
103 RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
104 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), remote);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 DicomFindAnswers answers;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
107 locker.GetConnection().FindPatient(answers, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 answers.ToJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
114 static void DicomFindStudy(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
116 ServerContext& context = OrthancRestApi::GetContext(call);
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
117
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 DicomMap m;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 DicomMap::SetupFindStudyTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
131 RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
132 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), remote);
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
133
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 DicomFindAnswers answers;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
135 locker.GetConnection().FindStudy(answers, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 answers.ToJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
142 static void DicomFindSeries(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
144 ServerContext& context = OrthancRestApi::GetContext(call);
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
145
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 DicomMap m;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 DicomMap::SetupFindSeriesTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
160 RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
161 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), remote);
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
162
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 DicomFindAnswers answers;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
164 locker.GetConnection().FindSeries(answers, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 answers.ToJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
171 static void DicomFindInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
173 ServerContext& context = OrthancRestApi::GetContext(call);
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
174
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 DicomMap m;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 DicomMap::SetupFindInstanceTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2 ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 m.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString().size() <= 2)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
190 RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
191 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), remote);
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
192
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 DicomFindAnswers answers;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
194 locker.GetConnection().FindInstance(answers, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 answers.ToJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
201 static void DicomFind(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
203 ServerContext& context = OrthancRestApi::GetContext(call);
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
204
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 DicomMap m;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 DicomMap::SetupFindPatientTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
212 RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
213 ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), remote);
773
3bd0589af992 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
214
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 DicomFindAnswers patients;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
216 locker.GetConnection().FindPatient(patients, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 // Loop over the found patients
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 for (size_t i = 0; i < patients.GetSize(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 Json::Value patient(Json::objectValue);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 DicomMap::SetupFindStudyTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 DicomFindAnswers studies;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
233 locker.GetConnection().FindStudy(studies, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 patient["Studies"] = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 // Loop over the found studies
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 for (size_t j = 0; j < studies.GetSize(); j++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 Json::Value study(Json::objectValue);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 DicomMap::SetupFindSeriesTemplate(m);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 DicomFindAnswers series;
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 773
diff changeset
252 locker.GetConnection().FindSeries(series, m);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 // Loop over the found series
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 study["Series"] = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 for (size_t k = 0; k < series.GetSize(); k++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 Json::Value series2(Json::objectValue);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 study["Series"].append(series2);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 patient["Studies"].append(study);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 result.append(patient);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 static bool GetInstancesToExport(std::list<std::string>& instances,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 const std::string& remote,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
275 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 std::string stripped = Toolbox::StripSpaces(call.GetPostBody());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 Json::Value request;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 if (Toolbox::IsSHA1(stripped))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 // This is for compatibility with Orthanc <= 0.5.1.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 request = stripped;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 else if (!call.ParseJsonRequest(request))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 // Bad JSON request
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (request.isString())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
1142
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
295 if (Configuration::GetGlobalBoolParameter("LogExportedResources", true))
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
296 {
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
297 context.GetIndex().LogExportedResource(request.asString(), remote);
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
298 }
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
299
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 context.GetIndex().GetChildInstances(instances, request.asString());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 else if (request.isArray())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 for (Json::Value::ArrayIndex i = 0; i < request.size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 if (!request[i].isString())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 std::string stripped = Toolbox::StripSpaces(request[i].asString());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 if (!Toolbox::IsSHA1(stripped))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
1142
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
317 if (Configuration::GetGlobalBoolParameter("LogExportedResources", true))
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
318 {
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
319 context.GetIndex().LogExportedResource(stripped, remote);
952cf9b6be83 Configuration option to disable the logging of exported resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
320 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 std::list<std::string> tmp;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 context.GetIndex().GetChildInstances(tmp, stripped);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 for (std::list<std::string>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 it = tmp.begin(); it != tmp.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 instances.push_back(*it);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 // Neither a string, nor a list of strings. Bad request.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
342 static void DicomStore(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 std::string remote = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 std::list<std::string> instances;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 if (!GetInstancesToExport(instances, remote, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
354 RemoteModalityParameters p = Configuration::GetModalityUsingSymbolicName(remote);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
999
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
356 ServerJob job;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 for (std::list<std::string>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 it = instances.begin(); it != instances.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 {
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
360 job.AddCommand(new StoreScuCommand(context, p)).AddInput(*it);
999
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
361 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
363 job.SetDescription("HTTP request: Store-SCU to peer \"" + remote + "\"");
999
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
364 context.GetScheduler().SubmitAndWait(job);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 call.GetOutput().AnswerBuffer("{}", "application/json");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 // Orthanc Peers ------------------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 static bool IsExistingPeer(const OrthancRestApi::SetOfStrings& peers,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 const std::string& id)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 return peers.find(id) != peers.end();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
378 static void ListPeers(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 OrthancRestApi::SetOfStrings peers;
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
381 Configuration::GetListOfOrthancPeers(peers);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 for (OrthancRestApi::SetOfStrings::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 it = peers.begin(); it != peers.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 result.append(*it);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
393 static void ListPeerOperations(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 OrthancRestApi::SetOfStrings peers;
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
396 Configuration::GetListOfOrthancPeers(peers);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 std::string id = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 if (IsExistingPeer(peers, id))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 {
1063
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1049
diff changeset
401 RestApi::AutoListChildren(call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
405 static void PeerStore(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 std::string remote = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 std::list<std::string> instances;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 if (!GetInstancesToExport(instances, remote, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
806
557575fd93e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
417 OrthancPeerParameters peer;
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
418 Configuration::GetOrthancPeer(peer, remote);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
420 ServerJob job;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 for (std::list<std::string>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 it = instances.begin(); it != instances.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
424 job.AddCommand(new StorePeerCommand(context, peer)).AddInput(*it);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
425 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
427 job.SetDescription("HTTP request: POST to peer \"" + remote + "\"");
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
428 context.GetScheduler().SubmitAndWait(job);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 call.GetOutput().AnswerBuffer("{}", "application/json");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 // DICOM bridge -------------------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 static bool IsExistingModality(const OrthancRestApi::SetOfStrings& modalities,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 const std::string& id)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 return modalities.find(id) != modalities.end();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
442 static void ListModalities(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 OrthancRestApi::SetOfStrings modalities;
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
445 Configuration::GetListOfDicomModalities(modalities);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 for (OrthancRestApi::SetOfStrings::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 it = modalities.begin(); it != modalities.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 result.append(*it);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
458 static void ListModalityOperations(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 OrthancRestApi::SetOfStrings modalities;
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
461 Configuration::GetListOfDicomModalities(modalities);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 std::string id = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 if (IsExistingModality(modalities, id))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 {
1063
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1049
diff changeset
466 RestApi::AutoListChildren(call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
471 static void UpdateModality(RestApiPutCall& call)
807
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
472 {
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
473 Json::Value json;
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
474 Json::Reader reader;
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
475 if (reader.parse(call.GetPutBody(), json))
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
476 {
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
477 RemoteModalityParameters modality;
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
478 modality.FromJson(json);
812
8a36c947490c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 810
diff changeset
479 Configuration::UpdateModality(call.GetUriComponent("id", ""), modality);
813
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 812
diff changeset
480 call.GetOutput().AnswerBuffer("", "text/plain");
807
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
481 }
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
482 }
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
483
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
484
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
485 static void DeleteModality(RestApiDeleteCall& call)
807
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
486 {
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
487 Configuration::RemoveModality(call.GetUriComponent("id", ""));
813
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 812
diff changeset
488 call.GetOutput().AnswerBuffer("", "text/plain");
807
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
489 }
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
490
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
491
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
492 static void UpdatePeer(RestApiPutCall& call)
808
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
493 {
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
494 Json::Value json;
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
495 Json::Reader reader;
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
496 if (reader.parse(call.GetPutBody(), json))
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
497 {
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
498 OrthancPeerParameters peer;
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
499 peer.FromJson(json);
812
8a36c947490c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 810
diff changeset
500 Configuration::UpdatePeer(call.GetUriComponent("id", ""), peer);
813
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 812
diff changeset
501 call.GetOutput().AnswerBuffer("", "text/plain");
808
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
502 }
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
503 }
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
504
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
505
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
506 static void DeletePeer(RestApiDeleteCall& call)
808
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
507 {
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 808
diff changeset
508 Configuration::RemovePeer(call.GetUriComponent("id", ""));
813
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 812
diff changeset
509 call.GetOutput().AnswerBuffer("", "text/plain");
808
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
510 }
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
511
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
512
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 void OrthancRestApi::RegisterModalities()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 Register("/modalities", ListModalities);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 Register("/modalities/{id}", ListModalityOperations);
807
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
517 Register("/modalities/{id}", UpdateModality);
566a2fb3c1fb update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 806
diff changeset
518 Register("/modalities/{id}", DeleteModality);
1049
bd2cb95003da C-Echo SCU in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
519 Register("/modalities/{id}/echo", DicomEcho);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 Register("/modalities/{id}/find-patient", DicomFindPatient);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 Register("/modalities/{id}/find-study", DicomFindStudy);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 Register("/modalities/{id}/find-series", DicomFindSeries);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 Register("/modalities/{id}/find-instance", DicomFindInstance);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 Register("/modalities/{id}/find", DicomFind);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 Register("/modalities/{id}/store", DicomStore);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 Register("/peers", ListPeers);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 Register("/peers/{id}", ListPeerOperations);
808
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
529 Register("/peers/{id}", UpdatePeer);
2d9a000aa3a6 update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 807
diff changeset
530 Register("/peers/{id}", DeletePeer);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 Register("/peers/{id}/store", PeerStore);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 }