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