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