Mercurial > hg > orthanc
annotate Plugins/Samples/DatabasePlugin/Database.cpp @ 2144:a979ded1dbb1
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 16:57:19 +0100 |
parents | b1291df2f780 |
children | a3a65de1840f |
rev | line source |
---|---|
1671 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1671 | 4 * Department, University Hospital of Liege, Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "Database.h" | |
34 | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
35 #include "../../../Core/DicomFormat/DicomArray.h" |
1671 | 36 |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
37 #include <EmbeddedResources.h> |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
38 #include <boost/lexical_cast.hpp> |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
39 |
1671 | 40 |
41 namespace Internals | |
42 { | |
43 class SignalFileDeleted : public Orthanc::SQLite::IScalarFunction | |
44 { | |
45 private: | |
46 OrthancPlugins::DatabaseBackendOutput& output_; | |
47 | |
48 public: | |
49 SignalFileDeleted(OrthancPlugins::DatabaseBackendOutput& output) : output_(output) | |
50 { | |
51 } | |
52 | |
53 virtual const char* GetName() const | |
54 { | |
55 return "SignalFileDeleted"; | |
56 } | |
57 | |
58 virtual unsigned int GetCardinality() const | |
59 { | |
60 return 7; | |
61 } | |
62 | |
63 virtual void Compute(Orthanc::SQLite::FunctionContext& context) | |
64 { | |
65 std::string uncompressedMD5, compressedMD5; | |
66 | |
67 if (!context.IsNullValue(5)) | |
68 { | |
69 uncompressedMD5 = context.GetStringValue(5); | |
70 } | |
71 | |
72 if (!context.IsNullValue(6)) | |
73 { | |
74 compressedMD5 = context.GetStringValue(6); | |
75 } | |
76 | |
77 output_.SignalDeletedAttachment(context.GetStringValue(0), | |
78 context.GetIntValue(1), | |
79 context.GetInt64Value(2), | |
80 uncompressedMD5, | |
81 context.GetIntValue(3), | |
82 context.GetInt64Value(4), | |
83 compressedMD5); | |
84 } | |
85 }; | |
86 | |
87 | |
88 class SignalResourceDeleted : public Orthanc::SQLite::IScalarFunction | |
89 { | |
90 private: | |
91 OrthancPlugins::DatabaseBackendOutput& output_; | |
92 | |
93 public: | |
94 SignalResourceDeleted(OrthancPlugins::DatabaseBackendOutput& output) : output_(output) | |
95 { | |
96 } | |
97 | |
98 virtual const char* GetName() const | |
99 { | |
100 return "SignalResourceDeleted"; | |
101 } | |
102 | |
103 virtual unsigned int GetCardinality() const | |
104 { | |
105 return 2; | |
106 } | |
107 | |
108 virtual void Compute(Orthanc::SQLite::FunctionContext& context) | |
109 { | |
110 output_.SignalDeletedResource(context.GetStringValue(0), | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
111 Orthanc::Plugins::Convert(static_cast<Orthanc::ResourceType>(context.GetIntValue(1)))); |
1671 | 112 } |
113 }; | |
114 } | |
115 | |
116 | |
117 class Database::SignalRemainingAncestor : public Orthanc::SQLite::IScalarFunction | |
118 { | |
119 private: | |
120 bool hasRemainingAncestor_; | |
121 std::string remainingPublicId_; | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
122 OrthancPluginResourceType remainingType_; |
1671 | 123 |
124 public: | |
125 SignalRemainingAncestor() : | |
1847 | 126 hasRemainingAncestor_(false), |
127 remainingType_(OrthancPluginResourceType_Instance) // Some dummy value | |
1671 | 128 { |
129 } | |
130 | |
131 void Reset() | |
132 { | |
133 hasRemainingAncestor_ = false; | |
134 } | |
135 | |
136 virtual const char* GetName() const | |
137 { | |
138 return "SignalRemainingAncestor"; | |
139 } | |
140 | |
141 virtual unsigned int GetCardinality() const | |
142 { | |
143 return 2; | |
144 } | |
145 | |
146 virtual void Compute(Orthanc::SQLite::FunctionContext& context) | |
147 { | |
148 if (!hasRemainingAncestor_ || | |
149 remainingType_ >= context.GetIntValue(1)) | |
150 { | |
151 hasRemainingAncestor_ = true; | |
152 remainingPublicId_ = context.GetStringValue(0); | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
153 remainingType_ = Orthanc::Plugins::Convert(static_cast<Orthanc::ResourceType>(context.GetIntValue(1))); |
1671 | 154 } |
155 } | |
156 | |
157 bool HasRemainingAncestor() const | |
158 { | |
159 return hasRemainingAncestor_; | |
160 } | |
161 | |
162 const std::string& GetRemainingAncestorId() const | |
163 { | |
164 assert(hasRemainingAncestor_); | |
165 return remainingPublicId_; | |
166 } | |
167 | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
168 OrthancPluginResourceType GetRemainingAncestorType() const |
1671 | 169 { |
170 assert(hasRemainingAncestor_); | |
171 return remainingType_; | |
172 } | |
173 }; | |
174 | |
175 | |
176 | |
177 Database::Database(const std::string& path) : | |
178 path_(path), | |
1847 | 179 base_(db_), |
180 signalRemainingAncestor_(NULL) | |
1671 | 181 { |
182 } | |
183 | |
184 | |
185 void Database::Open() | |
186 { | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
187 db_.Open(path_); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
188 |
1717
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1673
diff
changeset
|
189 db_.Execute("PRAGMA ENCODING=\"UTF-8\";"); |
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1673
diff
changeset
|
190 |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
191 // http://www.sqlite.org/pragma.html |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
192 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
193 db_.Execute("PRAGMA JOURNAL_MODE=WAL;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
194 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
195 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
196 //db_.Execute("PRAGMA TEMP_STORE=memory"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
197 |
1671 | 198 if (!db_.DoesTableExist("GlobalProperties")) |
199 { | |
200 std::string query; | |
201 Orthanc::EmbeddedResources::GetFileResource(query, Orthanc::EmbeddedResources::PREPARE_DATABASE); | |
202 db_.Execute(query); | |
203 } | |
204 | |
205 signalRemainingAncestor_ = new SignalRemainingAncestor; | |
206 db_.Register(signalRemainingAncestor_); | |
207 db_.Register(new Internals::SignalFileDeleted(GetOutput())); | |
208 db_.Register(new Internals::SignalResourceDeleted(GetOutput())); | |
209 } | |
210 | |
211 | |
212 void Database::Close() | |
213 { | |
214 db_.Close(); | |
215 } | |
216 | |
217 | |
218 void Database::AddAttachment(int64_t id, | |
219 const OrthancPluginAttachment& attachment) | |
220 { | |
221 Orthanc::FileInfo info(attachment.uuid, | |
222 static_cast<Orthanc::FileContentType>(attachment.contentType), | |
223 attachment.uncompressedSize, | |
224 attachment.uncompressedHash, | |
225 static_cast<Orthanc::CompressionType>(attachment.compressionType), | |
226 attachment.compressedSize, | |
227 attachment.compressedHash); | |
228 base_.AddAttachment(id, info); | |
229 } | |
230 | |
231 | |
232 void Database::DeleteResource(int64_t id) | |
233 { | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
234 signalRemainingAncestor_->Reset(); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
235 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
236 Orthanc::SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
237 s.BindInt64(0, id); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
238 s.Run(); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
239 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
240 if (signalRemainingAncestor_->HasRemainingAncestor()) |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
241 { |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
242 GetOutput().SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorId(), |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
243 signalRemainingAncestor_->GetRemainingAncestorType()); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
244 } |
1671 | 245 } |
246 | |
247 | |
248 static void Answer(OrthancPlugins::DatabaseBackendOutput& output, | |
249 const Orthanc::ServerIndexChange& change) | |
250 { | |
251 output.AnswerChange(change.GetSeq(), | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
252 change.GetChangeType(), |
1671 | 253 Orthanc::Plugins::Convert(change.GetResourceType()), |
254 change.GetPublicId(), | |
255 change.GetDate()); | |
256 } | |
257 | |
258 | |
259 static void Answer(OrthancPlugins::DatabaseBackendOutput& output, | |
260 const Orthanc::ExportedResource& resource) | |
261 { | |
262 output.AnswerExportedResource(resource.GetSeq(), | |
263 Orthanc::Plugins::Convert(resource.GetResourceType()), | |
264 resource.GetPublicId(), | |
265 resource.GetModality(), | |
266 resource.GetDate(), | |
267 resource.GetPatientId(), | |
268 resource.GetStudyInstanceUid(), | |
269 resource.GetSeriesInstanceUid(), | |
270 resource.GetSopInstanceUid()); | |
271 } | |
272 | |
273 | |
274 void Database::GetChanges(bool& done /*out*/, | |
275 int64_t since, | |
276 uint32_t maxResults) | |
277 { | |
278 typedef std::list<Orthanc::ServerIndexChange> Changes; | |
279 | |
280 Changes changes; | |
281 base_.GetChanges(changes, done, since, maxResults); | |
282 | |
283 for (Changes::const_iterator it = changes.begin(); it != changes.end(); ++it) | |
284 { | |
285 Answer(GetOutput(), *it); | |
286 } | |
287 } | |
288 | |
289 | |
290 void Database::GetExportedResources(bool& done /*out*/, | |
291 int64_t since, | |
292 uint32_t maxResults) | |
293 { | |
294 typedef std::list<Orthanc::ExportedResource> Resources; | |
295 | |
296 Resources resources; | |
297 base_.GetExportedResources(resources, done, since, maxResults); | |
298 | |
299 for (Resources::const_iterator it = resources.begin(); it != resources.end(); ++it) | |
300 { | |
301 Answer(GetOutput(), *it); | |
302 } | |
303 } | |
304 | |
305 | |
306 void Database::GetLastChange() | |
307 { | |
308 std::list<Orthanc::ServerIndexChange> change; | |
309 Orthanc::ErrorCode code = base_.GetLastChange(change); | |
310 | |
311 if (code != Orthanc::ErrorCode_Success) | |
312 { | |
313 throw OrthancPlugins::DatabaseException(static_cast<OrthancPluginErrorCode>(code)); | |
314 } | |
315 | |
316 if (!change.empty()) | |
317 { | |
318 Answer(GetOutput(), change.front()); | |
319 } | |
320 } | |
321 | |
322 | |
323 void Database::GetLastExportedResource() | |
324 { | |
325 std::list<Orthanc::ExportedResource> resource; | |
326 base_.GetLastExportedResource(resource); | |
327 | |
328 if (!resource.empty()) | |
329 { | |
330 Answer(GetOutput(), resource.front()); | |
331 } | |
332 } | |
333 | |
334 | |
335 void Database::GetMainDicomTags(int64_t id) | |
336 { | |
337 Orthanc::DicomMap tags; | |
338 base_.GetMainDicomTags(tags, id); | |
339 | |
340 Orthanc::DicomArray arr(tags); | |
341 for (size_t i = 0; i < arr.GetSize(); i++) | |
342 { | |
343 GetOutput().AnswerDicomTag(arr.GetElement(i).GetTag().GetGroup(), | |
344 arr.GetElement(i).GetTag().GetElement(), | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1717
diff
changeset
|
345 arr.GetElement(i).GetValue().GetContent()); |
1671 | 346 } |
347 } | |
348 | |
349 | |
350 std::string Database::GetPublicId(int64_t resourceId) | |
351 { | |
352 std::string id; | |
353 if (base_.GetPublicId(id, resourceId)) | |
354 { | |
355 return id; | |
356 } | |
357 else | |
358 { | |
359 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_UnknownResource); | |
360 } | |
361 } | |
362 | |
363 | |
364 OrthancPluginResourceType Database::GetResourceType(int64_t resourceId) | |
365 { | |
366 Orthanc::ResourceType result; | |
367 Orthanc::ErrorCode code = base_.GetResourceType(result, resourceId); | |
368 | |
369 if (code == Orthanc::ErrorCode_Success) | |
370 { | |
371 return Orthanc::Plugins::Convert(result); | |
372 } | |
373 else | |
374 { | |
375 throw OrthancPlugins::DatabaseException(static_cast<OrthancPluginErrorCode>(code)); | |
376 } | |
377 } | |
378 | |
379 | |
380 | |
381 template <typename I> | |
382 static void ConvertList(std::list<int32_t>& target, | |
383 const std::list<I>& source) | |
384 { | |
385 for (typename std::list<I>::const_iterator | |
1847 | 386 it = source.begin(); it != source.end(); ++it) |
1671 | 387 { |
388 target.push_back(*it); | |
389 } | |
390 } | |
391 | |
392 | |
393 void Database::ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
394 int64_t id) | |
395 { | |
396 std::list<Orthanc::MetadataType> tmp; | |
397 base_.ListAvailableMetadata(tmp, id); | |
398 ConvertList(target, tmp); | |
399 } | |
400 | |
401 | |
402 void Database::ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
403 int64_t id) | |
404 { | |
405 std::list<Orthanc::FileContentType> tmp; | |
406 base_.ListAvailableAttachments(tmp, id); | |
407 ConvertList(target, tmp); | |
408 } | |
409 | |
410 | |
411 void Database::LogChange(const OrthancPluginChange& change) | |
412 { | |
413 int64_t id; | |
414 OrthancPluginResourceType type; | |
415 if (!LookupResource(id, type, change.publicId) || | |
416 type != change.resourceType) | |
417 { | |
418 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_DatabasePlugin); | |
419 } | |
420 | |
421 Orthanc::ServerIndexChange tmp(change.seq, | |
422 static_cast<Orthanc::ChangeType>(change.changeType), | |
423 Orthanc::Plugins::Convert(change.resourceType), | |
424 change.publicId, | |
425 change.date); | |
426 | |
427 base_.LogChange(id, tmp); | |
428 } | |
429 | |
430 | |
431 void Database::LogExportedResource(const OrthancPluginExportedResource& resource) | |
432 { | |
433 Orthanc::ExportedResource tmp(resource.seq, | |
434 Orthanc::Plugins::Convert(resource.resourceType), | |
435 resource.publicId, | |
436 resource.modality, | |
437 resource.date, | |
438 resource.patientId, | |
439 resource.studyInstanceUid, | |
440 resource.seriesInstanceUid, | |
441 resource.sopInstanceUid); | |
442 | |
443 base_.LogExportedResource(tmp); | |
444 } | |
445 | |
446 | |
447 bool Database::LookupAttachment(int64_t id, | |
448 int32_t contentType) | |
449 { | |
450 Orthanc::FileInfo attachment; | |
451 if (base_.LookupAttachment(attachment, id, static_cast<Orthanc::FileContentType>(contentType))) | |
452 { | |
453 GetOutput().AnswerAttachment(attachment.GetUuid(), | |
454 attachment.GetContentType(), | |
455 attachment.GetUncompressedSize(), | |
456 attachment.GetUncompressedMD5(), | |
457 attachment.GetCompressionType(), | |
458 attachment.GetCompressedSize(), | |
459 attachment.GetCompressedMD5()); | |
460 return true; | |
461 } | |
462 else | |
463 { | |
464 return false; | |
465 } | |
466 } | |
467 | |
468 | |
469 bool Database::LookupParent(int64_t& parentId /*out*/, | |
470 int64_t resourceId) | |
471 { | |
472 bool found; | |
473 Orthanc::ErrorCode code = base_.LookupParent(found, parentId, resourceId); | |
474 | |
475 if (code == Orthanc::ErrorCode_Success) | |
476 { | |
477 return found; | |
478 } | |
479 else | |
480 { | |
481 throw OrthancPlugins::DatabaseException(static_cast<OrthancPluginErrorCode>(code)); | |
482 } | |
483 } | |
484 | |
485 | |
486 bool Database::LookupResource(int64_t& id /*out*/, | |
487 OrthancPluginResourceType& type /*out*/, | |
488 const char* publicId) | |
489 { | |
490 Orthanc::ResourceType tmp; | |
491 if (base_.LookupResource(id, tmp, publicId)) | |
492 { | |
493 type = Orthanc::Plugins::Convert(tmp); | |
494 return true; | |
495 } | |
496 else | |
497 { | |
498 return false; | |
499 } | |
500 } | |
501 | |
502 | |
503 void Database::StartTransaction() | |
504 { | |
505 transaction_.reset(new Orthanc::SQLite::Transaction(db_)); | |
506 transaction_->Begin(); | |
507 } | |
508 | |
509 | |
510 void Database::RollbackTransaction() | |
511 { | |
512 transaction_->Rollback(); | |
513 transaction_.reset(NULL); | |
514 } | |
515 | |
516 | |
517 void Database::CommitTransaction() | |
518 { | |
519 transaction_->Commit(); | |
520 transaction_.reset(NULL); | |
521 } | |
522 | |
523 | |
524 uint32_t Database::GetDatabaseVersion() | |
525 { | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
526 std::string version; |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
527 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
528 if (!LookupGlobalProperty(version, Orthanc::GlobalProperty_DatabaseSchemaVersion)) |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
529 { |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
530 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_InternalError); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
531 } |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
532 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
533 try |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
534 { |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
535 return boost::lexical_cast<uint32_t>(version); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
536 } |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
537 catch (boost::bad_lexical_cast&) |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
538 { |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
539 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_InternalError); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
540 } |
1671 | 541 } |
542 | |
543 | |
544 void Database::UpgradeDatabase(uint32_t targetVersion, | |
545 OrthancPluginStorageArea* storageArea) | |
546 { | |
1673
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
547 if (targetVersion == 6) |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
548 { |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
549 OrthancPluginErrorCode code = OrthancPluginReconstructMainDicomTags(GetOutput().GetContext(), storageArea, |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
550 OrthancPluginResourceType_Study); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
551 if (code == OrthancPluginErrorCode_Success) |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
552 { |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
553 code = OrthancPluginReconstructMainDicomTags(GetOutput().GetContext(), storageArea, |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
554 OrthancPluginResourceType_Series); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
555 } |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
556 |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
557 if (code != OrthancPluginErrorCode_Success) |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
558 { |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
559 throw OrthancPlugins::DatabaseException(code); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
560 } |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
561 |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
562 base_.SetGlobalProperty(Orthanc::GlobalProperty_DatabaseSchemaVersion, "6"); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
563 } |
1671 | 564 } |