Mercurial > hg > orthanc
changeset 1673:0bbcfd9695e5 db-changes
UpgradeDatabase in the sample plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Oct 2015 13:26:05 +0200 |
parents | 4c5a85c3ff43 |
children | 4fc502d469f4 |
files | OrthancServer/ServerToolbox.cpp Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Plugins/Samples/DatabasePlugin/Database.cpp |
diffstat | 6 files changed, 68 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/ServerToolbox.cpp Fri Oct 02 12:20:49 2015 +0200 +++ b/OrthancServer/ServerToolbox.cpp Fri Oct 02 13:26:05 2015 +0200 @@ -33,9 +33,10 @@ #include "PrecompiledHeadersServer.h" #include "ServerToolbox.h" +#include "../Core/DicomFormat/DicomArray.h" +#include "../Core/FileStorage/StorageAccessor.h" #include "../Core/Logging.h" #include "../Core/OrthancException.h" -#include "../Core/DicomFormat/DicomArray.h" #include "ParsedDicomFile.h" #include <cassert> @@ -286,8 +287,10 @@ } // Read and parse the content of the DICOM file + StorageAccessor accessor(storageArea); + std::string content; - storageArea.Read(content, attachment.GetUuid(), FileContentType_Dicom); + accessor.Read(content, attachment); ParsedDicomFile dicom(content); @@ -306,7 +309,7 @@ case ResourceType_Study: Toolbox::SetMainDicomTags(database, resource, ResourceType_Study, dicomSummary, true); - // Duplicate the patient tags at the study level + // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) Toolbox::SetMainDicomTags(database, resource, ResourceType_Patient, dicomSummary, false); break;
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Fri Oct 02 12:20:49 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Fri Oct 02 13:26:05 2015 +0200 @@ -692,7 +692,7 @@ void OrthancPluginDatabase::ClearMainDicomTags(int64_t id) { - if (extensions_.clearMainDicomTags != NULL) + if (extensions_.clearMainDicomTags == NULL) { LOG(ERROR) << "Your custom index plugin does not implement the ClearMainDicomTags() extension"; throw OrthancException(ErrorCode_DatabasePlugin); @@ -848,9 +848,23 @@ { if (extensions_.upgradeDatabase != NULL) { - CheckSuccess(extensions_.upgradeDatabase( - payload_, targetVersion, - reinterpret_cast<OrthancPluginStorageArea*>(&storageArea))); + Transaction transaction(backend_, payload_, errorDictionary_); + transaction.Begin(); + + OrthancPluginErrorCode code = extensions_.upgradeDatabase( + payload_, targetVersion, + reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)); + + if (code == OrthancPluginErrorCode_Success) + { + transaction.Commit(); + } + else + { + transaction.Rollback(); + errorDictionary_.LogError(code, true); + throw OrthancException(static_cast<ErrorCode>(code)); + } } }
--- a/Plugins/Engine/OrthancPlugins.cpp Fri Oct 02 12:20:49 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Fri Oct 02 13:26:05 2015 +0200 @@ -1722,6 +1722,7 @@ IStorageArea& storage = *reinterpret_cast<IStorageArea*>(p.storageArea); Toolbox::ReconstructMainDicomTags(*pimpl_->database_, storage, Plugins::Convert(p.level)); + return true; }
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Fri Oct 02 12:20:49 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Fri Oct 02 13:26:05 2015 +0200 @@ -3775,6 +3775,22 @@ OrthancPluginResourceType level; } _OrthancPluginReconstructMainDicomTags; + /** + * @brief Reconstruct the main DICOM tags. + * + * This function requests the Orthanc core to reconstruct the main + * DICOM tags of all the resources of the given type. This function + * can only be used as a part of the upgrade of a custom database + * back-end + * (cf. OrthancPlugins::IDatabaseBackend::UpgradeDatabase). A + * database transaction will be automatically setup. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param storageArea The storage area. + * @param level The type of the resources of interest. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( OrthancPluginContext* context, OrthancPluginStorageArea* storageArea,
--- a/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Fri Oct 02 12:20:49 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Fri Oct 02 13:26:05 2015 +0200 @@ -122,6 +122,11 @@ { } + OrthancPluginContext* GetContext() + { + return context_; + } + void LogError(const std::string& message) { OrthancPluginLogError(context_, message.c_str()); @@ -456,6 +461,11 @@ virtual uint32_t GetDatabaseVersion() = 0; + /** + * Upgrade the database to the specified version of the database + * schema. The upgrade script is allowed to make calls to + * OrthancPluginReconstructMainDicomTags(). + **/ virtual void UpgradeDatabase(uint32_t targetVersion, OrthancPluginStorageArea* storageArea) = 0;
--- a/Plugins/Samples/DatabasePlugin/Database.cpp Fri Oct 02 12:20:49 2015 +0200 +++ b/Plugins/Samples/DatabasePlugin/Database.cpp Fri Oct 02 13:26:05 2015 +0200 @@ -540,4 +540,21 @@ void Database::UpgradeDatabase(uint32_t targetVersion, OrthancPluginStorageArea* storageArea) { + if (targetVersion == 6) + { + OrthancPluginErrorCode code = OrthancPluginReconstructMainDicomTags(GetOutput().GetContext(), storageArea, + OrthancPluginResourceType_Study); + if (code == OrthancPluginErrorCode_Success) + { + code = OrthancPluginReconstructMainDicomTags(GetOutput().GetContext(), storageArea, + OrthancPluginResourceType_Series); + } + + if (code != OrthancPluginErrorCode_Success) + { + throw OrthancPlugins::DatabaseException(code); + } + + base_.SetGlobalProperty(Orthanc::GlobalProperty_DatabaseSchemaVersion, "6"); + } }