changeset 1718:2b812969e136 db-changes

getting rid of an IDatabaseWrapper::LookupIdentifier flavor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 10:11:22 +0200
parents 3926e6317a43
children 3b1f7e706d38
files OrthancServer/DatabaseWrapper.h OrthancServer/DatabaseWrapperBase.cpp OrthancServer/DatabaseWrapperBase.h OrthancServer/IDatabaseWrapper.h OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h Plugins/Include/orthanc/OrthancCDatabasePlugin.h Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Plugins/Samples/DatabasePlugin/Database.h UnitTestsSources/ServerIndexTests.cpp
diffstat 13 files changed, 35 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- 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<int64_t>& target,
-                                  const std::string& value)
-    {
-      base_.LookupIdentifier(target, value);
-    }
-
     virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
                                 int64_t id);
 
--- 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<int64_t>& 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));
-    }
-  }
 }
--- 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<int64_t>& target,
                           const DicomTag& tag,
                           const std::string& value);
-
-    void LookupIdentifier(std::list<int64_t>& target,
-                          const std::string& value);
   };
 }
 
--- 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<int64_t>& target,
-                                  const std::string& value) = 0;
-
     virtual bool LookupMetadata(std::string& target,
                                 int64_t id,
                                 MetadataType type) = 0;
--- 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<ResourceType, std::string> >  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;
--- 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<ResourceType, std::string> >& 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<int64_t> id;
-    db_.LookupIdentifier(id, value);
+    db_.LookupIdentifier(id, tag, value);
 
     for (std::list<int64_t>::const_iterator 
            it = id.begin(); it != id.end(); ++it)
--- 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<FileInfo> Attachments;
     typedef std::map< std::pair<ResourceType, MetadataType>, std::string>  MetadataMap;
+    typedef std::list< std::pair<ResourceType, std::string> >  LookupResults;
 
   private:
     class Listener;
@@ -244,7 +245,8 @@
                           const DicomTag& tag,
                           const std::string& value);
 
-    void LookupIdentifier(std::list< std::pair<ResourceType, std::string> >& result,
+    void LookupIdentifier(LookupResults& result,
+                          const DicomTag& tag,
                           const std::string& value);
 
     StoreStatus AddAttachment(const FileInfo& attachment,
--- 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<int64_t>& 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)
--- 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<int64_t>& target,
-                                  const std::string& value);
-
     virtual bool LookupMetadata(std::string& target,
                                 int64_t id,
                                 MetadataType type);
--- 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,
--- 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<IDatabaseBackend*>(payload);
-      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
-
-      try
-      {
-        std::list<int64_t> target;
-        backend->LookupIdentifier(target, value);
-
-        for (std::list<int64_t>::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;
--- 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<int64_t>& target /*out*/,
-                                const char* value)
-  {
-    base_.LookupIdentifier(target, value);
-  }
-
   virtual bool LookupMetadata(std::string& target /*out*/,
                               int64_t id,
                               int32_t metadataType)
--- 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<std::string> s;