Mercurial > hg > orthanc
annotate OrthancServer/Sources/QueryRetrieveHandler.cpp @ 4299:3f85db78c441
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 18:24:50 +0100 |
parents | a4f28efdfccf |
children | d9473bd5ed43 |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3370
diff
changeset
|
5 * Copyright (C) 2017-2020 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 | |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
37 #include "OrthancConfiguration.h" |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
38 |
4045 | 39 #include "../../OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.h" |
40 #include "../../OrthancFramework/Sources/Logging.h" | |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
41 #include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h" |
3096 | 42 #include "LuaScripting.h" |
43 #include "ServerContext.h" | |
1368 | 44 |
45 | |
46 namespace Orthanc | |
47 { | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
48 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
|
49 ServerContext& context, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
50 const std::string& modality) |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
51 { |
2221
e7beca979562
fix Windows build due to overwriting a macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2218
diff
changeset
|
52 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
|
53 |
2617
912a767911b0
back to a single Lua context
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
54 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
|
55 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
56 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
|
57 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
58 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
|
59 call.PushDicom(query); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
60 call.PushJson(modality); |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
61 call.ExecuteToDicom(query); |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
62 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
63 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
64 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
65 |
1368 | 66 void QueryRetrieveHandler::Invalidate() |
67 { | |
68 done_ = false; | |
69 answers_.Clear(); | |
70 } | |
71 | |
72 | |
73 void QueryRetrieveHandler::Run() | |
74 { | |
75 if (!done_) | |
76 { | |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
77 // 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
|
78 DicomMap fixed; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
79 fixed.Assign(query_); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
80 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
81 // 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
|
82 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
|
83 |
2843
4ee3a759afea
Fix: Closing DICOM associations after running query/retrieve from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2617
diff
changeset
|
84 { |
3874
2effa961f67f
forcing use of DicomAssociationParameters if creating an SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3843
diff
changeset
|
85 DicomAssociationParameters params(localAet_, modality_); |
2effa961f67f
forcing use of DicomAssociationParameters if creating an SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3843
diff
changeset
|
86 DicomControlUserConnection connection(params); |
3370
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
87 connection.Find(answers_, level_, fixed, findNormalized_); |
2843
4ee3a759afea
Fix: Closing DICOM associations after running query/retrieve from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2617
diff
changeset
|
88 } |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
89 |
1368 | 90 done_ = true; |
91 } | |
92 } | |
93 | |
94 | |
95 QueryRetrieveHandler::QueryRetrieveHandler(ServerContext& context) : | |
96 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
|
97 localAet_(context.GetDefaultLocalApplicationEntityTitle()), |
1368 | 98 done_(false), |
2059 | 99 level_(ResourceType_Study), |
3370
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
100 answers_(false), |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
101 findNormalized_(true) |
1368 | 102 { |
103 } | |
104 | |
105 | |
106 void QueryRetrieveHandler::SetModality(const std::string& symbolicName) | |
107 { | |
108 Invalidate(); | |
109 modalityName_ = symbolicName; | |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
110 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
111 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
112 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
113 lock.GetConfiguration().GetDicomModalityUsingSymbolicName(modality_, symbolicName); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
114 } |
1368 | 115 } |
116 | |
117 | |
118 void QueryRetrieveHandler::SetLevel(ResourceType level) | |
119 { | |
120 Invalidate(); | |
121 level_ = level; | |
122 } | |
123 | |
124 | |
125 void QueryRetrieveHandler::SetQuery(const DicomTag& tag, | |
126 const std::string& value) | |
127 { | |
128 Invalidate(); | |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
129 query_.SetValue(tag, value, false); |
1368 | 130 } |
131 | |
132 | |
2986
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
133 void QueryRetrieveHandler::CopyStringTag(const DicomMap& from, |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
134 const DicomTag& tag) |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
135 { |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
136 const DicomValue* value = from.TestAndGetValue(tag); |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
137 |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
138 if (value == NULL || |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
139 value->IsNull() || |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
140 value->IsBinary()) |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
141 { |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
142 throw OrthancException(ErrorCode_InexistentTag); |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
143 } |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
144 else |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
145 { |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
146 SetQuery(tag, value->GetContent()); |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
147 } |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
148 } |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
149 |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
150 |
2867 | 151 size_t QueryRetrieveHandler::GetAnswersCount() |
1368 | 152 { |
153 Run(); | |
154 return answers_.GetSize(); | |
155 } | |
156 | |
157 | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
158 void QueryRetrieveHandler::GetAnswer(DicomMap& target, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
159 size_t i) |
1368 | 160 { |
161 Run(); | |
4139
a4f28efdfccf
"maxTagLength" must be explicitly given to ParsedDicomFile::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
162 answers_.GetAnswer(i).ExtractDicomSummary(target, 0 /* don't truncate tags */); |
1368 | 163 } |
3370
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
164 |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
165 |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
166 void QueryRetrieveHandler::SetFindNormalized(bool normalized) |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
167 { |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
168 Invalidate(); |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
169 findNormalized_ = normalized; |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
170 } |
1368 | 171 } |