Mercurial > hg > orthanc
annotate Plugins/Samples/DatabasePlugin/Database.cpp @ 1761:f4286d99ee0a db-changes
fix sample database plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Oct 2015 11:22:48 +0100 |
parents | 3926e6317a43 |
children | 559956d5ceb2 |
rev | line source |
---|---|
1671 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
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() : | |
126 hasRemainingAncestor_(false) | |
127 { | |
128 } | |
129 | |
130 void Reset() | |
131 { | |
132 hasRemainingAncestor_ = false; | |
133 } | |
134 | |
135 virtual const char* GetName() const | |
136 { | |
137 return "SignalRemainingAncestor"; | |
138 } | |
139 | |
140 virtual unsigned int GetCardinality() const | |
141 { | |
142 return 2; | |
143 } | |
144 | |
145 virtual void Compute(Orthanc::SQLite::FunctionContext& context) | |
146 { | |
147 if (!hasRemainingAncestor_ || | |
148 remainingType_ >= context.GetIntValue(1)) | |
149 { | |
150 hasRemainingAncestor_ = true; | |
151 remainingPublicId_ = context.GetStringValue(0); | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
152 remainingType_ = Orthanc::Plugins::Convert(static_cast<Orthanc::ResourceType>(context.GetIntValue(1))); |
1671 | 153 } |
154 } | |
155 | |
156 bool HasRemainingAncestor() const | |
157 { | |
158 return hasRemainingAncestor_; | |
159 } | |
160 | |
161 const std::string& GetRemainingAncestorId() const | |
162 { | |
163 assert(hasRemainingAncestor_); | |
164 return remainingPublicId_; | |
165 } | |
166 | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
167 OrthancPluginResourceType GetRemainingAncestorType() const |
1671 | 168 { |
169 assert(hasRemainingAncestor_); | |
170 return remainingType_; | |
171 } | |
172 }; | |
173 | |
174 | |
175 | |
176 Database::Database(const std::string& path) : | |
177 path_(path), | |
178 base_(db_) | |
179 { | |
180 } | |
181 | |
182 | |
183 void Database::Open() | |
184 { | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
185 db_.Open(path_); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
186 |
1717
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1673
diff
changeset
|
187 db_.Execute("PRAGMA ENCODING=\"UTF-8\";"); |
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1673
diff
changeset
|
188 |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
189 // http://www.sqlite.org/pragma.html |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
190 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
191 db_.Execute("PRAGMA JOURNAL_MODE=WAL;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
192 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
193 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
194 //db_.Execute("PRAGMA TEMP_STORE=memory"); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
195 |
1671 | 196 if (!db_.DoesTableExist("GlobalProperties")) |
197 { | |
198 std::string query; | |
199 Orthanc::EmbeddedResources::GetFileResource(query, Orthanc::EmbeddedResources::PREPARE_DATABASE); | |
200 db_.Execute(query); | |
201 } | |
202 | |
203 signalRemainingAncestor_ = new SignalRemainingAncestor; | |
204 db_.Register(signalRemainingAncestor_); | |
205 db_.Register(new Internals::SignalFileDeleted(GetOutput())); | |
206 db_.Register(new Internals::SignalResourceDeleted(GetOutput())); | |
207 } | |
208 | |
209 | |
210 void Database::Close() | |
211 { | |
212 db_.Close(); | |
213 } | |
214 | |
215 | |
216 void Database::AddAttachment(int64_t id, | |
217 const OrthancPluginAttachment& attachment) | |
218 { | |
219 Orthanc::FileInfo info(attachment.uuid, | |
220 static_cast<Orthanc::FileContentType>(attachment.contentType), | |
221 attachment.uncompressedSize, | |
222 attachment.uncompressedHash, | |
223 static_cast<Orthanc::CompressionType>(attachment.compressionType), | |
224 attachment.compressedSize, | |
225 attachment.compressedHash); | |
226 base_.AddAttachment(id, info); | |
227 } | |
228 | |
229 | |
230 void Database::DeleteResource(int64_t id) | |
231 { | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
232 signalRemainingAncestor_->Reset(); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
233 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
234 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
|
235 s.BindInt64(0, id); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
236 s.Run(); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
237 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
238 if (signalRemainingAncestor_->HasRemainingAncestor()) |
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 GetOutput().SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorId(), |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
241 signalRemainingAncestor_->GetRemainingAncestorType()); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
242 } |
1671 | 243 } |
244 | |
245 | |
246 static void Answer(OrthancPlugins::DatabaseBackendOutput& output, | |
247 const Orthanc::ServerIndexChange& change) | |
248 { | |
249 output.AnswerChange(change.GetSeq(), | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
250 change.GetChangeType(), |
1671 | 251 Orthanc::Plugins::Convert(change.GetResourceType()), |
252 change.GetPublicId(), | |
253 change.GetDate()); | |
254 } | |
255 | |
256 | |
257 static void Answer(OrthancPlugins::DatabaseBackendOutput& output, | |
258 const Orthanc::ExportedResource& resource) | |
259 { | |
260 output.AnswerExportedResource(resource.GetSeq(), | |
261 Orthanc::Plugins::Convert(resource.GetResourceType()), | |
262 resource.GetPublicId(), | |
263 resource.GetModality(), | |
264 resource.GetDate(), | |
265 resource.GetPatientId(), | |
266 resource.GetStudyInstanceUid(), | |
267 resource.GetSeriesInstanceUid(), | |
268 resource.GetSopInstanceUid()); | |
269 } | |
270 | |
271 | |
272 void Database::GetChanges(bool& done /*out*/, | |
273 int64_t since, | |
274 uint32_t maxResults) | |
275 { | |
276 typedef std::list<Orthanc::ServerIndexChange> Changes; | |
277 | |
278 Changes changes; | |
279 base_.GetChanges(changes, done, since, maxResults); | |
280 | |
281 for (Changes::const_iterator it = changes.begin(); it != changes.end(); ++it) | |
282 { | |
283 Answer(GetOutput(), *it); | |
284 } | |
285 } | |
286 | |
287 | |
288 void Database::GetExportedResources(bool& done /*out*/, | |
289 int64_t since, | |
290 uint32_t maxResults) | |
291 { | |
292 typedef std::list<Orthanc::ExportedResource> Resources; | |
293 | |
294 Resources resources; | |
295 base_.GetExportedResources(resources, done, since, maxResults); | |
296 | |
297 for (Resources::const_iterator it = resources.begin(); it != resources.end(); ++it) | |
298 { | |
299 Answer(GetOutput(), *it); | |
300 } | |
301 } | |
302 | |
303 | |
304 void Database::GetLastChange() | |
305 { | |
306 std::list<Orthanc::ServerIndexChange> change; | |
307 Orthanc::ErrorCode code = base_.GetLastChange(change); | |
308 | |
309 if (code != Orthanc::ErrorCode_Success) | |
310 { | |
311 throw OrthancPlugins::DatabaseException(static_cast<OrthancPluginErrorCode>(code)); | |
312 } | |
313 | |
314 if (!change.empty()) | |
315 { | |
316 Answer(GetOutput(), change.front()); | |
317 } | |
318 } | |
319 | |
320 | |
321 void Database::GetLastExportedResource() | |
322 { | |
323 std::list<Orthanc::ExportedResource> resource; | |
324 base_.GetLastExportedResource(resource); | |
325 | |
326 if (!resource.empty()) | |
327 { | |
328 Answer(GetOutput(), resource.front()); | |
329 } | |
330 } | |
331 | |
332 | |
333 void Database::GetMainDicomTags(int64_t id) | |
334 { | |
335 Orthanc::DicomMap tags; | |
336 base_.GetMainDicomTags(tags, id); | |
337 | |
338 Orthanc::DicomArray arr(tags); | |
339 for (size_t i = 0; i < arr.GetSize(); i++) | |
340 { | |
341 GetOutput().AnswerDicomTag(arr.GetElement(i).GetTag().GetGroup(), | |
342 arr.GetElement(i).GetTag().GetElement(), | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1717
diff
changeset
|
343 arr.GetElement(i).GetValue().GetContent()); |
1671 | 344 } |
345 } | |
346 | |
347 | |
348 std::string Database::GetPublicId(int64_t resourceId) | |
349 { | |
350 std::string id; | |
351 if (base_.GetPublicId(id, resourceId)) | |
352 { | |
353 return id; | |
354 } | |
355 else | |
356 { | |
357 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_UnknownResource); | |
358 } | |
359 } | |
360 | |
361 | |
362 OrthancPluginResourceType Database::GetResourceType(int64_t resourceId) | |
363 { | |
364 Orthanc::ResourceType result; | |
365 Orthanc::ErrorCode code = base_.GetResourceType(result, resourceId); | |
366 | |
367 if (code == Orthanc::ErrorCode_Success) | |
368 { | |
369 return Orthanc::Plugins::Convert(result); | |
370 } | |
371 else | |
372 { | |
373 throw OrthancPlugins::DatabaseException(static_cast<OrthancPluginErrorCode>(code)); | |
374 } | |
375 } | |
376 | |
377 | |
378 | |
379 template <typename I> | |
380 static void ConvertList(std::list<int32_t>& target, | |
381 const std::list<I>& source) | |
382 { | |
383 for (typename std::list<I>::const_iterator | |
384 it = source.begin(); it != source.end(); it++) | |
385 { | |
386 target.push_back(*it); | |
387 } | |
388 } | |
389 | |
390 | |
391 void Database::ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
392 int64_t id) | |
393 { | |
394 std::list<Orthanc::MetadataType> tmp; | |
395 base_.ListAvailableMetadata(tmp, id); | |
396 ConvertList(target, tmp); | |
397 } | |
398 | |
399 | |
400 void Database::ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
401 int64_t id) | |
402 { | |
403 std::list<Orthanc::FileContentType> tmp; | |
404 base_.ListAvailableAttachments(tmp, id); | |
405 ConvertList(target, tmp); | |
406 } | |
407 | |
408 | |
409 void Database::LogChange(const OrthancPluginChange& change) | |
410 { | |
411 int64_t id; | |
412 OrthancPluginResourceType type; | |
413 if (!LookupResource(id, type, change.publicId) || | |
414 type != change.resourceType) | |
415 { | |
416 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_DatabasePlugin); | |
417 } | |
418 | |
419 Orthanc::ServerIndexChange tmp(change.seq, | |
420 static_cast<Orthanc::ChangeType>(change.changeType), | |
421 Orthanc::Plugins::Convert(change.resourceType), | |
422 change.publicId, | |
423 change.date); | |
424 | |
425 base_.LogChange(id, tmp); | |
426 } | |
427 | |
428 | |
429 void Database::LogExportedResource(const OrthancPluginExportedResource& resource) | |
430 { | |
431 Orthanc::ExportedResource tmp(resource.seq, | |
432 Orthanc::Plugins::Convert(resource.resourceType), | |
433 resource.publicId, | |
434 resource.modality, | |
435 resource.date, | |
436 resource.patientId, | |
437 resource.studyInstanceUid, | |
438 resource.seriesInstanceUid, | |
439 resource.sopInstanceUid); | |
440 | |
441 base_.LogExportedResource(tmp); | |
442 } | |
443 | |
444 | |
445 bool Database::LookupAttachment(int64_t id, | |
446 int32_t contentType) | |
447 { | |
448 Orthanc::FileInfo attachment; | |
449 if (base_.LookupAttachment(attachment, id, static_cast<Orthanc::FileContentType>(contentType))) | |
450 { | |
451 GetOutput().AnswerAttachment(attachment.GetUuid(), | |
452 attachment.GetContentType(), | |
453 attachment.GetUncompressedSize(), | |
454 attachment.GetUncompressedMD5(), | |
455 attachment.GetCompressionType(), | |
456 attachment.GetCompressedSize(), | |
457 attachment.GetCompressedMD5()); | |
458 return true; | |
459 } | |
460 else | |
461 { | |
462 return false; | |
463 } | |
464 } | |
465 | |
466 | |
467 bool Database::LookupParent(int64_t& parentId /*out*/, | |
468 int64_t resourceId) | |
469 { | |
470 bool found; | |
471 Orthanc::ErrorCode code = base_.LookupParent(found, parentId, resourceId); | |
472 | |
473 if (code == Orthanc::ErrorCode_Success) | |
474 { | |
475 return found; | |
476 } | |
477 else | |
478 { | |
479 throw OrthancPlugins::DatabaseException(static_cast<OrthancPluginErrorCode>(code)); | |
480 } | |
481 } | |
482 | |
483 | |
484 bool Database::LookupResource(int64_t& id /*out*/, | |
485 OrthancPluginResourceType& type /*out*/, | |
486 const char* publicId) | |
487 { | |
488 Orthanc::ResourceType tmp; | |
489 if (base_.LookupResource(id, tmp, publicId)) | |
490 { | |
491 type = Orthanc::Plugins::Convert(tmp); | |
492 return true; | |
493 } | |
494 else | |
495 { | |
496 return false; | |
497 } | |
498 } | |
499 | |
500 | |
501 void Database::StartTransaction() | |
502 { | |
503 transaction_.reset(new Orthanc::SQLite::Transaction(db_)); | |
504 transaction_->Begin(); | |
505 } | |
506 | |
507 | |
508 void Database::RollbackTransaction() | |
509 { | |
510 transaction_->Rollback(); | |
511 transaction_.reset(NULL); | |
512 } | |
513 | |
514 | |
515 void Database::CommitTransaction() | |
516 { | |
517 transaction_->Commit(); | |
518 transaction_.reset(NULL); | |
519 } | |
520 | |
521 | |
522 uint32_t Database::GetDatabaseVersion() | |
523 { | |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
524 std::string version; |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
525 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
526 if (!LookupGlobalProperty(version, Orthanc::GlobalProperty_DatabaseSchemaVersion)) |
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 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_InternalError); |
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 |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
531 try |
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 return boost::lexical_cast<uint32_t>(version); |
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 catch (boost::bad_lexical_cast&) |
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 throw OrthancPlugins::DatabaseException(OrthancPluginErrorCode_InternalError); |
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
538 } |
1671 | 539 } |
540 | |
541 | |
542 void Database::UpgradeDatabase(uint32_t targetVersion, | |
543 OrthancPluginStorageArea* storageArea) | |
544 { | |
1673
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
545 if (targetVersion == 6) |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
546 { |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
547 OrthancPluginErrorCode code = OrthancPluginReconstructMainDicomTags(GetOutput().GetContext(), storageArea, |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
548 OrthancPluginResourceType_Study); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
549 if (code == OrthancPluginErrorCode_Success) |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
550 { |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
551 code = OrthancPluginReconstructMainDicomTags(GetOutput().GetContext(), storageArea, |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
552 OrthancPluginResourceType_Series); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
553 } |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
554 |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
555 if (code != OrthancPluginErrorCode_Success) |
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 throw OrthancPlugins::DatabaseException(code); |
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 |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
560 base_.SetGlobalProperty(Orthanc::GlobalProperty_DatabaseSchemaVersion, "6"); |
0bbcfd9695e5
UpgradeDatabase in the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1672
diff
changeset
|
561 } |
1671 | 562 } |