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