Mercurial > hg > orthanc
annotate OrthancServer/QueryRetrieveHandler.cpp @ 2713:301adea5cc7f jobs
integration mainline->jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Jul 2018 11:37:36 +0200 |
parents | 912a767911b0 |
children | 4ee3a759afea |
rev | line source |
---|---|
1368 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1368 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1368 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "PrecompiledHeadersServer.h" | |
35 #include "QueryRetrieveHandler.h" | |
36 | |
37 #include "OrthancInitialization.h" | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
38 |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
39 #include "../Core/DicomParsing/FromDcmtkBridge.h" |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
40 #include "../Core/Logging.h" |
1368 | 41 |
42 | |
43 namespace Orthanc | |
44 { | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
45 static void FixQueryLua(DicomMap& query, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
46 ServerContext& context, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
47 const std::string& modality) |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
48 { |
2221
e7beca979562
fix Windows build due to overwriting a macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2218
diff
changeset
|
49 static const char* LUA_CALLBACK = "OutgoingFindRequestFilter"; |
e7beca979562
fix Windows build due to overwriting a macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2218
diff
changeset
|
50 |
2617
912a767911b0
back to a single Lua context
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
51 LuaScripting::Lock lock(context.GetLuaScripting()); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
52 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
53 if (lock.GetLua().IsExistingFunction(LUA_CALLBACK)) |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
54 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
55 LuaFunctionCall call(lock.GetLua(), LUA_CALLBACK); |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
56 call.PushDicom(query); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
57 call.PushJson(modality); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
58 FromDcmtkBridge::ExecuteToDicom(query, call); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
59 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
60 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
61 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
62 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
63 static void FixQueryBuiltin(DicomMap& query, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
64 ModalityManufacturer manufacturer) |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
65 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
66 /** |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
67 * Introduce patches for specific manufacturers below. |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
68 **/ |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
69 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
70 switch (manufacturer) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
71 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
72 default: |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
73 break; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
74 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
75 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
76 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
77 |
1368 | 78 void QueryRetrieveHandler::Invalidate() |
79 { | |
80 done_ = false; | |
81 answers_.Clear(); | |
2590
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
82 connection_.reset(NULL); |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
83 } |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
84 |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
85 |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
86 DicomUserConnection& QueryRetrieveHandler::GetConnection() |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
87 { |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
88 if (connection_.get() == NULL) |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
89 { |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
90 connection_.reset(new DicomUserConnection(localAet_, modality_)); |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
91 connection_->Open(); |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
92 } |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
93 |
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
94 return *connection_; |
1368 | 95 } |
96 | |
97 | |
98 void QueryRetrieveHandler::Run() | |
99 { | |
100 if (!done_) | |
101 { | |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
102 // Firstly, fix the content of the query for specific manufacturers |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
103 DicomMap fixed; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
104 fixed.Assign(query_); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
105 FixQueryBuiltin(fixed, modality_.GetManufacturer()); |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
106 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
107 // Secondly, possibly fix the query with the user-provider Lua callback |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
108 FixQueryLua(fixed, context_, modality_.GetApplicationEntityTitle()); |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
109 |
2590
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
110 GetConnection().Find(answers_, level_, fixed); |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
111 |
1368 | 112 done_ = true; |
113 } | |
114 } | |
115 | |
116 | |
117 QueryRetrieveHandler::QueryRetrieveHandler(ServerContext& context) : | |
118 context_(context), | |
1427
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
119 localAet_(context.GetDefaultLocalApplicationEntityTitle()), |
1368 | 120 done_(false), |
2059 | 121 level_(ResourceType_Study), |
122 answers_(false) | |
1368 | 123 { |
124 } | |
125 | |
126 | |
127 void QueryRetrieveHandler::SetModality(const std::string& symbolicName) | |
128 { | |
129 Invalidate(); | |
130 modalityName_ = symbolicName; | |
131 Configuration::GetDicomModalityUsingSymbolicName(modality_, symbolicName); | |
132 } | |
133 | |
134 | |
135 void QueryRetrieveHandler::SetLevel(ResourceType level) | |
136 { | |
137 Invalidate(); | |
138 level_ = level; | |
139 } | |
140 | |
141 | |
142 void QueryRetrieveHandler::SetQuery(const DicomTag& tag, | |
143 const std::string& value) | |
144 { | |
145 Invalidate(); | |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
146 query_.SetValue(tag, value, false); |
1368 | 147 } |
148 | |
149 | |
150 size_t QueryRetrieveHandler::GetAnswerCount() | |
151 { | |
152 Run(); | |
153 return answers_.GetSize(); | |
154 } | |
155 | |
156 | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
157 void QueryRetrieveHandler::GetAnswer(DicomMap& target, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
158 size_t i) |
1368 | 159 { |
160 Run(); | |
2209
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
161 answers_.GetAnswer(i).ExtractDicomSummary(target); |
1368 | 162 } |
163 | |
164 | |
165 void QueryRetrieveHandler::Retrieve(const std::string& target, | |
166 size_t i) | |
167 { | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
168 DicomMap map; |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
169 GetAnswer(map, i); |
2590
5e2730c8e23c
getting rid of ReusableDicomConnection in QueryRetrieveHandler and OrthancMoveRequestHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
170 GetConnection().Move(target, map); |
1368 | 171 } |
172 | |
173 | |
174 void QueryRetrieveHandler::Retrieve(const std::string& target) | |
175 { | |
176 for (size_t i = 0; i < GetAnswerCount(); i++) | |
177 { | |
178 Retrieve(target, i); | |
179 } | |
180 } | |
181 } |