Mercurial > hg > orthanc-databases
changeset 403:91124cc8a8c7 db-protobuf
database plugins are informed about the identifier tags
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV2.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV2.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -90,7 +90,8 @@ if (manager_.get() == NULL) { - manager_.reset(IndexBackend::CreateSingleDatabaseManager(*backend_)); + std::list<IdentifierTag> identifierTags; + manager_.reset(IndexBackend::CreateSingleDatabaseManager(*backend_, false, identifierTags)); } else {
--- a/Framework/Plugins/DatabaseBackendAdapterV3.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV3.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -800,7 +800,8 @@ try { - pool->OpenConnections(); + std::list<IdentifierTag> identifierTags; + pool->OpenConnections(false, identifierTags); return OrthancPluginErrorCode_Success; } ORTHANC_PLUGINS_DATABASE_CATCH(pool->GetContext());
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -90,6 +90,28 @@ } + static Orthanc::ResourceType Convert2(Orthanc::DatabasePluginMessages::ResourceType resourceType) + { + switch (resourceType) + { + case Orthanc::DatabasePluginMessages::RESOURCE_PATIENT: + return Orthanc::ResourceType_Patient; + + case Orthanc::DatabasePluginMessages::RESOURCE_STUDY: + return Orthanc::ResourceType_Study; + + case Orthanc::DatabasePluginMessages::RESOURCE_SERIES: + return Orthanc::ResourceType_Series; + + case Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE: + return Orthanc::ResourceType_Instance; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + + class Output : public IDatabaseBackendOutput { private: @@ -414,7 +436,24 @@ case Orthanc::DatabasePluginMessages::OPERATION_OPEN: { - pool.OpenConnections(); + std::list<IdentifierTag> identifierTags; + + if (request.open().identifier_tags().empty()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, + "No identifier tag was provided by the Orthanc core"); + } + + for (int i = 0; i < request.open().identifier_tags().size(); i++) + { + const Orthanc::DatabasePluginMessages::Open_Request_IdentifierTag& tag = request.open().identifier_tags(i); + identifierTags.push_back(IdentifierTag(Convert2(tag.level()), + Orthanc::DicomTag(tag.group(), tag.element()), + tag.name())); + } + + pool.OpenConnections(true, identifierTags); + break; }
--- a/Framework/Plugins/IDatabaseBackend.h Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/IDatabaseBackend.h Tue Apr 11 11:10:19 2023 +0200 @@ -27,6 +27,7 @@ #include "../Common/DatabaseManager.h" #include "../Common/DatabasesEnumerations.h" #include "IDatabaseBackendOutput.h" +#include "IdentifierTag.h" #include <list> @@ -43,8 +44,13 @@ virtual IDatabaseFactory* CreateDatabaseFactory() = 0; - // This function is invoked once, even if multiple connections are open - virtual void ConfigureDatabase(DatabaseManager& database) = 0; + /** + * This function is invoked once, even if multiple connections are + * open. It is notably used to update the schema of the database. + **/ + virtual void ConfigureDatabase(DatabaseManager& database, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) = 0; virtual void SetOutputFactory(IDatabaseBackendOutput::IFactory* factory) = 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Plugins/IdentifierTag.h Tue Apr 11 11:10:19 2023 +0200 @@ -0,0 +1,62 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2023 Osimis S.A., Belgium + * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + + +#pragma once + +#include <DicomFormat/DicomTag.h> + +namespace OrthancDatabases +{ + class IdentifierTag + { + private: + Orthanc::ResourceType level_; + Orthanc::DicomTag tag_; + std::string name_; + + public: + IdentifierTag(Orthanc::ResourceType level, + const Orthanc::DicomTag& tag, + const std::string& name) : + level_(level), + tag_(tag), + name_(name) + { + } + + Orthanc::ResourceType GetLevel() const + { + return level_; + } + + const Orthanc::DicomTag& GetTag() const + { + return tag_; + } + + const std::string& GetName() const + { + return name_; + } + }; +}
--- a/Framework/Plugins/IndexBackend.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/IndexBackend.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -2792,10 +2792,12 @@ } - DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend) + DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) { std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend.CreateDatabaseFactory())); - backend.ConfigureDatabase(*manager); + backend.ConfigureDatabase(*manager, hasIdentifierTags, identifierTags); return manager.release(); } }
--- a/Framework/Plugins/IndexBackend.h Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/IndexBackend.h Tue Apr 11 11:10:19 2023 +0200 @@ -408,6 +408,8 @@ static void Finalize(); - static DatabaseManager* CreateSingleDatabaseManager(IDatabaseBackend& backend); + static DatabaseManager* CreateSingleDatabaseManager(IDatabaseBackend& backend, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags); }; }
--- a/Framework/Plugins/IndexConnectionsPool.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/IndexConnectionsPool.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -75,7 +75,8 @@ } - void IndexConnectionsPool::OpenConnections() + void IndexConnectionsPool::OpenConnections(bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) { boost::unique_lock<boost::shared_mutex> lock(connectionsMutex_); @@ -87,7 +88,7 @@ std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend_->CreateDatabaseFactory())); manager->GetDatabase(); // Make sure to open the database connection - backend_->ConfigureDatabase(*manager); + backend_->ConfigureDatabase(*manager, hasIdentifierTags, identifierTags); connections_.push_back(manager.release()); }
--- a/Framework/Plugins/IndexConnectionsPool.h Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/IndexConnectionsPool.h Tue Apr 11 11:10:19 2023 +0200 @@ -22,6 +22,7 @@ #pragma once +#include "IdentifierTag.h" #include "IndexBackend.h" #include <MultiThreading/SharedMessageQueue.h> @@ -53,7 +54,8 @@ return context_; } - void OpenConnections(); + void OpenConnections(bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags); void CloseConnections();
--- a/Framework/Plugins/IndexUnitTests.h Sat Apr 08 10:26:03 2023 +0200 +++ b/Framework/Plugins/IndexUnitTests.h Tue Apr 11 11:10:19 2023 +0200 @@ -246,7 +246,8 @@ db.SetOutputFactory(new DatabaseBackendAdapterV2::Factory(&context, NULL)); - std::unique_ptr<DatabaseManager> manager(IndexBackend::CreateSingleDatabaseManager(db)); + std::list<IdentifierTag> identifierTags; + std::unique_ptr<DatabaseManager> manager(IndexBackend::CreateSingleDatabaseManager(db, false, identifierTags)); std::unique_ptr<IDatabaseBackendOutput> output(db.CreateOutput());
--- a/MySQL/Plugins/MySQLIndex.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/MySQL/Plugins/MySQLIndex.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -63,7 +63,9 @@ } - void MySQLIndex::ConfigureDatabase(DatabaseManager& manager) + void MySQLIndex::ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) { uint32_t expectedVersion = 6;
--- a/MySQL/Plugins/MySQLIndex.h Sat Apr 08 10:26:03 2023 +0200 +++ b/MySQL/Plugins/MySQLIndex.h Tue Apr 11 11:10:19 2023 +0200 @@ -44,7 +44,9 @@ virtual IDatabaseFactory* CreateDatabaseFactory() ORTHANC_OVERRIDE; - virtual void ConfigureDatabase(DatabaseManager& database) ORTHANC_OVERRIDE; + virtual void ConfigureDatabase(DatabaseManager& database, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) ORTHANC_OVERRIDE; virtual bool HasRevisionsSupport() const ORTHANC_OVERRIDE {
--- a/MySQL/UnitTests/UnitTestsMain.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/MySQL/UnitTests/UnitTestsMain.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -51,19 +51,21 @@ OrthancDatabases::MySQLIndex db1(NULL, noLock); db1.SetClearAll(true); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1)); + std::list<OrthancDatabases::IdentifierTag> identifierTags; + + std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1, false, identifierTags)); { OrthancDatabases::MySQLIndex db2(NULL, lock); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2, false, identifierTags)); OrthancDatabases::MySQLIndex db3(NULL, lock); - ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3), Orthanc::OrthancException); + ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3, false, identifierTags), Orthanc::OrthancException); } OrthancDatabases::MySQLIndex db4(NULL, lock); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4, false, identifierTags)); }
--- a/Odbc/Plugins/OdbcIndex.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/Odbc/Plugins/OdbcIndex.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -162,7 +162,9 @@ } - void OdbcIndex::ConfigureDatabase(DatabaseManager& manager) + void OdbcIndex::ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) { uint32_t expectedVersion = 6;
--- a/Odbc/Plugins/OdbcIndex.h Sat Apr 08 10:26:03 2023 +0200 +++ b/Odbc/Plugins/OdbcIndex.h Tue Apr 11 11:10:19 2023 +0200 @@ -56,7 +56,9 @@ virtual IDatabaseFactory* CreateDatabaseFactory() ORTHANC_OVERRIDE; - virtual void ConfigureDatabase(DatabaseManager& manager) ORTHANC_OVERRIDE; + virtual void ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) ORTHANC_OVERRIDE; virtual bool HasRevisionsSupport() const ORTHANC_OVERRIDE {
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -61,7 +61,9 @@ } - void PostgreSQLIndex::ConfigureDatabase(DatabaseManager& manager) + void PostgreSQLIndex::ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) { uint32_t expectedVersion = 6;
--- a/PostgreSQL/Plugins/PostgreSQLIndex.h Sat Apr 08 10:26:03 2023 +0200 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.h Tue Apr 11 11:10:19 2023 +0200 @@ -44,7 +44,9 @@ virtual IDatabaseFactory* CreateDatabaseFactory() ORTHANC_OVERRIDE; - virtual void ConfigureDatabase(DatabaseManager& manager) ORTHANC_OVERRIDE; + virtual void ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) ORTHANC_OVERRIDE; virtual bool HasRevisionsSupport() const ORTHANC_OVERRIDE {
--- a/PostgreSQL/UnitTests/PostgreSQLTests.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/PostgreSQL/UnitTests/PostgreSQLTests.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -542,7 +542,8 @@ OrthancDatabases::PostgreSQLIndex db(NULL, globalParameters_); db.SetClearAll(true); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db)); + std::list<OrthancDatabases::IdentifierTag> tags; + std::unique_ptr<OrthancDatabases::DatabaseManager> manager(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db, false, tags)); std::string s; ASSERT_TRUE(db.LookupGlobalProperty(s, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal1));
--- a/PostgreSQL/UnitTests/UnitTestsMain.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/PostgreSQL/UnitTests/UnitTestsMain.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -95,18 +95,19 @@ OrthancDatabases::PostgreSQLIndex db1(NULL, noLock); db1.SetClearAll(true); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1)); + std::list<OrthancDatabases::IdentifierTag> identifierTags; + std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1, false, identifierTags)); { OrthancDatabases::PostgreSQLIndex db2(NULL, lock); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2, false, identifierTags)); OrthancDatabases::PostgreSQLIndex db3(NULL, lock); - ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3), Orthanc::OrthancException); + ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3, false, identifierTags), Orthanc::OrthancException); } OrthancDatabases::PostgreSQLIndex db4(NULL, lock); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4, false, identifierTags)); }
--- a/SQLite/Plugins/SQLiteIndex.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/SQLite/Plugins/SQLiteIndex.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -85,7 +85,9 @@ } - void SQLiteIndex::ConfigureDatabase(DatabaseManager& manager) + void SQLiteIndex::ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) { uint32_t expectedVersion = 6;
--- a/SQLite/Plugins/SQLiteIndex.h Sat Apr 08 10:26:03 2023 +0200 +++ b/SQLite/Plugins/SQLiteIndex.h Tue Apr 11 11:10:19 2023 +0200 @@ -45,7 +45,9 @@ virtual IDatabaseFactory* CreateDatabaseFactory() ORTHANC_OVERRIDE; - virtual void ConfigureDatabase(DatabaseManager& manager) ORTHANC_OVERRIDE; + virtual void ConfigureDatabase(DatabaseManager& manager, + bool hasIdentifierTags, + const std::list<IdentifierTag>& identifierTags) ORTHANC_OVERRIDE; virtual bool HasRevisionsSupport() const ORTHANC_OVERRIDE {
--- a/SQLite/UnitTests/UnitTestsMain.cpp Sat Apr 08 10:26:03 2023 +0200 +++ b/SQLite/UnitTests/UnitTestsMain.cpp Tue Apr 11 11:10:19 2023 +0200 @@ -35,28 +35,30 @@ TEST(SQLiteIndex, Lock) { + std::list<OrthancDatabases::IdentifierTag> identifierTags; + { // No locking if using memory backend OrthancDatabases::SQLiteIndex db1(NULL); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1, false, identifierTags)); OrthancDatabases::SQLiteIndex db2(NULL); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2, false, identifierTags)); } Orthanc::SystemToolbox::RemoveFile("index.db"); { OrthancDatabases::SQLiteIndex db1(NULL, "index.db"); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1, false, identifierTags)); OrthancDatabases::SQLiteIndex db2(NULL, "index.db"); - ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2), Orthanc::OrthancException); + ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2, false, identifierTags), Orthanc::OrthancException); } { OrthancDatabases::SQLiteIndex db3(NULL, "index.db"); - std::unique_ptr<OrthancDatabases::DatabaseManager> manager3(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3)); + std::unique_ptr<OrthancDatabases::DatabaseManager> manager3(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3, false, identifierTags)); } }