Mercurial > hg > orthanc-databases
annotate Framework/Plugins/IndexBackend.cpp @ 260:793bbbe11287
IDatabaseBackend::HasRevisionsSupport()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 19 Apr 2021 16:45:15 +0200 |
parents | e184dcadf163 |
children | 34e2b93a7ac1 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "IndexBackend.h" | |
23 | |
152 | 24 #include "../../Resources/Orthanc/Databases/ISqlLookupFormatter.h" |
0 | 25 #include "../Common/BinaryStringValue.h" |
26 #include "../Common/Integer64Value.h" | |
27 #include "../Common/Utf8StringValue.h" | |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
28 #include "DatabaseBackendAdapterV2.h" |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
29 #include "DatabaseBackendAdapterV3.h" |
0 | 30 #include "GlobalProperties.h" |
31 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
32 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 33 #include <Logging.h> |
34 #include <OrthancException.h> | |
0 | 35 |
36 | |
37 namespace OrthancDatabases | |
38 { | |
39 static std::string ConvertWildcardToLike(const std::string& query) | |
40 { | |
41 std::string s = query; | |
42 | |
43 for (size_t i = 0; i < s.size(); i++) | |
44 { | |
45 if (s[i] == '*') | |
46 { | |
47 s[i] = '%'; | |
48 } | |
49 else if (s[i] == '?') | |
50 { | |
51 s[i] = '_'; | |
52 } | |
53 } | |
54 | |
65 | 55 // TODO Escape underscores and percents |
56 | |
0 | 57 return s; |
58 } | |
59 | |
60 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
61 int64_t IndexBackend::ReadInteger64(const DatabaseManager::StatementBase& statement, |
0 | 62 size_t field) |
63 { | |
64 if (statement.IsDone()) | |
65 { | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
67 } | |
68 | |
69 const IValue& value = statement.GetResultField(field); | |
70 | |
71 switch (value.GetType()) | |
72 { | |
73 case ValueType_Integer64: | |
74 return dynamic_cast<const Integer64Value&>(value).GetValue(); | |
75 | |
76 default: | |
77 //LOG(ERROR) << value.Format(); | |
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
79 } | |
80 } | |
81 | |
82 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
83 int32_t IndexBackend::ReadInteger32(const DatabaseManager::StatementBase& statement, |
0 | 84 size_t field) |
85 { | |
86 if (statement.IsDone()) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
89 } | |
90 | |
91 int64_t value = ReadInteger64(statement, field); | |
92 | |
93 if (value != static_cast<int64_t>(static_cast<int32_t>(value))) | |
94 { | |
95 LOG(ERROR) << "Integer overflow"; | |
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
97 } | |
98 else | |
99 { | |
100 return static_cast<int32_t>(value); | |
101 } | |
102 } | |
103 | |
104 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
105 std::string IndexBackend::ReadString(const DatabaseManager::StatementBase& statement, |
0 | 106 size_t field) |
107 { | |
108 const IValue& value = statement.GetResultField(field); | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
109 |
0 | 110 switch (value.GetType()) |
111 { | |
112 case ValueType_BinaryString: | |
113 return dynamic_cast<const BinaryStringValue&>(value).GetContent(); | |
114 | |
115 case ValueType_Utf8String: | |
116 return dynamic_cast<const Utf8StringValue&>(value).GetContent(); | |
117 | |
118 default: | |
119 //LOG(ERROR) << value.Format(); | |
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
121 } | |
122 } | |
123 | |
124 | |
125 template <typename T> | |
126 void IndexBackend::ReadListOfIntegers(std::list<T>& target, | |
127 DatabaseManager::CachedStatement& statement, | |
128 const Dictionary& args) | |
129 { | |
130 statement.Execute(args); | |
131 | |
132 target.clear(); | |
133 | |
134 if (!statement.IsDone()) | |
135 { | |
136 if (statement.GetResultFieldsCount() != 1) | |
137 { | |
138 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
139 } | |
140 | |
141 statement.SetResultFieldType(0, ValueType_Integer64); | |
142 | |
143 while (!statement.IsDone()) | |
144 { | |
145 target.push_back(static_cast<T>(ReadInteger64(statement, 0))); | |
146 statement.Next(); | |
147 } | |
148 } | |
149 } | |
150 | |
151 | |
152 void IndexBackend::ReadListOfStrings(std::list<std::string>& target, | |
153 DatabaseManager::CachedStatement& statement, | |
154 const Dictionary& args) | |
155 { | |
156 statement.Execute(args); | |
157 | |
158 target.clear(); | |
159 | |
160 if (!statement.IsDone()) | |
161 { | |
162 if (statement.GetResultFieldsCount() != 1) | |
163 { | |
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
165 } | |
166 | |
167 while (!statement.IsDone()) | |
168 { | |
169 target.push_back(ReadString(statement, 0)); | |
170 statement.Next(); | |
171 } | |
172 } | |
173 } | |
174 | |
175 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
176 void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
177 bool& done, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
178 DatabaseManager& manager, |
0 | 179 DatabaseManager::CachedStatement& statement, |
180 const Dictionary& args, | |
181 uint32_t maxResults) | |
182 { | |
183 statement.Execute(args); | |
184 | |
185 uint32_t count = 0; | |
186 | |
187 while (count < maxResults && | |
188 !statement.IsDone()) | |
189 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
190 output.AnswerChange( |
0 | 191 ReadInteger64(statement, 0), |
192 ReadInteger32(statement, 1), | |
193 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 3)), | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
194 GetPublicId(manager, ReadInteger64(statement, 2)), |
0 | 195 ReadString(statement, 4)); |
196 | |
197 statement.Next(); | |
198 count++; | |
199 } | |
200 | |
201 done = (count < maxResults || | |
202 statement.IsDone()); | |
203 } | |
204 | |
205 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
206 void IndexBackend::ReadExportedResourcesInternal(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
207 bool& done, |
0 | 208 DatabaseManager::CachedStatement& statement, |
209 const Dictionary& args, | |
210 uint32_t maxResults) | |
211 { | |
212 statement.Execute(args); | |
213 | |
214 uint32_t count = 0; | |
215 | |
216 while (count < maxResults && | |
217 !statement.IsDone()) | |
218 { | |
219 int64_t seq = ReadInteger64(statement, 0); | |
220 OrthancPluginResourceType resourceType = | |
221 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); | |
222 std::string publicId = ReadString(statement, 2); | |
223 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
224 output.AnswerExportedResource(seq, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
225 resourceType, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
226 publicId, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
227 ReadString(statement, 3), // modality |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
228 ReadString(statement, 8), // date |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
229 ReadString(statement, 4), // patient ID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
230 ReadString(statement, 5), // study instance UID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
231 ReadString(statement, 6), // series instance UID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
232 ReadString(statement, 7)); // sop instance UID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
233 |
0 | 234 statement.Next(); |
235 count++; | |
236 } | |
237 | |
238 done = (count < maxResults || | |
239 statement.IsDone()); | |
240 } | |
241 | |
242 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
243 void IndexBackend::ClearDeletedFiles(DatabaseManager& manager) |
0 | 244 { |
245 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
246 STATEMENT_FROM_HERE, manager, |
0 | 247 "DELETE FROM DeletedFiles"); |
248 | |
249 statement.Execute(); | |
250 } | |
251 | |
252 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
253 void IndexBackend::ClearDeletedResources(DatabaseManager& manager) |
0 | 254 { |
255 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
256 STATEMENT_FROM_HERE, manager, |
0 | 257 "DELETE FROM DeletedResources"); |
258 | |
259 statement.Execute(); | |
260 } | |
261 | |
262 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
263 void IndexBackend::SignalDeletedFiles(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
264 DatabaseManager& manager) |
0 | 265 { |
266 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
267 STATEMENT_FROM_HERE, manager, |
0 | 268 "SELECT * FROM DeletedFiles"); |
269 | |
270 statement.SetReadOnly(true); | |
271 statement.Execute(); | |
272 | |
273 while (!statement.IsDone()) | |
274 { | |
275 std::string a = ReadString(statement, 0); | |
276 std::string b = ReadString(statement, 5); | |
277 std::string c = ReadString(statement, 6); | |
278 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
279 output.SignalDeletedAttachment(a.c_str(), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
280 ReadInteger32(statement, 1), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
281 ReadInteger64(statement, 3), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
282 b.c_str(), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
283 ReadInteger32(statement, 4), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
284 ReadInteger64(statement, 2), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
285 c.c_str()); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
286 |
0 | 287 statement.Next(); |
288 } | |
289 } | |
290 | |
291 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
292 void IndexBackend::SignalDeletedResources(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
293 DatabaseManager& manager) |
0 | 294 { |
295 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
296 STATEMENT_FROM_HERE, manager, |
0 | 297 "SELECT * FROM DeletedResources"); |
298 | |
299 statement.SetReadOnly(true); | |
300 statement.Execute(); | |
301 | |
302 while (!statement.IsDone()) | |
303 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
304 output.SignalDeletedResource( |
0 | 305 ReadString(statement, 1), |
306 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0))); | |
307 | |
308 statement.Next(); | |
309 } | |
310 } | |
311 | |
312 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
313 IndexBackend::IndexBackend(OrthancPluginContext* context) : |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
314 context_(context) |
0 | 315 { |
316 } | |
317 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
318 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
319 void IndexBackend::SetOutputFactory(IDatabaseBackendOutput::IFactory* factory) |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
320 { |
232
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
321 boost::unique_lock<boost::shared_mutex> lock(outputFactoryMutex_); |
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
322 |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
323 if (factory == NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
324 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
325 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
326 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
327 else if (outputFactory_.get() != NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
328 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
330 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
331 else |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
332 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
333 outputFactory_.reset(factory); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
334 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
335 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
336 |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
337 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
338 IDatabaseBackendOutput* IndexBackend::CreateOutput() |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
339 { |
232
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
340 boost::shared_lock<boost::shared_mutex> lock(outputFactoryMutex_); |
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
341 |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
342 if (outputFactory_.get() == NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
343 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
345 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
346 else |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
347 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
348 return outputFactory_->CreateOutput(); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
349 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
350 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
351 |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
352 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
353 void IndexBackend::AddAttachment(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
354 int64_t id, |
0 | 355 const OrthancPluginAttachment& attachment) |
356 { | |
357 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
358 STATEMENT_FROM_HERE, manager, |
0 | 359 "INSERT INTO AttachedFiles VALUES(${id}, ${type}, ${uuid}, " |
360 "${compressed}, ${uncompressed}, ${compression}, ${hash}, ${hash-compressed})"); | |
361 | |
362 statement.SetParameterType("id", ValueType_Integer64); | |
363 statement.SetParameterType("type", ValueType_Integer64); | |
364 statement.SetParameterType("uuid", ValueType_Utf8String); | |
365 statement.SetParameterType("compressed", ValueType_Integer64); | |
366 statement.SetParameterType("uncompressed", ValueType_Integer64); | |
367 statement.SetParameterType("compression", ValueType_Integer64); | |
368 statement.SetParameterType("hash", ValueType_Utf8String); | |
369 statement.SetParameterType("hash-compressed", ValueType_Utf8String); | |
370 | |
371 Dictionary args; | |
372 args.SetIntegerValue("id", id); | |
373 args.SetIntegerValue("type", attachment.contentType); | |
374 args.SetUtf8Value("uuid", attachment.uuid); | |
375 args.SetIntegerValue("compressed", attachment.compressedSize); | |
376 args.SetIntegerValue("uncompressed", attachment.uncompressedSize); | |
377 args.SetIntegerValue("compression", attachment.compressionType); | |
378 args.SetUtf8Value("hash", attachment.uncompressedHash); | |
379 args.SetUtf8Value("hash-compressed", attachment.compressedHash); | |
380 | |
381 statement.Execute(args); | |
382 } | |
383 | |
384 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
385 void IndexBackend::AttachChild(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
386 int64_t parent, |
0 | 387 int64_t child) |
388 { | |
389 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
390 STATEMENT_FROM_HERE, manager, |
0 | 391 "UPDATE Resources SET parentId = ${parent} WHERE internalId = ${child}"); |
392 | |
393 statement.SetParameterType("parent", ValueType_Integer64); | |
394 statement.SetParameterType("child", ValueType_Integer64); | |
395 | |
396 Dictionary args; | |
397 args.SetIntegerValue("parent", parent); | |
398 args.SetIntegerValue("child", child); | |
399 | |
400 statement.Execute(args); | |
401 } | |
402 | |
403 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
404 void IndexBackend::ClearChanges(DatabaseManager& manager) |
0 | 405 { |
406 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
407 STATEMENT_FROM_HERE, manager, |
0 | 408 "DELETE FROM Changes"); |
409 | |
410 statement.Execute(); | |
411 } | |
412 | |
413 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
414 void IndexBackend::ClearExportedResources(DatabaseManager& manager) |
0 | 415 { |
416 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
417 STATEMENT_FROM_HERE, manager, |
0 | 418 "DELETE FROM ExportedResources"); |
419 | |
420 statement.Execute(); | |
421 } | |
422 | |
423 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
424 void IndexBackend::DeleteAttachment(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
425 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
426 int64_t id, |
0 | 427 int32_t attachment) |
428 { | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
429 ClearDeletedFiles(manager); |
0 | 430 |
431 { | |
432 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
433 STATEMENT_FROM_HERE, manager, |
0 | 434 "DELETE FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); |
435 | |
436 statement.SetParameterType("id", ValueType_Integer64); | |
437 statement.SetParameterType("type", ValueType_Integer64); | |
438 | |
439 Dictionary args; | |
440 args.SetIntegerValue("id", id); | |
441 args.SetIntegerValue("type", static_cast<int>(attachment)); | |
442 | |
443 statement.Execute(args); | |
444 } | |
445 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
446 SignalDeletedFiles(output, manager); |
0 | 447 } |
448 | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
449 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
450 void IndexBackend::DeleteMetadata(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
451 int64_t id, |
0 | 452 int32_t metadataType) |
453 { | |
454 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
455 STATEMENT_FROM_HERE, manager, |
0 | 456 "DELETE FROM Metadata WHERE id=${id} and type=${type}"); |
457 | |
458 statement.SetParameterType("id", ValueType_Integer64); | |
459 statement.SetParameterType("type", ValueType_Integer64); | |
460 | |
461 Dictionary args; | |
462 args.SetIntegerValue("id", id); | |
463 args.SetIntegerValue("type", static_cast<int>(metadataType)); | |
464 | |
465 statement.Execute(args); | |
466 } | |
467 | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
468 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
469 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
470 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
471 int64_t id) |
0 | 472 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
473 assert(manager.GetDialect() != Dialect_MySQL); |
0 | 474 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
475 ClearDeletedFiles(manager); |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
476 ClearDeletedResources(manager); |
0 | 477 |
478 { | |
479 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
480 STATEMENT_FROM_HERE, manager, |
0 | 481 "DELETE FROM RemainingAncestor"); |
482 | |
483 statement.Execute(); | |
484 } | |
485 | |
486 { | |
487 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
488 STATEMENT_FROM_HERE, manager, |
0 | 489 "DELETE FROM Resources WHERE internalId=${id}"); |
490 | |
491 statement.SetParameterType("id", ValueType_Integer64); | |
492 | |
493 Dictionary args; | |
494 args.SetIntegerValue("id", id); | |
495 | |
496 statement.Execute(args); | |
497 } | |
498 | |
499 | |
500 { | |
501 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
502 STATEMENT_FROM_HERE, manager, |
0 | 503 "SELECT * FROM RemainingAncestor"); |
504 | |
505 statement.Execute(); | |
506 | |
507 if (!statement.IsDone()) | |
508 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
509 output.SignalRemainingAncestor( |
0 | 510 ReadString(statement, 1), |
511 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0))); | |
512 | |
513 // There is at most 1 remaining ancestor | |
514 assert((statement.Next(), statement.IsDone())); | |
515 } | |
516 } | |
517 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
518 SignalDeletedFiles(output, manager); |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
519 SignalDeletedResources(output, manager); |
0 | 520 } |
521 | |
522 | |
523 void IndexBackend::GetAllInternalIds(std::list<int64_t>& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
524 DatabaseManager& manager, |
0 | 525 OrthancPluginResourceType resourceType) |
526 { | |
527 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
528 STATEMENT_FROM_HERE, manager, |
0 | 529 "SELECT internalId FROM Resources WHERE resourceType=${type}"); |
530 | |
531 statement.SetReadOnly(true); | |
532 statement.SetParameterType("type", ValueType_Integer64); | |
533 | |
534 Dictionary args; | |
535 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
536 | |
537 ReadListOfIntegers<int64_t>(target, statement, args); | |
538 } | |
539 | |
540 | |
541 void IndexBackend::GetAllPublicIds(std::list<std::string>& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
542 DatabaseManager& manager, |
0 | 543 OrthancPluginResourceType resourceType) |
544 { | |
545 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
546 STATEMENT_FROM_HERE, manager, |
0 | 547 "SELECT publicId FROM Resources WHERE resourceType=${type}"); |
548 | |
549 statement.SetReadOnly(true); | |
550 statement.SetParameterType("type", ValueType_Integer64); | |
551 | |
552 Dictionary args; | |
553 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
554 | |
555 ReadListOfStrings(target, statement, args); | |
556 } | |
557 | |
558 | |
559 void IndexBackend::GetAllPublicIds(std::list<std::string>& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
560 DatabaseManager& manager, |
0 | 561 OrthancPluginResourceType resourceType, |
562 uint64_t since, | |
563 uint64_t limit) | |
564 { | |
565 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
566 STATEMENT_FROM_HERE, manager, |
0 | 567 "SELECT publicId FROM (SELECT publicId FROM Resources " |
568 "WHERE resourceType=${type}) AS tmp " | |
569 "ORDER BY tmp.publicId LIMIT ${limit} OFFSET ${since}"); | |
570 | |
571 statement.SetReadOnly(true); | |
572 statement.SetParameterType("type", ValueType_Integer64); | |
573 statement.SetParameterType("limit", ValueType_Integer64); | |
574 statement.SetParameterType("since", ValueType_Integer64); | |
575 | |
576 Dictionary args; | |
577 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
578 args.SetIntegerValue("limit", limit); | |
579 args.SetIntegerValue("since", since); | |
580 | |
581 ReadListOfStrings(target, statement, args); | |
582 } | |
583 | |
584 | |
585 /* Use GetOutput().AnswerChange() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
586 void IndexBackend::GetChanges(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
587 bool& done /*out*/, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
588 DatabaseManager& manager, |
0 | 589 int64_t since, |
590 uint32_t maxResults) | |
591 { | |
592 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
593 STATEMENT_FROM_HERE, manager, |
0 | 594 "SELECT * FROM Changes WHERE seq>${since} ORDER BY seq LIMIT ${limit}"); |
595 | |
596 statement.SetReadOnly(true); | |
597 statement.SetParameterType("limit", ValueType_Integer64); | |
598 statement.SetParameterType("since", ValueType_Integer64); | |
599 | |
600 Dictionary args; | |
601 args.SetIntegerValue("limit", maxResults + 1); | |
602 args.SetIntegerValue("since", since); | |
603 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
604 ReadChangesInternal(output, done, manager, statement, args, maxResults); |
0 | 605 } |
606 | |
607 | |
608 void IndexBackend::GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
609 DatabaseManager& manager, |
0 | 610 int64_t id) |
611 { | |
612 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
613 STATEMENT_FROM_HERE, manager, |
0 | 614 "SELECT a.internalId FROM Resources AS a, Resources AS b " |
615 "WHERE a.parentId = b.internalId AND b.internalId = ${id}"); | |
616 | |
617 statement.SetReadOnly(true); | |
618 statement.SetParameterType("id", ValueType_Integer64); | |
619 | |
620 Dictionary args; | |
621 args.SetIntegerValue("id", id); | |
622 | |
623 ReadListOfIntegers<int64_t>(target, statement, args); | |
624 } | |
625 | |
626 | |
627 void IndexBackend::GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
628 DatabaseManager& manager, |
0 | 629 int64_t id) |
630 { | |
631 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
632 STATEMENT_FROM_HERE, manager, |
0 | 633 "SELECT a.publicId FROM Resources AS a, Resources AS b " |
634 "WHERE a.parentId = b.internalId AND b.internalId = ${id}"); | |
635 | |
636 statement.SetReadOnly(true); | |
637 statement.SetParameterType("id", ValueType_Integer64); | |
638 | |
639 Dictionary args; | |
640 args.SetIntegerValue("id", id); | |
641 | |
642 ReadListOfStrings(target, statement, args); | |
643 } | |
644 | |
645 | |
646 /* Use GetOutput().AnswerExportedResource() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
647 void IndexBackend::GetExportedResources(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
648 bool& done /*out*/, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
649 DatabaseManager& manager, |
0 | 650 int64_t since, |
651 uint32_t maxResults) | |
652 { | |
653 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
654 STATEMENT_FROM_HERE, manager, |
0 | 655 "SELECT * FROM ExportedResources WHERE seq>${since} ORDER BY seq LIMIT ${limit}"); |
656 | |
657 statement.SetReadOnly(true); | |
658 statement.SetParameterType("limit", ValueType_Integer64); | |
659 statement.SetParameterType("since", ValueType_Integer64); | |
660 | |
661 Dictionary args; | |
662 args.SetIntegerValue("limit", maxResults + 1); | |
663 args.SetIntegerValue("since", since); | |
664 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
665 ReadExportedResourcesInternal(output, done, statement, args, maxResults); |
0 | 666 } |
667 | |
668 | |
669 /* Use GetOutput().AnswerChange() */ | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
670 void IndexBackend::GetLastChange(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
671 DatabaseManager& manager) |
0 | 672 { |
673 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
674 STATEMENT_FROM_HERE, manager, |
0 | 675 "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1"); |
676 | |
677 statement.SetReadOnly(true); | |
678 | |
679 Dictionary args; | |
680 | |
681 bool done; // Ignored | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
682 ReadChangesInternal(output, done, manager, statement, args, 1); |
0 | 683 } |
684 | |
685 | |
686 /* Use GetOutput().AnswerExportedResource() */ | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
687 void IndexBackend::GetLastExportedResource(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
688 DatabaseManager& manager) |
0 | 689 { |
690 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
691 STATEMENT_FROM_HERE, manager, |
0 | 692 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); |
693 | |
694 statement.SetReadOnly(true); | |
695 | |
696 Dictionary args; | |
697 | |
698 bool done; // Ignored | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
699 ReadExportedResourcesInternal(output, done, statement, args, 1); |
0 | 700 } |
701 | |
702 | |
703 /* Use GetOutput().AnswerDicomTag() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
704 void IndexBackend::GetMainDicomTags(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
705 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
706 int64_t id) |
0 | 707 { |
708 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
709 STATEMENT_FROM_HERE, manager, |
0 | 710 "SELECT * FROM MainDicomTags WHERE id=${id}"); |
711 | |
712 statement.SetReadOnly(true); | |
713 statement.SetParameterType("id", ValueType_Integer64); | |
714 | |
715 Dictionary args; | |
716 args.SetIntegerValue("id", id); | |
717 | |
718 statement.Execute(args); | |
719 | |
720 while (!statement.IsDone()) | |
721 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
722 output.AnswerDicomTag(static_cast<uint16_t>(ReadInteger64(statement, 1)), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
723 static_cast<uint16_t>(ReadInteger64(statement, 2)), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
724 ReadString(statement, 3)); |
0 | 725 statement.Next(); |
726 } | |
727 } | |
728 | |
729 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
730 std::string IndexBackend::GetPublicId(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
731 int64_t resourceId) |
0 | 732 { |
733 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
734 STATEMENT_FROM_HERE, manager, |
0 | 735 "SELECT publicId FROM Resources WHERE internalId=${id}"); |
736 | |
737 statement.SetReadOnly(true); | |
738 statement.SetParameterType("id", ValueType_Integer64); | |
739 | |
740 Dictionary args; | |
741 args.SetIntegerValue("id", resourceId); | |
742 | |
743 statement.Execute(args); | |
744 | |
745 if (statement.IsDone()) | |
746 { | |
747 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
748 } | |
749 else | |
750 { | |
751 return ReadString(statement, 0); | |
752 } | |
753 } | |
754 | |
755 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
756 uint64_t IndexBackend::GetResourcesCount(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
757 OrthancPluginResourceType resourceType) |
0 | 758 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
759 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 760 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
761 switch (manager.GetDialect()) |
0 | 762 { |
763 case Dialect_MySQL: | |
764 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
765 STATEMENT_FROM_HERE, manager, |
0 | 766 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources WHERE resourceType=${type}")); |
767 break; | |
768 | |
769 case Dialect_PostgreSQL: | |
770 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
771 STATEMENT_FROM_HERE, manager, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
772 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources WHERE resourceType=${type}")); |
0 | 773 break; |
774 | |
775 case Dialect_SQLite: | |
776 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
777 STATEMENT_FROM_HERE, manager, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
778 "SELECT COUNT(*) FROM Resources WHERE resourceType=${type}")); |
0 | 779 break; |
780 | |
781 default: | |
782 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
783 } | |
784 | |
785 statement->SetReadOnly(true); | |
786 statement->SetParameterType("type", ValueType_Integer64); | |
787 | |
788 Dictionary args; | |
789 args.SetIntegerValue("type", resourceType); | |
790 | |
791 statement->Execute(args); | |
792 | |
793 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
794 } | |
795 | |
796 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
797 OrthancPluginResourceType IndexBackend::GetResourceType(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
798 int64_t resourceId) |
0 | 799 { |
800 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
801 STATEMENT_FROM_HERE, manager, |
0 | 802 "SELECT resourceType FROM Resources WHERE internalId=${id}"); |
803 | |
804 statement.SetReadOnly(true); | |
805 statement.SetParameterType("id", ValueType_Integer64); | |
806 | |
807 Dictionary args; | |
808 args.SetIntegerValue("id", resourceId); | |
809 | |
810 statement.Execute(args); | |
811 | |
812 if (statement.IsDone()) | |
813 { | |
814 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
815 } | |
816 else | |
817 { | |
818 return static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0)); | |
819 } | |
820 } | |
821 | |
822 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
823 uint64_t IndexBackend::GetTotalCompressedSize(DatabaseManager& manager) |
0 | 824 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
825 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 826 |
827 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty | |
828 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
829 switch (manager.GetDialect()) |
0 | 830 { |
831 case Dialect_MySQL: | |
832 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
833 STATEMENT_FROM_HERE, manager, |
0 | 834 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles")); |
835 break; | |
836 | |
837 case Dialect_PostgreSQL: | |
838 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
839 STATEMENT_FROM_HERE, manager, |
0 | 840 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS BIGINT) FROM AttachedFiles")); |
841 break; | |
842 | |
843 case Dialect_SQLite: | |
844 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
845 STATEMENT_FROM_HERE, manager, |
0 | 846 "SELECT COALESCE(SUM(compressedSize), 0) FROM AttachedFiles")); |
847 break; | |
848 | |
849 default: | |
850 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
851 } | |
852 | |
853 statement->SetReadOnly(true); | |
854 statement->Execute(); | |
855 | |
856 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
857 } | |
858 | |
859 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
860 uint64_t IndexBackend::GetTotalUncompressedSize(DatabaseManager& manager) |
0 | 861 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
862 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 863 |
864 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty | |
865 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
866 switch (manager.GetDialect()) |
0 | 867 { |
868 case Dialect_MySQL: | |
869 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
870 STATEMENT_FROM_HERE, manager, |
0 | 871 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles")); |
872 break; | |
873 | |
874 case Dialect_PostgreSQL: | |
875 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
876 STATEMENT_FROM_HERE, manager, |
0 | 877 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS BIGINT) FROM AttachedFiles")); |
878 break; | |
879 | |
880 case Dialect_SQLite: | |
881 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
882 STATEMENT_FROM_HERE, manager, |
0 | 883 "SELECT COALESCE(SUM(uncompressedSize), 0) FROM AttachedFiles")); |
884 break; | |
885 | |
886 default: | |
887 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
888 } | |
889 | |
890 statement->SetReadOnly(true); | |
891 statement->Execute(); | |
892 | |
893 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
894 } | |
895 | |
896 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
897 bool IndexBackend::IsExistingResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
898 int64_t internalId) |
0 | 899 { |
900 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
901 STATEMENT_FROM_HERE, manager, |
0 | 902 "SELECT * FROM Resources WHERE internalId=${id}"); |
903 | |
904 statement.SetReadOnly(true); | |
905 statement.SetParameterType("id", ValueType_Integer64); | |
906 | |
907 Dictionary args; | |
908 args.SetIntegerValue("id", internalId); | |
909 | |
910 statement.Execute(args); | |
911 | |
912 return !statement.IsDone(); | |
913 } | |
914 | |
915 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
916 bool IndexBackend::IsProtectedPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
917 int64_t internalId) |
0 | 918 { |
919 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
920 STATEMENT_FROM_HERE, manager, |
0 | 921 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ${id}"); |
922 | |
923 statement.SetReadOnly(true); | |
924 statement.SetParameterType("id", ValueType_Integer64); | |
925 | |
926 Dictionary args; | |
927 args.SetIntegerValue("id", internalId); | |
928 | |
929 statement.Execute(args); | |
930 | |
931 return statement.IsDone(); | |
932 } | |
933 | |
934 | |
935 void IndexBackend::ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
936 DatabaseManager& manager, |
0 | 937 int64_t id) |
938 { | |
939 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
940 STATEMENT_FROM_HERE, manager, |
0 | 941 "SELECT type FROM Metadata WHERE id=${id}"); |
942 | |
943 statement.SetReadOnly(true); | |
944 statement.SetParameterType("id", ValueType_Integer64); | |
945 | |
946 Dictionary args; | |
947 args.SetIntegerValue("id", id); | |
948 | |
949 ReadListOfIntegers<int32_t>(target, statement, args); | |
950 } | |
951 | |
952 | |
953 void IndexBackend::ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
954 DatabaseManager& manager, |
0 | 955 int64_t id) |
956 { | |
957 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
958 STATEMENT_FROM_HERE, manager, |
0 | 959 "SELECT fileType FROM AttachedFiles WHERE id=${id}"); |
960 | |
961 statement.SetReadOnly(true); | |
962 statement.SetParameterType("id", ValueType_Integer64); | |
963 | |
964 Dictionary args; | |
965 args.SetIntegerValue("id", id); | |
966 | |
967 ReadListOfIntegers<int32_t>(target, statement, args); | |
968 } | |
969 | |
970 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
971 void IndexBackend::LogChange(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
972 int32_t changeType, |
209 | 973 int64_t resourceId, |
974 OrthancPluginResourceType resourceType, | |
975 const char* date) | |
0 | 976 { |
977 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
978 STATEMENT_FROM_HERE, manager, |
0 | 979 "INSERT INTO Changes VALUES(${}, ${changeType}, ${id}, ${resourceType}, ${date})"); |
980 | |
981 statement.SetParameterType("changeType", ValueType_Integer64); | |
982 statement.SetParameterType("id", ValueType_Integer64); | |
983 statement.SetParameterType("resourceType", ValueType_Integer64); | |
984 statement.SetParameterType("date", ValueType_Utf8String); | |
985 | |
986 Dictionary args; | |
209 | 987 args.SetIntegerValue("changeType", changeType); |
988 args.SetIntegerValue("id", resourceId); | |
989 args.SetIntegerValue("resourceType", resourceType); | |
990 args.SetUtf8Value("date", date); | |
0 | 991 |
992 statement.Execute(args); | |
993 } | |
994 | |
995 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
996 void IndexBackend::LogExportedResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
997 const OrthancPluginExportedResource& resource) |
0 | 998 { |
999 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1000 STATEMENT_FROM_HERE, manager, |
0 | 1001 "INSERT INTO ExportedResources VALUES(${}, ${type}, ${publicId}, " |
1002 "${modality}, ${patient}, ${study}, ${series}, ${instance}, ${date})"); | |
1003 | |
1004 statement.SetParameterType("type", ValueType_Integer64); | |
1005 statement.SetParameterType("publicId", ValueType_Utf8String); | |
1006 statement.SetParameterType("modality", ValueType_Utf8String); | |
1007 statement.SetParameterType("patient", ValueType_Utf8String); | |
1008 statement.SetParameterType("study", ValueType_Utf8String); | |
1009 statement.SetParameterType("series", ValueType_Utf8String); | |
1010 statement.SetParameterType("instance", ValueType_Utf8String); | |
1011 statement.SetParameterType("date", ValueType_Utf8String); | |
1012 | |
1013 Dictionary args; | |
1014 args.SetIntegerValue("type", resource.resourceType); | |
1015 args.SetUtf8Value("publicId", resource.publicId); | |
1016 args.SetUtf8Value("modality", resource.modality); | |
1017 args.SetUtf8Value("patient", resource.patientId); | |
1018 args.SetUtf8Value("study", resource.studyInstanceUid); | |
1019 args.SetUtf8Value("series", resource.seriesInstanceUid); | |
1020 args.SetUtf8Value("instance", resource.sopInstanceUid); | |
1021 args.SetUtf8Value("date", resource.date); | |
1022 | |
1023 statement.Execute(args); | |
1024 } | |
1025 | |
1026 | |
1027 /* Use GetOutput().AnswerAttachment() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
1028 bool IndexBackend::LookupAttachment(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1029 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1030 int64_t id, |
0 | 1031 int32_t contentType) |
1032 { | |
1033 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1034 STATEMENT_FROM_HERE, manager, |
0 | 1035 "SELECT uuid, uncompressedSize, compressionType, compressedSize, " |
1036 "uncompressedHash, compressedHash FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); | |
1037 | |
1038 statement.SetReadOnly(true); | |
1039 statement.SetParameterType("id", ValueType_Integer64); | |
1040 statement.SetParameterType("type", ValueType_Integer64); | |
1041 | |
1042 Dictionary args; | |
1043 args.SetIntegerValue("id", id); | |
1044 args.SetIntegerValue("type", static_cast<int>(contentType)); | |
1045 | |
1046 statement.Execute(args); | |
1047 | |
1048 if (statement.IsDone()) | |
1049 { | |
1050 return false; | |
1051 } | |
1052 else | |
1053 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1054 output.AnswerAttachment(ReadString(statement, 0), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1055 contentType, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1056 ReadInteger64(statement, 1), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1057 ReadString(statement, 4), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1058 ReadInteger32(statement, 2), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1059 ReadInteger64(statement, 3), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1060 ReadString(statement, 5)); |
0 | 1061 return true; |
1062 } | |
1063 } | |
1064 | |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1065 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1066 static bool ReadGlobalProperty(std::string& target, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1067 DatabaseManager::CachedStatement& statement, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1068 const Dictionary& args) |
0 | 1069 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1070 statement.Execute(args); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1071 statement.SetResultFieldType(0, ValueType_Utf8String); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1072 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1073 if (statement.IsDone()) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1074 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1075 return false; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1076 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1077 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1078 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1079 ValueType type = statement.GetResultField(0).GetType(); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1080 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1081 if (type == ValueType_Null) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1082 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1083 return false; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1084 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1085 else if (type != ValueType_Utf8String) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1086 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1087 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1088 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1089 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1090 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1091 target = dynamic_cast<const Utf8StringValue&>(statement.GetResultField(0)).GetContent(); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1092 return true; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1093 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1094 } |
0 | 1095 } |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1096 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1097 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1098 bool IndexBackend::LookupGlobalProperty(std::string& target /*out*/, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1099 DatabaseManager& manager, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1100 const char* serverIdentifier, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1101 int32_t property) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1102 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1103 if (serverIdentifier == NULL) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1104 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1105 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1106 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1107 else |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1108 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1109 if (strlen(serverIdentifier) == 0) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1110 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1111 DatabaseManager::CachedStatement statement( |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1112 STATEMENT_FROM_HERE, manager, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1113 "SELECT value FROM GlobalProperties WHERE property=${property}"); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1114 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1115 statement.SetReadOnly(true); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1116 statement.SetParameterType("property", ValueType_Integer64); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1117 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1118 Dictionary args; |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1119 args.SetIntegerValue("property", property); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1120 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1121 return ReadGlobalProperty(target, statement, args); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1122 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1123 else |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1124 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1125 DatabaseManager::CachedStatement statement( |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1126 STATEMENT_FROM_HERE, manager, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1127 "SELECT value FROM ServerProperties WHERE server=${server} AND property=${property}"); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1128 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1129 statement.SetReadOnly(true); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1130 statement.SetParameterType("server", ValueType_Utf8String); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1131 statement.SetParameterType("property", ValueType_Integer64); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1132 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1133 Dictionary args; |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1134 args.SetUtf8Value("server", serverIdentifier); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1135 args.SetIntegerValue("property", property); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1136 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1137 return ReadGlobalProperty(target, statement, args); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1138 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1139 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1140 } |
0 | 1141 |
1142 | |
1143 void IndexBackend::LookupIdentifier(std::list<int64_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1144 DatabaseManager& manager, |
0 | 1145 OrthancPluginResourceType resourceType, |
1146 uint16_t group, | |
1147 uint16_t element, | |
1148 OrthancPluginIdentifierConstraint constraint, | |
1149 const char* value) | |
1150 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1151 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1152 |
1153 std::string header = | |
1154 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " | |
1155 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} " | |
1156 "AND d.tagElement=${element} AND "; | |
1157 | |
1158 switch (constraint) | |
1159 { | |
1160 case OrthancPluginIdentifierConstraint_Equal: | |
1161 header += "d.value = ${value}"; | |
1162 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1163 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1164 break; |
1165 | |
1166 case OrthancPluginIdentifierConstraint_SmallerOrEqual: | |
1167 header += "d.value <= ${value}"; | |
1168 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1169 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1170 break; |
1171 | |
1172 case OrthancPluginIdentifierConstraint_GreaterOrEqual: | |
1173 header += "d.value >= ${value}"; | |
1174 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1175 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1176 break; |
1177 | |
1178 case OrthancPluginIdentifierConstraint_Wildcard: | |
1179 header += "d.value LIKE ${value}"; | |
1180 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1181 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1182 break; |
1183 | |
1184 default: | |
1185 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
1186 } | |
1187 | |
1188 statement->SetReadOnly(true); | |
1189 statement->SetParameterType("type", ValueType_Integer64); | |
1190 statement->SetParameterType("group", ValueType_Integer64); | |
1191 statement->SetParameterType("element", ValueType_Integer64); | |
1192 statement->SetParameterType("value", ValueType_Utf8String); | |
1193 | |
1194 Dictionary args; | |
1195 args.SetIntegerValue("type", resourceType); | |
1196 args.SetIntegerValue("group", group); | |
1197 args.SetIntegerValue("element", element); | |
1198 | |
1199 if (constraint == OrthancPluginIdentifierConstraint_Wildcard) | |
1200 { | |
1201 args.SetUtf8Value("value", ConvertWildcardToLike(value)); | |
1202 } | |
1203 else | |
1204 { | |
1205 args.SetUtf8Value("value", value); | |
1206 } | |
1207 | |
1208 statement->Execute(args); | |
1209 | |
1210 target.clear(); | |
1211 while (!statement->IsDone()) | |
1212 { | |
1213 target.push_back(ReadInteger64(*statement, 0)); | |
1214 statement->Next(); | |
1215 } | |
1216 } | |
1217 | |
1218 | |
1219 void IndexBackend::LookupIdentifierRange(std::list<int64_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1220 DatabaseManager& manager, |
0 | 1221 OrthancPluginResourceType resourceType, |
1222 uint16_t group, | |
1223 uint16_t element, | |
1224 const char* start, | |
1225 const char* end) | |
1226 { | |
1227 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1228 STATEMENT_FROM_HERE, manager, |
0 | 1229 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " |
1230 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} " | |
1231 "AND d.tagElement=${element} AND d.value>=${start} AND d.value<=${end}"); | |
1232 | |
1233 statement.SetReadOnly(true); | |
1234 statement.SetParameterType("type", ValueType_Integer64); | |
1235 statement.SetParameterType("group", ValueType_Integer64); | |
1236 statement.SetParameterType("element", ValueType_Integer64); | |
1237 statement.SetParameterType("start", ValueType_Utf8String); | |
1238 statement.SetParameterType("end", ValueType_Utf8String); | |
1239 | |
1240 Dictionary args; | |
1241 args.SetIntegerValue("type", resourceType); | |
1242 args.SetIntegerValue("group", group); | |
1243 args.SetIntegerValue("element", element); | |
1244 args.SetUtf8Value("start", start); | |
1245 args.SetUtf8Value("end", end); | |
1246 | |
1247 statement.Execute(args); | |
1248 | |
1249 target.clear(); | |
1250 while (!statement.IsDone()) | |
1251 { | |
1252 target.push_back(ReadInteger64(statement, 0)); | |
1253 statement.Next(); | |
1254 } | |
1255 } | |
1256 | |
1257 | |
1258 bool IndexBackend::LookupMetadata(std::string& target /*out*/, | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1259 int64_t& revision /*out*/, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1260 DatabaseManager& manager, |
0 | 1261 int64_t id, |
1262 int32_t metadataType) | |
1263 { | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1264 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1265 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1266 switch (manager.GetDialect()) |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1267 { |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1268 case Dialect_MySQL: |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1269 case Dialect_PostgreSQL: |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1270 statement.reset(new DatabaseManager::CachedStatement( |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1271 STATEMENT_FROM_HERE, manager, |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1272 "SELECT value FROM Metadata WHERE id=${id} and type=${type}")); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1273 break; |
0 | 1274 |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1275 case Dialect_SQLite: |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1276 statement.reset(new DatabaseManager::CachedStatement( |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1277 STATEMENT_FROM_HERE, manager, |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1278 "SELECT value, revision FROM Metadata WHERE id=${id} and type=${type}")); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1279 break; |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1280 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1281 default: |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1282 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1283 } |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1284 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1285 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1286 statement->SetReadOnly(true); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1287 statement->SetParameterType("id", ValueType_Integer64); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1288 statement->SetParameterType("type", ValueType_Integer64); |
0 | 1289 |
1290 Dictionary args; | |
1291 args.SetIntegerValue("id", id); | |
1292 args.SetIntegerValue("type", metadataType); | |
1293 | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1294 statement->Execute(args); |
0 | 1295 |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1296 if (statement->IsDone()) |
0 | 1297 { |
1298 return false; | |
1299 } | |
1300 else | |
1301 { | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1302 target = ReadString(*statement, 0); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1303 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1304 if (manager.GetDialect() == Dialect_SQLite) |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1305 { |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1306 revision = ReadInteger64(*statement, 1); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1307 } |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1308 else |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1309 { |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1310 revision = 0; // TODO - REVISIONS |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1311 } |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1312 |
0 | 1313 return true; |
1314 } | |
1315 } | |
1316 | |
1317 | |
1318 bool IndexBackend::LookupParent(int64_t& parentId /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1319 DatabaseManager& manager, |
0 | 1320 int64_t resourceId) |
1321 { | |
1322 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1323 STATEMENT_FROM_HERE, manager, |
0 | 1324 "SELECT parentId FROM Resources WHERE internalId=${id}"); |
1325 | |
1326 statement.SetReadOnly(true); | |
1327 statement.SetParameterType("id", ValueType_Integer64); | |
1328 | |
1329 Dictionary args; | |
1330 args.SetIntegerValue("id", resourceId); | |
1331 | |
1332 statement.Execute(args); | |
1333 | |
1334 if (statement.IsDone() || | |
1335 statement.GetResultField(0).GetType() == ValueType_Null) | |
1336 { | |
1337 return false; | |
1338 } | |
1339 else | |
1340 { | |
1341 parentId = ReadInteger64(statement, 0); | |
1342 return true; | |
1343 } | |
1344 } | |
1345 | |
1346 | |
1347 bool IndexBackend::LookupResource(int64_t& id /*out*/, | |
1348 OrthancPluginResourceType& type /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1349 DatabaseManager& manager, |
0 | 1350 const char* publicId) |
1351 { | |
1352 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1353 STATEMENT_FROM_HERE, manager, |
0 | 1354 "SELECT internalId, resourceType FROM Resources WHERE publicId=${id}"); |
1355 | |
1356 statement.SetReadOnly(true); | |
1357 statement.SetParameterType("id", ValueType_Utf8String); | |
1358 | |
1359 Dictionary args; | |
1360 args.SetUtf8Value("id", publicId); | |
1361 | |
1362 statement.Execute(args); | |
1363 | |
1364 if (statement.IsDone()) | |
1365 { | |
1366 return false; | |
1367 } | |
1368 else | |
1369 { | |
1370 id = ReadInteger64(statement, 0); | |
1371 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); | |
1372 return true; | |
1373 } | |
1374 } | |
1375 | |
1376 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1377 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1378 DatabaseManager& manager) |
0 | 1379 { |
1380 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1381 STATEMENT_FROM_HERE, manager, |
0 | 1382 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1"); |
1383 | |
1384 statement.SetReadOnly(true); | |
1385 statement.Execute(); | |
1386 | |
1387 if (statement.IsDone()) | |
1388 { | |
1389 return false; | |
1390 } | |
1391 else | |
1392 { | |
1393 internalId = ReadInteger64(statement, 0); | |
1394 return true; | |
1395 } | |
1396 } | |
1397 | |
1398 | |
1399 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1400 DatabaseManager& manager, |
0 | 1401 int64_t patientIdToAvoid) |
1402 { | |
1403 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1404 STATEMENT_FROM_HERE, manager, |
0 | 1405 "SELECT patientId FROM PatientRecyclingOrder " |
1406 "WHERE patientId != ${id} ORDER BY seq ASC LIMIT 1"); | |
1407 | |
1408 statement.SetReadOnly(true); | |
1409 statement.SetParameterType("id", ValueType_Integer64); | |
1410 | |
1411 Dictionary args; | |
1412 args.SetIntegerValue("id", patientIdToAvoid); | |
1413 | |
1414 statement.Execute(args); | |
1415 | |
1416 if (statement.IsDone()) | |
1417 { | |
1418 return false; | |
1419 } | |
1420 else | |
1421 { | |
1422 internalId = ReadInteger64(statement, 0); | |
1423 return true; | |
1424 } | |
1425 } | |
1426 | |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1427 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1428 static void RunSetGlobalPropertyStatement(DatabaseManager::CachedStatement& statement, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1429 bool hasServer, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1430 bool hasValue, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1431 const char* serverIdentifier, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1432 int32_t property, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1433 const char* utf8) |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1434 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1435 Dictionary args; |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1436 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1437 statement.SetParameterType("property", ValueType_Integer64); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1438 args.SetIntegerValue("property", static_cast<int>(property)); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1439 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1440 if (hasValue) |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1441 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1442 assert(utf8 != NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1443 statement.SetParameterType("value", ValueType_Utf8String); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1444 args.SetUtf8Value("value", utf8); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1445 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1446 else |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1447 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1448 assert(utf8 == NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1449 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1450 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1451 if (hasServer) |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1452 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1453 assert(serverIdentifier != NULL && strlen(serverIdentifier) > 0); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1454 statement.SetParameterType("server", ValueType_Utf8String); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1455 args.SetUtf8Value("server", serverIdentifier); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1456 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1457 else |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1458 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1459 assert(serverIdentifier == NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1460 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1461 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1462 statement.Execute(args); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1463 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1464 |
0 | 1465 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1466 void IndexBackend::SetGlobalProperty(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1467 const char* serverIdentifier, |
221
73cc85f3d9c1
implementation of the "serverIdentifier" information for global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
220
diff
changeset
|
1468 int32_t property, |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1469 const char* utf8) |
0 | 1470 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1471 if (serverIdentifier == NULL) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1472 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1473 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1474 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1475 else if (manager.GetDialect() == Dialect_SQLite) |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1476 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1477 bool hasServer = (strlen(serverIdentifier) != 0); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1478 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1479 if (hasServer) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1480 { |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1481 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1482 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1483 "INSERT OR REPLACE INTO ServerProperties VALUES (${server}, ${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1484 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1485 RunSetGlobalPropertyStatement(statement, true, true, serverIdentifier, property, utf8); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1486 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1487 else |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1488 { |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1489 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1490 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1491 "INSERT OR REPLACE INTO GlobalProperties VALUES (${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1492 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1493 RunSetGlobalPropertyStatement(statement, false, true, NULL, property, utf8); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1494 } |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1495 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1496 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1497 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1498 bool hasServer = (strlen(serverIdentifier) != 0); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1499 |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1500 if (hasServer) |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1501 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1502 { |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1503 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1504 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1505 "DELETE FROM ServerProperties WHERE server=${server} AND property=${property}"); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1506 |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1507 RunSetGlobalPropertyStatement(statement, true, false, serverIdentifier, property, NULL); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1508 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1509 |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1510 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1511 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1512 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1513 "INSERT INTO ServerProperties VALUES (${server}, ${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1514 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1515 RunSetGlobalPropertyStatement(statement, true, true, serverIdentifier, property, utf8); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1516 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1517 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1518 else |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1519 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1520 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1521 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1522 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1523 "DELETE FROM GlobalProperties WHERE property=${property}"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1524 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1525 RunSetGlobalPropertyStatement(statement, false, false, NULL, property, NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1526 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1527 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1528 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1529 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1530 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1531 "INSERT INTO GlobalProperties VALUES (${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1532 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1533 RunSetGlobalPropertyStatement(statement, false, true, NULL, property, utf8); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1534 } |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1535 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1536 } |
0 | 1537 } |
1538 | |
1539 | |
1540 static void ExecuteSetTag(DatabaseManager::CachedStatement& statement, | |
1541 int64_t id, | |
1542 uint16_t group, | |
1543 uint16_t element, | |
1544 const char* value) | |
1545 { | |
1546 statement.SetParameterType("id", ValueType_Integer64); | |
1547 statement.SetParameterType("group", ValueType_Integer64); | |
1548 statement.SetParameterType("element", ValueType_Integer64); | |
1549 statement.SetParameterType("value", ValueType_Utf8String); | |
1550 | |
1551 Dictionary args; | |
1552 args.SetIntegerValue("id", id); | |
1553 args.SetIntegerValue("group", group); | |
1554 args.SetIntegerValue("element", element); | |
1555 args.SetUtf8Value("value", value); | |
1556 | |
1557 statement.Execute(args); | |
1558 } | |
1559 | |
1560 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1561 void IndexBackend::SetMainDicomTag(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1562 int64_t id, |
0 | 1563 uint16_t group, |
1564 uint16_t element, | |
1565 const char* value) | |
1566 { | |
1567 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1568 STATEMENT_FROM_HERE, manager, |
0 | 1569 "INSERT INTO MainDicomTags VALUES(${id}, ${group}, ${element}, ${value})"); |
1570 | |
1571 ExecuteSetTag(statement, id, group, element, value); | |
1572 } | |
1573 | |
1574 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1575 void IndexBackend::SetIdentifierTag(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1576 int64_t id, |
0 | 1577 uint16_t group, |
1578 uint16_t element, | |
1579 const char* value) | |
1580 { | |
1581 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1582 STATEMENT_FROM_HERE, manager, |
0 | 1583 "INSERT INTO DicomIdentifiers VALUES(${id}, ${group}, ${element}, ${value})"); |
1584 | |
1585 ExecuteSetTag(statement, id, group, element, value); | |
1586 } | |
1587 | |
1588 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1589 void IndexBackend::SetMetadata(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1590 int64_t id, |
0 | 1591 int32_t metadataType, |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1592 const char* value, |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1593 int64_t revision) |
0 | 1594 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1595 if (manager.GetDialect() == Dialect_SQLite) |
0 | 1596 { |
1597 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1598 STATEMENT_FROM_HERE, manager, |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1599 "INSERT OR REPLACE INTO Metadata VALUES (${id}, ${type}, ${value}, ${revision})"); |
0 | 1600 |
1601 statement.SetParameterType("id", ValueType_Integer64); | |
1602 statement.SetParameterType("type", ValueType_Integer64); | |
1603 statement.SetParameterType("value", ValueType_Utf8String); | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1604 statement.SetParameterType("revision", ValueType_Integer64); |
0 | 1605 |
1606 Dictionary args; | |
1607 args.SetIntegerValue("id", id); | |
1608 args.SetIntegerValue("type", metadataType); | |
1609 args.SetUtf8Value("value", value); | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1610 args.SetIntegerValue("revision", revision); |
0 | 1611 |
1612 statement.Execute(args); | |
1613 } | |
1614 else | |
1615 { | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1616 // TODO - REVISIONS |
0 | 1617 { |
1618 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1619 STATEMENT_FROM_HERE, manager, |
0 | 1620 "DELETE FROM Metadata WHERE id=${id} AND type=${type}"); |
1621 | |
1622 statement.SetParameterType("id", ValueType_Integer64); | |
1623 statement.SetParameterType("type", ValueType_Integer64); | |
1624 | |
1625 Dictionary args; | |
1626 args.SetIntegerValue("id", id); | |
1627 args.SetIntegerValue("type", metadataType); | |
1628 | |
1629 statement.Execute(args); | |
1630 } | |
1631 | |
1632 { | |
1633 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1634 STATEMENT_FROM_HERE, manager, |
0 | 1635 "INSERT INTO Metadata VALUES (${id}, ${type}, ${value})"); |
1636 | |
1637 statement.SetParameterType("id", ValueType_Integer64); | |
1638 statement.SetParameterType("type", ValueType_Integer64); | |
1639 statement.SetParameterType("value", ValueType_Utf8String); | |
1640 | |
1641 Dictionary args; | |
1642 args.SetIntegerValue("id", id); | |
1643 args.SetIntegerValue("type", metadataType); | |
1644 args.SetUtf8Value("value", value); | |
1645 | |
1646 statement.Execute(args); | |
1647 } | |
1648 } | |
1649 } | |
1650 | |
1651 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1652 void IndexBackend::SetProtectedPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1653 int64_t internalId, |
0 | 1654 bool isProtected) |
1655 { | |
1656 if (isProtected) | |
1657 { | |
1658 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1659 STATEMENT_FROM_HERE, manager, |
0 | 1660 "DELETE FROM PatientRecyclingOrder WHERE patientId=${id}"); |
1661 | |
1662 statement.SetParameterType("id", ValueType_Integer64); | |
1663 | |
1664 Dictionary args; | |
1665 args.SetIntegerValue("id", internalId); | |
1666 | |
1667 statement.Execute(args); | |
1668 } | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1669 else if (IsProtectedPatient(manager, internalId)) |
0 | 1670 { |
1671 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1672 STATEMENT_FROM_HERE, manager, |
0 | 1673 "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); |
1674 | |
1675 statement.SetParameterType("id", ValueType_Integer64); | |
1676 | |
1677 Dictionary args; | |
1678 args.SetIntegerValue("id", internalId); | |
1679 | |
1680 statement.Execute(args); | |
1681 } | |
1682 else | |
1683 { | |
1684 // Nothing to do: The patient is already unprotected | |
1685 } | |
1686 } | |
1687 | |
1688 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1689 uint32_t IndexBackend::GetDatabaseVersion(DatabaseManager& manager) |
0 | 1690 { |
220
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1691 // Create a read-only, explicit transaction to read the database |
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1692 // version (this was a read-write, implicit transaction in |
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1693 // PostgreSQL plugin <= 3.3 and MySQL plugin <= 3.0) |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1694 DatabaseManager::Transaction transaction(manager, TransactionType_ReadOnly); |
220
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1695 |
0 | 1696 std::string version = "unknown"; |
1697 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1698 if (LookupGlobalProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)) |
0 | 1699 { |
1700 try | |
1701 { | |
1702 return boost::lexical_cast<unsigned int>(version); | |
1703 } | |
1704 catch (boost::bad_lexical_cast&) | |
1705 { | |
1706 } | |
1707 } | |
1708 | |
1709 LOG(ERROR) << "The database is corrupted. Drop it manually for Orthanc to recreate it"; | |
1710 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
1711 } | |
1712 | |
1713 | |
1714 /** | |
1715 * Upgrade the database to the specified version of the database | |
1716 * schema. The upgrade script is allowed to make calls to | |
1717 * OrthancPluginReconstructMainDicomTags(). | |
1718 **/ | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1719 void IndexBackend::UpgradeDatabase(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1720 uint32_t targetVersion, |
0 | 1721 OrthancPluginStorageArea* storageArea) |
1722 { | |
1723 LOG(ERROR) << "Upgrading database is not implemented by this plugin"; | |
1724 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1725 } | |
1726 | |
1727 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1728 void IndexBackend::ClearMainDicomTags(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1729 int64_t internalId) |
0 | 1730 { |
1731 { | |
1732 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1733 STATEMENT_FROM_HERE, manager, |
0 | 1734 "DELETE FROM MainDicomTags WHERE id=${id}"); |
1735 | |
1736 statement.SetParameterType("id", ValueType_Integer64); | |
1737 | |
1738 Dictionary args; | |
1739 args.SetIntegerValue("id", internalId); | |
1740 | |
1741 statement.Execute(args); | |
1742 } | |
1743 | |
1744 { | |
1745 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1746 STATEMENT_FROM_HERE, manager, |
0 | 1747 "DELETE FROM DicomIdentifiers WHERE id=${id}"); |
1748 | |
1749 statement.SetParameterType("id", ValueType_Integer64); | |
1750 | |
1751 Dictionary args; | |
1752 args.SetIntegerValue("id", internalId); | |
1753 | |
1754 statement.Execute(args); | |
1755 } | |
1756 } | |
1757 | |
1758 | |
1759 // For unit testing only! | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1760 uint64_t IndexBackend::GetAllResourcesCount(DatabaseManager& manager) |
0 | 1761 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1762 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1763 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1764 switch (manager.GetDialect()) |
0 | 1765 { |
1766 case Dialect_MySQL: | |
1767 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1768 STATEMENT_FROM_HERE, manager, |
0 | 1769 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources")); |
1770 break; | |
1771 | |
1772 case Dialect_PostgreSQL: | |
1773 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1774 STATEMENT_FROM_HERE, manager, |
0 | 1775 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources")); |
1776 break; | |
1777 | |
1778 case Dialect_SQLite: | |
1779 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1780 STATEMENT_FROM_HERE, manager, |
0 | 1781 "SELECT COUNT(*) FROM Resources")); |
1782 break; | |
1783 | |
1784 default: | |
1785 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1786 } | |
1787 | |
1788 statement->SetReadOnly(true); | |
1789 statement->Execute(); | |
1790 | |
1791 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
1792 } | |
1793 | |
1794 | |
1795 // For unit testing only! | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1796 uint64_t IndexBackend::GetUnprotectedPatientsCount(DatabaseManager& manager) |
0 | 1797 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1798 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1799 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1800 switch (manager.GetDialect()) |
0 | 1801 { |
1802 case Dialect_MySQL: | |
1803 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1804 STATEMENT_FROM_HERE, manager, |
0 | 1805 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM PatientRecyclingOrder")); |
1806 break; | |
1807 | |
1808 case Dialect_PostgreSQL: | |
1809 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1810 STATEMENT_FROM_HERE, manager, |
0 | 1811 "SELECT CAST(COUNT(*) AS BIGINT) FROM PatientRecyclingOrder")); |
1812 break; | |
1813 | |
1814 case Dialect_SQLite: | |
1815 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1816 STATEMENT_FROM_HERE, manager, |
0 | 1817 "SELECT COUNT(*) FROM PatientRecyclingOrder")); |
1818 break; | |
1819 | |
1820 default: | |
1821 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1822 } | |
1823 | |
1824 statement->SetReadOnly(true); | |
1825 statement->Execute(); | |
1826 | |
1827 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
1828 } | |
1829 | |
1830 | |
1831 // For unit testing only! | |
1832 bool IndexBackend::GetParentPublicId(std::string& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1833 DatabaseManager& manager, |
0 | 1834 int64_t id) |
1835 { | |
1836 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1837 STATEMENT_FROM_HERE, manager, |
0 | 1838 "SELECT a.publicId FROM Resources AS a, Resources AS b " |
1839 "WHERE a.internalId = b.parentId AND b.internalId = ${id}"); | |
1840 | |
1841 statement.SetReadOnly(true); | |
1842 statement.SetParameterType("id", ValueType_Integer64); | |
1843 | |
1844 Dictionary args; | |
1845 args.SetIntegerValue("id", id); | |
1846 | |
1847 statement.Execute(args); | |
1848 | |
1849 if (statement.IsDone()) | |
1850 { | |
1851 return false; | |
1852 } | |
1853 else | |
1854 { | |
1855 target = ReadString(statement, 0); | |
1856 return true; | |
1857 } | |
1858 } | |
1859 | |
1860 | |
1861 // For unit tests only! | |
1862 void IndexBackend::GetChildren(std::list<std::string>& childrenPublicIds, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1863 DatabaseManager& manager, |
0 | 1864 int64_t id) |
1865 { | |
1866 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1867 STATEMENT_FROM_HERE, manager, |
0 | 1868 "SELECT publicId FROM Resources WHERE parentId=${id}"); |
1869 | |
1870 statement.SetReadOnly(true); | |
1871 statement.SetParameterType("id", ValueType_Integer64); | |
1872 | |
1873 Dictionary args; | |
1874 args.SetIntegerValue("id", id); | |
1875 | |
1876 ReadListOfStrings(childrenPublicIds, statement, args); | |
1877 } | |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1878 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1879 |
78 | 1880 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1881 class IndexBackend::LookupFormatter : public Orthanc::ISqlLookupFormatter |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1882 { |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1883 private: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1884 Dialect dialect_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1885 size_t count_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1886 Dictionary dictionary_; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1887 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1888 static std::string FormatParameter(size_t index) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1889 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1890 return "p" + boost::lexical_cast<std::string>(index); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1891 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1892 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1893 public: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1894 LookupFormatter(Dialect dialect) : |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1895 dialect_(dialect), |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1896 count_(0) |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1897 { |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1898 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1899 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1900 virtual std::string GenerateParameter(const std::string& value) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1901 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1902 const std::string key = FormatParameter(count_); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1903 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1904 count_ ++; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1905 dictionary_.SetUtf8Value(key, value); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1906 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1907 return "${" + key + "}"; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1908 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1909 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1910 virtual std::string FormatResourceType(Orthanc::ResourceType level) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1911 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1912 return boost::lexical_cast<std::string>(Orthanc::Plugins::Convert(level)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1913 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1914 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1915 virtual std::string FormatWildcardEscape() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1916 { |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1917 switch (dialect_) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1918 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1919 case Dialect_SQLite: |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1920 case Dialect_PostgreSQL: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1921 return "ESCAPE '\\'"; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1922 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1923 case Dialect_MySQL: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1924 return "ESCAPE '\\\\'"; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1925 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1926 default: |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1927 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1928 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1929 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1930 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1931 void PrepareStatement(DatabaseManager::StandaloneStatement& statement) const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1932 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1933 statement.SetReadOnly(true); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1934 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1935 for (size_t i = 0; i < count_; i++) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1936 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1937 statement.SetParameterType(FormatParameter(i), ValueType_Utf8String); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1938 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1939 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1940 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1941 const Dictionary& GetDictionary() const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1942 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1943 return dictionary_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1944 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1945 }; |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1946 #endif |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1947 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1948 |
78 | 1949 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1950 // New primitive since Orthanc 1.5.2 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
1951 void IndexBackend::LookupResources(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1952 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1953 const std::vector<Orthanc::DatabaseConstraint>& lookup, |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1954 OrthancPluginResourceType queryLevel, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1955 uint32_t limit, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1956 bool requestSomeInstance) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1957 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1958 LookupFormatter formatter(manager.GetDialect()); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1959 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1960 std::string sql; |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1961 Orthanc::ISqlLookupFormatter::Apply(sql, formatter, lookup, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1962 Orthanc::Plugins::Convert(queryLevel), limit); |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1963 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1964 if (requestSomeInstance) |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1965 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1966 // Composite query to find some instance if requested |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1967 switch (queryLevel) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1968 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1969 case OrthancPluginResourceType_Patient: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1970 sql = ("SELECT patients.publicId, MIN(instances.publicId) FROM (" + sql + ") patients " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1971 "INNER JOIN Resources studies ON studies.parentId = patients.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1972 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1973 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1974 "GROUP BY patients.publicId"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1975 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1976 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1977 case OrthancPluginResourceType_Study: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1978 sql = ("SELECT studies.publicId, MIN(instances.publicId) FROM (" + sql + ") studies " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1979 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1980 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1981 "GROUP BY studies.publicId"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1982 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1983 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1984 case OrthancPluginResourceType_Series: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1985 sql = ("SELECT series.publicId, MIN(instances.publicId) FROM (" + sql + ") series " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1986 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1987 "GROUP BY series.publicId"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1988 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1989 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1990 case OrthancPluginResourceType_Instance: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1991 sql = ("SELECT instances.publicId, instances.publicId FROM (" + sql + ") instances"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1992 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1993 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1994 default: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1995 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1996 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1997 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1998 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1999 DatabaseManager::StandaloneStatement statement(manager, sql); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2000 formatter.PrepareStatement(statement); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2001 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2002 statement.Execute(formatter.GetDictionary()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2003 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2004 while (!statement.IsDone()) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2005 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2006 if (requestSomeInstance) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2007 { |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
2008 output.AnswerMatchingResource(ReadString(statement, 0), ReadString(statement, 1)); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2009 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2010 else |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2011 { |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
2012 output.AnswerMatchingResource(ReadString(statement, 0)); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2013 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2014 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2015 statement.Next(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2016 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2017 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2018 #endif |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2019 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2020 |
78 | 2021 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2022 static void ExecuteSetResourcesContentTags( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2023 DatabaseManager& manager, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2024 const std::string& table, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2025 const std::string& variablePrefix, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2026 uint32_t count, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2027 const OrthancPluginResourcesContentTags* tags) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2028 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2029 std::string sql; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2030 Dictionary args; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2031 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2032 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2033 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2034 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2035 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2036 args.SetUtf8Value(name, tags[i].value); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2037 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2038 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2039 boost::lexical_cast<std::string>(tags[i].group) + ", " + |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2040 boost::lexical_cast<std::string>(tags[i].element) + ", " + |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2041 "${" + name + "})"); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2042 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2043 if (sql.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2044 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2045 sql = "INSERT INTO " + table + " VALUES " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2046 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2047 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2048 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2049 sql += ", " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2050 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2051 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2052 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2053 if (!sql.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2054 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2055 DatabaseManager::StandaloneStatement statement(manager, sql); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2056 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2057 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2058 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2059 statement.SetParameterType(variablePrefix + boost::lexical_cast<std::string>(i), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2060 ValueType_Utf8String); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2061 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2062 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2063 statement.Execute(args); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2064 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2065 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2066 #endif |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2067 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2068 |
78 | 2069 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2070 static void ExecuteSetResourcesContentMetadata( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2071 DatabaseManager& manager, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2072 uint32_t count, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2073 const OrthancPluginResourcesContentMetadata* metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2074 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2075 std::string sqlRemove; // To overwrite |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2076 std::string sqlInsert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2077 Dictionary args; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2078 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2079 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2080 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2081 std::string name = "m" + boost::lexical_cast<std::string>(i); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2082 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2083 args.SetUtf8Value(name, metadata[i].value); |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2084 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2085 std::string revisionSuffix; |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2086 if (manager.GetDialect() == Dialect_SQLite) |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2087 { |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2088 revisionSuffix = ", 0"; // TODO - REVISIONS |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2089 } |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2090 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2091 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " + |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2092 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " + |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2093 "${" + name + "}" + revisionSuffix + ")"); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2094 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2095 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) + |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2096 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2097 + ")"); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2098 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2099 if (sqlInsert.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2100 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2101 sqlInsert = "INSERT INTO Metadata VALUES " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2102 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2103 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2104 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2105 sqlInsert += ", " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2106 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2107 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2108 if (sqlRemove.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2109 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2110 sqlRemove = "DELETE FROM Metadata WHERE " + remove; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2111 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2112 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2113 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2114 sqlRemove += " OR " + remove; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2115 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2116 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2117 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2118 if (!sqlRemove.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2119 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2120 DatabaseManager::StandaloneStatement statement(manager, sqlRemove); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2121 statement.Execute(); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2122 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2123 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2124 if (!sqlInsert.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2125 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2126 DatabaseManager::StandaloneStatement statement(manager, sqlInsert); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2127 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2128 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2129 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2130 statement.SetParameterType("m" + boost::lexical_cast<std::string>(i), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2131 ValueType_Utf8String); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2132 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2133 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2134 statement.Execute(args); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2135 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2136 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2137 #endif |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2138 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2139 |
78 | 2140 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2141 // New primitive since Orthanc 1.5.2 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2142 void IndexBackend::SetResourcesContent( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2143 DatabaseManager& manager, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2144 uint32_t countIdentifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2145 const OrthancPluginResourcesContentTags* identifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2146 uint32_t countMainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2147 const OrthancPluginResourcesContentTags* mainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2148 uint32_t countMetadata, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2149 const OrthancPluginResourcesContentMetadata* metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2150 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2151 /** |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2152 * TODO - PostgreSQL doesn't allow multiple commands in a prepared |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2153 * statement, so we execute 3 separate commands (for identifiers, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2154 * main tags and metadata). Maybe MySQL does not suffer from the |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2155 * same limitation, to check. |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2156 **/ |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2157 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2158 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i", |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2159 countIdentifierTags, identifierTags); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2160 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2161 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t", |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2162 countMainDicomTags, mainDicomTags); |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2163 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2164 ExecuteSetResourcesContentMetadata(manager, countMetadata, metadata); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2165 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2166 #endif |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2167 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2168 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2169 // New primitive since Orthanc 1.5.2 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2170 void IndexBackend::GetChildrenMetadata(std::list<std::string>& target, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2171 DatabaseManager& manager, |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2172 int64_t resourceId, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2173 int32_t metadata) |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2174 { |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2175 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2176 STATEMENT_FROM_HERE, manager, |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2177 "SELECT value FROM Metadata WHERE type=${metadata} AND " |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2178 "id IN (SELECT internalId FROM Resources WHERE parentId=${id})"); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2179 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2180 statement.SetReadOnly(true); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2181 statement.SetParameterType("id", ValueType_Integer64); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2182 statement.SetParameterType("metadata", ValueType_Integer64); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2183 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2184 Dictionary args; |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2185 args.SetIntegerValue("id", static_cast<int>(resourceId)); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2186 args.SetIntegerValue("metadata", static_cast<int>(metadata)); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2187 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2188 ReadListOfStrings(target, statement, args); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2189 } |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2190 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2191 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2192 // New primitive since Orthanc 1.5.2 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2193 void IndexBackend::TagMostRecentPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2194 int64_t patient) |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2195 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2196 int64_t seq; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2197 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2198 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2199 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2200 STATEMENT_FROM_HERE, manager, |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2201 "SELECT * FROM PatientRecyclingOrder WHERE seq >= " |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2202 "(SELECT seq FROM PatientRecyclingOrder WHERE patientid=${id}) ORDER BY seq LIMIT 2"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2203 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2204 statement.SetReadOnly(true); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2205 statement.SetParameterType("id", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2206 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2207 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2208 args.SetIntegerValue("id", patient); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2209 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2210 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2211 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2212 if (statement.IsDone()) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2213 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2214 // The patient is protected, don't add it to the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2215 return; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2216 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2217 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2218 seq = ReadInteger64(statement, 0); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2219 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2220 statement.Next(); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2221 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2222 if (statement.IsDone()) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2223 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2224 // The patient is already at the end of the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2225 // (because of the "LIMIT 2" above), no need to modify the table |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2226 return; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2227 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2228 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2229 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2230 // Delete the old position of the patient in the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2231 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2232 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2233 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2234 STATEMENT_FROM_HERE, manager, |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2235 "DELETE FROM PatientRecyclingOrder WHERE seq=${seq}"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2236 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2237 statement.SetParameterType("seq", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2238 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2239 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2240 args.SetIntegerValue("seq", seq); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2241 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2242 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2243 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2244 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2245 // Add the patient to the end of the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2246 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2247 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2248 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2249 STATEMENT_FROM_HERE, manager, |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2250 "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2251 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2252 statement.SetParameterType("id", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2253 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2254 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2255 args.SetIntegerValue("id", patient); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2256 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2257 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2258 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2259 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2260 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2261 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2262 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2263 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2264 // New primitive since Orthanc 1.5.4 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2265 bool IndexBackend::LookupResourceAndParent(int64_t& id, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2266 OrthancPluginResourceType& type, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2267 std::string& parentPublicId, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2268 DatabaseManager& manager, |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2269 const char* publicId) |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2270 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2271 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2272 STATEMENT_FROM_HERE, manager, |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2273 "SELECT resource.internalId, resource.resourceType, parent.publicId " |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2274 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId " |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2275 "WHERE resource.publicId=${id}"); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2276 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2277 statement.SetParameterType("id", ValueType_Utf8String); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2278 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2279 Dictionary args; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2280 args.SetUtf8Value("id", publicId); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2281 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2282 statement.Execute(args); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2283 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2284 if (statement.IsDone()) |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2285 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2286 return false; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2287 } |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2288 else |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2289 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2290 if (statement.GetResultFieldsCount() != 3) |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2291 { |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2292 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2293 } |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2294 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2295 statement.SetResultFieldType(0, ValueType_Integer64); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2296 statement.SetResultFieldType(1, ValueType_Integer64); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2297 statement.SetResultFieldType(2, ValueType_Utf8String); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2298 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2299 id = ReadInteger64(statement, 0); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2300 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2301 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2302 const IValue& value = statement.GetResultField(2); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2303 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2304 switch (value.GetType()) |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2305 { |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2306 case ValueType_Null: |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2307 parentPublicId.clear(); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2308 break; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2309 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2310 case ValueType_Utf8String: |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2311 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent(); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2312 break; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2313 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2314 default: |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2315 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2316 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2317 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2318 assert((statement.Next(), statement.IsDone())); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2319 return true; |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2320 } |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2321 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2322 # endif |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2323 #endif |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2324 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2325 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2326 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2327 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2328 // New primitive since Orthanc 1.5.4 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2329 void IndexBackend::GetAllMetadata(std::map<int32_t, std::string>& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2330 DatabaseManager& manager, |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2331 int64_t id) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2332 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2333 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2334 STATEMENT_FROM_HERE, manager, |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2335 "SELECT type, value FROM Metadata WHERE id=${id}"); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2336 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2337 statement.SetReadOnly(true); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2338 statement.SetParameterType("id", ValueType_Integer64); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2339 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2340 Dictionary args; |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2341 args.SetIntegerValue("id", id); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2342 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2343 statement.Execute(args); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2344 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2345 result.clear(); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2346 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2347 if (!statement.IsDone()) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2348 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2349 if (statement.GetResultFieldsCount() != 2) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2350 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2351 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2352 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2353 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2354 statement.SetResultFieldType(0, ValueType_Integer64); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2355 statement.SetResultFieldType(1, ValueType_Utf8String); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2356 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2357 while (!statement.IsDone()) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2358 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2359 result[ReadInteger32(statement, 0)] = ReadString(statement, 1); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2360 statement.Next(); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2361 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2362 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2363 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2364 # endif |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2365 #endif |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2366 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2367 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2368 void IndexBackend::CreateInstanceGeneric(OrthancPluginCreateInstanceResult& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2369 DatabaseManager& manager, |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2370 const char* hashPatient, |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2371 const char* hashStudy, |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2372 const char* hashSeries, |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2373 const char* hashInstance) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2374 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2375 // Check out "OrthancServer/Sources/Database/Compatibility/ICreateInstance.cpp" |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2376 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2377 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2378 OrthancPluginResourceType type; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2379 int64_t tmp; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2380 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2381 if (LookupResource(tmp, type, manager, hashInstance)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2382 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2383 // The instance already exists |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2384 assert(type == OrthancPluginResourceType_Instance); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2385 result.instanceId = tmp; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2386 result.isNewInstance = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2387 return; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2388 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2389 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2390 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2391 result.instanceId = CreateResource(manager, hashInstance, OrthancPluginResourceType_Instance); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2392 result.isNewInstance = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2393 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2394 result.isNewPatient = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2395 result.isNewStudy = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2396 result.isNewSeries = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2397 result.patientId = -1; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2398 result.studyId = -1; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2399 result.seriesId = -1; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2400 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2401 // Detect up to which level the patient/study/series/instance |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2402 // hierarchy must be created |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2403 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2404 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2405 OrthancPluginResourceType dummy; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2406 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2407 if (LookupResource(result.seriesId, dummy, manager, hashSeries)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2408 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2409 assert(dummy == OrthancPluginResourceType_Series); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2410 // The patient, the study and the series already exist |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2411 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2412 bool ok = (LookupResource(result.patientId, dummy, manager, hashPatient) && |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2413 LookupResource(result.studyId, dummy, manager, hashStudy)); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2414 (void) ok; // Remove warning about unused variable in release builds |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2415 assert(ok); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2416 } |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2417 else if (LookupResource(result.studyId, dummy, manager, hashStudy)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2418 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2419 assert(dummy == OrthancPluginResourceType_Study); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2420 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2421 // New series: The patient and the study already exist |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2422 result.isNewSeries = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2423 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2424 bool ok = LookupResource(result.patientId, dummy, manager, hashPatient); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2425 (void) ok; // Remove warning about unused variable in release builds |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2426 assert(ok); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2427 } |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2428 else if (LookupResource(result.patientId, dummy, manager, hashPatient)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2429 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2430 assert(dummy == OrthancPluginResourceType_Patient); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2431 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2432 // New study and series: The patient already exist |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2433 result.isNewStudy = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2434 result.isNewSeries = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2435 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2436 else |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2437 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2438 // New patient, study and series: Nothing exists |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2439 result.isNewPatient = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2440 result.isNewStudy = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2441 result.isNewSeries = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2442 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2443 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2444 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2445 // Create the series if needed |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2446 if (result.isNewSeries) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2447 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2448 result.seriesId = CreateResource(manager, hashSeries, OrthancPluginResourceType_Series); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2449 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2450 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2451 // Create the study if needed |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2452 if (result.isNewStudy) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2453 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2454 result.studyId = CreateResource(manager, hashStudy, OrthancPluginResourceType_Study); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2455 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2456 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2457 // Create the patient if needed |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2458 if (result.isNewPatient) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2459 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2460 result.patientId = CreateResource(manager, hashPatient, OrthancPluginResourceType_Patient); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2461 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2462 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2463 // Create the parent-to-child links |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2464 AttachChild(manager, result.seriesId, result.instanceId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2465 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2466 if (result.isNewSeries) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2467 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2468 AttachChild(manager, result.studyId, result.seriesId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2469 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2470 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2471 if (result.isNewStudy) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2472 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2473 AttachChild(manager, result.patientId, result.studyId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2474 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2475 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2476 TagMostRecentPatient(manager, result.patientId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2477 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2478 // Sanity checks |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2479 assert(result.patientId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2480 assert(result.studyId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2481 assert(result.seriesId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2482 assert(result.instanceId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2483 } |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2484 |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2485 |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2486 void IndexBackend::Register(IndexBackend* backend, |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2487 size_t countConnections, |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2488 unsigned int maxDatabaseRetries) |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2489 { |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2490 if (backend == NULL) |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2491 { |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2492 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2493 } |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2494 |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2495 bool hasLoadedV3 = false; |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2496 |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2497 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2498 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2) |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2499 if (OrthancPluginCheckVersionAdvanced(backend->GetContext(), 1, 9, 2) == 1) |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2500 { |
253
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
2501 LOG(WARNING) << "The index plugin will use " << countConnections << " connection(s) to the database, " |
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
2502 << "and will retry up to " << maxDatabaseRetries << " time(s) in the case of a collision"; |
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
2503 |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2504 OrthancDatabases::DatabaseBackendAdapterV3::Register(backend, countConnections, maxDatabaseRetries); |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2505 hasLoadedV3 = true; |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2506 } |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2507 # endif |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2508 #endif |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2509 |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2510 if (!hasLoadedV3) |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2511 { |
249
7f5ee2b42a86
better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
239
diff
changeset
|
2512 LOG(WARNING) << "Performance warning: Your version of the Orthanc SDK doesn't support multiple readers/writers"; |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2513 OrthancDatabases::DatabaseBackendAdapterV2::Register(backend); |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2514 } |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2515 } |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2516 |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2517 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2518 bool IndexBackend::LookupGlobalIntegerProperty(int& target, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2519 DatabaseManager& manager, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2520 const char* serverIdentifier, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2521 int32_t property) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2522 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2523 std::string value; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2524 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2525 if (LookupGlobalProperty(value, manager, serverIdentifier, property)) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2526 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2527 try |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2528 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2529 target = boost::lexical_cast<int>(value); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2530 return true; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2531 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2532 catch (boost::bad_lexical_cast&) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2533 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2534 LOG(ERROR) << "Corrupted PostgreSQL database"; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2535 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2536 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2537 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2538 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2539 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2540 return false; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2541 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2542 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2543 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2544 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2545 void IndexBackend::SetGlobalIntegerProperty(DatabaseManager& manager, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2546 const char* serverIdentifier, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2547 int32_t property, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2548 int value) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2549 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2550 std::string s = boost::lexical_cast<std::string>(value); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2551 SetGlobalProperty(manager, serverIdentifier, property, s.c_str()); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2552 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2553 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2554 |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2555 void IndexBackend::Finalize() |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2556 { |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2557 OrthancDatabases::DatabaseBackendAdapterV2::Finalize(); |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2558 |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2559 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2560 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2) |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2561 OrthancDatabases::DatabaseBackendAdapterV3::Finalize(); |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2562 # endif |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2563 #endif |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2564 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2565 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2566 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2567 DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend) |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2568 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
2569 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend.CreateDatabaseFactory())); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2570 backend.ConfigureDatabase(*manager); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2571 return manager.release(); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2572 } |
0 | 2573 } |