Mercurial > hg > orthanc
annotate OrthancServer/Sources/QueryRetrieveHandler.cpp @ 5656:a3c244090f67 find-refactoring
integration mainline->find-refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Jun 2024 13:24:04 +0200 |
parents | f7adfb22e20e |
children |
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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1368 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "PrecompiledHeadersServer.h" | |
25 #include "QueryRetrieveHandler.h" | |
26 | |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
27 #include "OrthancConfiguration.h" |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
28 |
4045 | 29 #include "../../OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.h" |
30 #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
|
31 #include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h" |
3096 | 32 #include "LuaScripting.h" |
33 #include "ServerContext.h" | |
1368 | 34 |
35 | |
36 namespace Orthanc | |
37 { | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
38 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
|
39 ServerContext& context, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
40 const std::string& modality) |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
41 { |
2221
e7beca979562
fix Windows build due to overwriting a macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2218
diff
changeset
|
42 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
|
43 |
2617
912a767911b0
back to a single Lua context
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
44 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
|
45 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
46 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
|
47 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2612
diff
changeset
|
48 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
|
49 call.PushDicom(query); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
50 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
|
51 call.ExecuteToDicom(query); |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
52 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
53 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
54 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
55 |
1368 | 56 void QueryRetrieveHandler::Invalidate() |
57 { | |
58 done_ = false; | |
59 answers_.Clear(); | |
60 } | |
61 | |
62 | |
63 void QueryRetrieveHandler::Run() | |
64 { | |
65 if (!done_) | |
66 { | |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
67 // 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
|
68 DicomMap fixed; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
69 fixed.Assign(query_); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
70 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
71 // 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
|
72 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
|
73 |
2843
4ee3a759afea
Fix: Closing DICOM associations after running query/retrieve from REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2617
diff
changeset
|
74 { |
3874
2effa961f67f
forcing use of DicomAssociationParameters if creating an SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3843
diff
changeset
|
75 DicomAssociationParameters params(localAet_, modality_); |
4517
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
76 |
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
77 if (timeout_ != 0) |
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
78 { |
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
79 params.SetTimeout(timeout_); |
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
80 } |
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
81 |
3874
2effa961f67f
forcing use of DicomAssociationParameters if creating an SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3843
diff
changeset
|
82 DicomControlUserConnection connection(params); |
3370
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
83 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
|
84 } |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2209
diff
changeset
|
85 |
1368 | 86 done_ = true; |
87 } | |
88 } | |
89 | |
90 | |
91 QueryRetrieveHandler::QueryRetrieveHandler(ServerContext& context) : | |
92 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
|
93 localAet_(context.GetDefaultLocalApplicationEntityTitle()), |
1368 | 94 done_(false), |
2059 | 95 level_(ResourceType_Study), |
3370
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
96 answers_(false), |
4517
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
97 findNormalized_(true), |
c494ee5d0101
Added "Timeout" parameter everywhere in "/modalities/.../"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4462
diff
changeset
|
98 timeout_(0) |
1368 | 99 { |
100 } | |
101 | |
102 | |
103 void QueryRetrieveHandler::SetModality(const std::string& symbolicName) | |
104 { | |
105 Invalidate(); | |
106 modalityName_ = symbolicName; | |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
107 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
108 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
109 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
110 lock.GetConfiguration().GetDicomModalityUsingSymbolicName(modality_, symbolicName); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
111 } |
1368 | 112 } |
113 | |
114 | |
4462
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
115 void QueryRetrieveHandler::SetLocalAet(const std::string& localAet) |
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
116 { |
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
117 Invalidate(); |
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
118 localAet_ = localAet; |
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
119 } |
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
120 |
da460bef88f8
"/modalities/{...}/query": New string argument "LocalAet"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
121 |
1368 | 122 void QueryRetrieveHandler::SetLevel(ResourceType level) |
123 { | |
124 Invalidate(); | |
125 level_ = level; | |
126 } | |
127 | |
128 | |
129 void QueryRetrieveHandler::SetQuery(const DicomTag& tag, | |
130 const std::string& value) | |
131 { | |
132 Invalidate(); | |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
133 query_.SetValue(tag, value, false); |
1368 | 134 } |
135 | |
136 | |
2986
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
137 void QueryRetrieveHandler::CopyStringTag(const DicomMap& from, |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
138 const DicomTag& tag) |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
139 { |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
140 const DicomValue* value = from.TestAndGetValue(tag); |
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 if (value == NULL || |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
143 value->IsNull() || |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
144 value->IsBinary()) |
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 throw OrthancException(ErrorCode_InexistentTag); |
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 else |
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 SetQuery(tag, value->GetContent()); |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
151 } |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
152 } |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
153 |
b1ba0a8311b5
exploring hierarchy of C-FIND answers finished
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
154 |
2867 | 155 size_t QueryRetrieveHandler::GetAnswersCount() |
1368 | 156 { |
157 Run(); | |
158 return answers_.GetSize(); | |
159 } | |
160 | |
161 | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
162 void QueryRetrieveHandler::GetAnswer(DicomMap& target, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
163 size_t i) |
1368 | 164 { |
165 Run(); | |
4139
a4f28efdfccf
"maxTagLength" must be explicitly given to ParsedDicomFile::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
166 answers_.GetAnswer(i).ExtractDicomSummary(target, 0 /* don't truncate tags */); |
1368 | 167 } |
3370
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
168 |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
169 |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
170 void QueryRetrieveHandler::SetFindNormalized(bool normalized) |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
171 { |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
172 Invalidate(); |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
173 findNormalized_ = normalized; |
872bd3b6ec72
"/modalities/{id}/query": New argument "Normalize"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3096
diff
changeset
|
174 } |
1368 | 175 } |