# HG changeset patch # User Sebastien Jodogne # Date 1445328682 -7200 # Node ID 2b812969e136fb0be6ba58ef4cb1b20a16bd0e8d # Parent 3926e6317a43ec5dea555445b8fb08f518b0ef98 getting rid of an IDatabaseWrapper::LookupIdentifier flavor diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/DatabaseWrapper.h Tue Oct 20 10:11:22 2015 +0200 @@ -319,12 +319,6 @@ const DicomTag& tag, const std::string& value); - virtual void LookupIdentifier(std::list& target, - const std::string& value) - { - base_.LookupIdentifier(target, value); - } - virtual void GetAllMetadata(std::map& target, int64_t id); diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/DatabaseWrapperBase.cpp --- a/OrthancServer/DatabaseWrapperBase.cpp Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/DatabaseWrapperBase.cpp Tue Oct 20 10:11:22 2015 +0200 @@ -683,21 +683,4 @@ target.push_back(s.ColumnInt64(0)); } } - - - void DatabaseWrapperBase::LookupIdentifier(std::list& target, - const std::string& value) - { - SQLite::Statement s(db_, SQLITE_FROM_HERE, - "SELECT id FROM DicomIdentifiers WHERE value=?"); - - s.BindString(0, value); - - target.clear(); - - while (s.Step()) - { - target.push_back(s.ColumnInt64(0)); - } - } } diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/DatabaseWrapperBase.h --- a/OrthancServer/DatabaseWrapperBase.h Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/DatabaseWrapperBase.h Tue Oct 20 10:11:22 2015 +0200 @@ -193,9 +193,6 @@ void LookupIdentifier(std::list& target, const DicomTag& tag, const std::string& value); - - void LookupIdentifier(std::list& target, - const std::string& value); }; } diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/IDatabaseWrapper.h --- a/OrthancServer/IDatabaseWrapper.h Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/IDatabaseWrapper.h Tue Oct 20 10:11:22 2015 +0200 @@ -150,9 +150,6 @@ const DicomTag& tag, const std::string& value) = 0; - virtual void LookupIdentifier(std::list& target, - const std::string& value) = 0; - virtual bool LookupMetadata(std::string& target, int64_t id, MetadataType type) = 0; diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Oct 20 10:11:22 2015 +0200 @@ -879,20 +879,32 @@ } + static void AccumulateLookupResults(ServerIndex::LookupResults& result, + ServerIndex& index, + const DicomTag& tag, + const std::string& value) + { + ServerIndex::LookupResults tmp; + index.LookupIdentifier(tmp, tag, value); + result.insert(result.end(), tmp.begin(), tmp.end()); + } + + static void Lookup(RestApiPostCall& call) { - typedef std::list< std::pair > Resources; - std::string tag; call.BodyToString(tag); - Resources resources; - - OrthancRestApi::GetIndex(call).LookupIdentifier(resources, tag); - Json::Value result = Json::arrayValue; - - for (Resources::const_iterator it = resources.begin(); - it != resources.end(); ++it) + ServerIndex::LookupResults resources; + ServerIndex& index = OrthancRestApi::GetIndex(call); + AccumulateLookupResults(resources, index, DICOM_TAG_PATIENT_ID, tag); + AccumulateLookupResults(resources, index, DICOM_TAG_STUDY_INSTANCE_UID, tag); + AccumulateLookupResults(resources, index, DICOM_TAG_SERIES_INSTANCE_UID, tag); + AccumulateLookupResults(resources, index, DICOM_TAG_SOP_INSTANCE_UID, tag); + + Json::Value result = Json::arrayValue; + for (ServerIndex::LookupResults::const_iterator + it = resources.begin(); it != resources.end(); ++it) { ResourceType type = it->first; const std::string& id = it->second; diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/ServerIndex.cpp Tue Oct 20 10:11:22 2015 +0200 @@ -1930,7 +1930,8 @@ } - void ServerIndex::LookupIdentifier(std::list< std::pair >& result, + void ServerIndex::LookupIdentifier(LookupResults& result, + const DicomTag& tag, const std::string& value) { result.clear(); @@ -1938,7 +1939,7 @@ boost::mutex::scoped_lock lock(mutex_); std::list id; - db_.LookupIdentifier(id, value); + db_.LookupIdentifier(id, tag, value); for (std::list::const_iterator it = id.begin(); it != id.end(); ++it) diff -r 3926e6317a43 -r 2b812969e136 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Mon Oct 19 17:45:34 2015 +0200 +++ b/OrthancServer/ServerIndex.h Tue Oct 20 10:11:22 2015 +0200 @@ -52,6 +52,7 @@ public: typedef std::list Attachments; typedef std::map< std::pair, std::string> MetadataMap; + typedef std::list< std::pair > LookupResults; private: class Listener; @@ -244,7 +245,8 @@ const DicomTag& tag, const std::string& value); - void LookupIdentifier(std::list< std::pair >& result, + void LookupIdentifier(LookupResults& result, + const DicomTag& tag, const std::string& value); StoreStatus AddAttachment(const FileInfo& attachment, diff -r 3926e6317a43 -r 2b812969e136 Plugins/Engine/OrthancPluginDatabase.cpp --- a/Plugins/Engine/OrthancPluginDatabase.cpp Mon Oct 19 17:45:34 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Tue Oct 20 10:11:22 2015 +0200 @@ -611,15 +611,6 @@ } - void OrthancPluginDatabase::LookupIdentifier(std::list& target, - const std::string& value) - { - ResetAnswers(); - CheckSuccess(backend_.lookupIdentifier2(GetContext(), payload_, value.c_str())); - ForwardAnswers(target); - } - - bool OrthancPluginDatabase::LookupMetadata(std::string& target, int64_t id, MetadataType type) diff -r 3926e6317a43 -r 2b812969e136 Plugins/Engine/OrthancPluginDatabase.h --- a/Plugins/Engine/OrthancPluginDatabase.h Mon Oct 19 17:45:34 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.h Tue Oct 20 10:11:22 2015 +0200 @@ -207,9 +207,6 @@ const DicomTag& tag, const std::string& value); - virtual void LookupIdentifier(std::list& target, - const std::string& value); - virtual bool LookupMetadata(std::string& target, int64_t id, MetadataType type); diff -r 3926e6317a43 -r 2b812969e136 Plugins/Include/orthanc/OrthancCDatabasePlugin.h --- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Mon Oct 19 17:45:34 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Tue Oct 20 10:11:22 2015 +0200 @@ -530,7 +530,8 @@ void* payload, const OrthancPluginDicomTag* tag); - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + /* Unused starting with Orthanc 0.9.5 (db v6), can be set to NULL. + Output: Use OrthancPluginDatabaseAnswerInt64() */ OrthancPluginErrorCode (*lookupIdentifier2) ( /* outputs */ OrthancPluginDatabaseContext* context, diff -r 3926e6317a43 -r 2b812969e136 Plugins/Include/orthanc/OrthancCppDatabasePlugin.h --- a/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Mon Oct 19 17:45:34 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Tue Oct 20 10:11:22 2015 +0200 @@ -1331,39 +1331,6 @@ } - static OrthancPluginErrorCode LookupIdentifier2(OrthancPluginDatabaseContext* context, - void* payload, - const char* value) - { - IDatabaseBackend* backend = reinterpret_cast(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list target; - backend->LookupIdentifier(target, value); - - for (std::list::const_iterator - it = target.begin(); it != target.end(); ++it) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, *it); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - static OrthancPluginErrorCode LookupMetadata(OrthancPluginDatabaseContext* context, void* payload, int64_t id, @@ -1861,7 +1828,7 @@ params.lookupAttachment = LookupAttachment; params.lookupGlobalProperty = LookupGlobalProperty; params.lookupIdentifier = LookupIdentifier; - params.lookupIdentifier2 = LookupIdentifier2; + params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) params.lookupMetadata = LookupMetadata; params.lookupParent = LookupParent; params.lookupResource = LookupResource; diff -r 3926e6317a43 -r 2b812969e136 Plugins/Samples/DatabasePlugin/Database.h --- a/Plugins/Samples/DatabasePlugin/Database.h Mon Oct 19 17:45:34 2015 +0200 +++ b/Plugins/Samples/DatabasePlugin/Database.h Tue Oct 20 10:11:22 2015 +0200 @@ -195,12 +195,6 @@ base_.LookupIdentifier(target, Orthanc::DicomTag(group, element), value); } - virtual void LookupIdentifier(std::list& target /*out*/, - const char* value) - { - base_.LookupIdentifier(target, value); - } - virtual bool LookupMetadata(std::string& target /*out*/, int64_t id, int32_t metadataType) diff -r 3926e6317a43 -r 2b812969e136 UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Mon Oct 19 17:45:34 2015 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Tue Oct 20 10:11:22 2015 +0200 @@ -698,20 +698,20 @@ ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); - index_->LookupIdentifier(s, "0"); - ASSERT_EQ(3u, s.size()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); + index_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "0"); + ASSERT_EQ(1u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end()); index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); ASSERT_EQ(1u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); - index_->LookupIdentifier(s, "1"); + index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); ASSERT_EQ(1u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); + index_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "1"); + ASSERT_EQ(0u, s.size()); /*{ std::list s;