changeset 521:2c739f76d0bb

lookup tag values
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Aug 2013 14:50:23 +0200
parents 1b2cdc855bd3
children 68451838fb2c d80376e73f52
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h UnitTests/ServerIndex.cpp
diffstat 5 files changed, 144 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Tue Aug 20 13:39:42 2013 +0200
+++ b/OrthancServer/DatabaseWrapper.cpp	Thu Aug 29 14:50:23 2013 +0200
@@ -958,4 +958,41 @@
     s.BindInt(0, internalId);
     return s.Step();
   }
+
+
+  void  DatabaseWrapper::LookupTagValue(std::list<int64_t>& result,
+                                        DicomTag tag,
+                                        const std::string& value)
+  {
+    SQLite::Statement s(db_, SQLITE_FROM_HERE, 
+                        "SELECT id FROM MainDicomTags WHERE tagGroup=? AND tagElement=? and value=?");
+
+    s.BindInt(0, tag.GetGroup());
+    s.BindInt(1, tag.GetElement());
+    s.BindString(2, value);
+
+    result.clear();
+
+    while (s.Step())
+    {
+      result.push_back(s.ColumnInt64(0));
+    }
+  }
+
+
+  void  DatabaseWrapper::LookupTagValue(std::list<int64_t>& result,
+                                        const std::string& value)
+  {
+    SQLite::Statement s(db_, SQLITE_FROM_HERE, 
+                        "SELECT id FROM MainDicomTags WHERE value=?");
+
+    s.BindString(0, value);
+
+    result.clear();
+
+    while (s.Step())
+    {
+      result.push_back(s.ColumnInt64(0));
+    }
+  }
 }
--- a/OrthancServer/DatabaseWrapper.h	Tue Aug 20 13:39:42 2013 +0200
+++ b/OrthancServer/DatabaseWrapper.h	Thu Aug 29 14:50:23 2013 +0200
@@ -225,5 +225,12 @@
     void ClearTable(const std::string& tableName);
 
     bool IsExistingResource(int64_t internalId);
+
+    void LookupTagValue(std::list<int64_t>& result,
+                        DicomTag tag,
+                        const std::string& value);
+
+    void LookupTagValue(std::list<int64_t>& result,
+                        const std::string& value);
   };
 }
--- a/OrthancServer/ServerIndex.cpp	Tue Aug 20 13:39:42 2013 +0200
+++ b/OrthancServer/ServerIndex.cpp	Thu Aug 29 14:50:23 2013 +0200
@@ -1468,4 +1468,42 @@
     unstableResources_.AddOrMakeMostRecent(id, type);
     //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id;
   }
+
+
+
+  void ServerIndex::LookupTagValue(std::list<std::string>& result,
+                                   DicomTag tag,
+                                   const std::string& value)
+  {
+    result.clear();
+
+    boost::mutex::scoped_lock lock(mutex_);
+
+    std::list<int64_t> id;
+    db_->LookupTagValue(id, tag, value);
+
+    for (std::list<int64_t>::const_iterator 
+           it = id.begin(); it != id.end(); it++)
+    {
+      result.push_back(db_->GetPublicId(*it));
+    }
+  }
+
+
+  void ServerIndex::LookupTagValue(std::list<std::string>& result,
+                                   const std::string& value)
+  {
+    result.clear();
+
+    boost::mutex::scoped_lock lock(mutex_);
+
+    std::list<int64_t> id;
+    db_->LookupTagValue(id, value);
+
+    for (std::list<int64_t>::const_iterator 
+           it = id.begin(); it != id.end(); it++)
+    {
+      result.push_back(db_->GetPublicId(*it));
+    }
+  }
 }
--- a/OrthancServer/ServerIndex.h	Tue Aug 20 13:39:42 2013 +0200
+++ b/OrthancServer/ServerIndex.h	Thu Aug 29 14:50:23 2013 +0200
@@ -186,5 +186,12 @@
 
     void GetStatistics(Json::Value& target,
                        const std::string& publicId);
+
+    void LookupTagValue(std::list<std::string>& result,
+                        DicomTag tag,
+                        const std::string& value);
+
+    void LookupTagValue(std::list<std::string>& result,
+                        const std::string& value);
   };
 }
--- a/UnitTests/ServerIndex.cpp	Tue Aug 20 13:39:42 2013 +0200
+++ b/UnitTests/ServerIndex.cpp	Thu Aug 29 14:50:23 2013 +0200
@@ -5,6 +5,7 @@
 
 #include <ctype.h>
 #include <glog/logging.h>
+#include <algorithm>
 
 using namespace Orthanc;
 
@@ -432,3 +433,57 @@
   ASSERT_EQ(3u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence));
   ASSERT_EQ(4u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence));
 }
+
+
+
+TEST(DatabaseWrapper, LookupTagValue)
+{
+  ServerIndexListener listener;
+  DatabaseWrapper index(listener);
+
+  int64_t a[] = {
+    index.CreateResource("a", ResourceType_Study),   // 0
+    index.CreateResource("b", ResourceType_Study),   // 1
+    index.CreateResource("c", ResourceType_Study),   // 2
+    index.CreateResource("d", ResourceType_Series)   // 3
+  };
+
+  DicomMap m;
+  m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "0"); index.SetMainDicomTags(a[0], m);
+  m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "1"); index.SetMainDicomTags(a[1], m);
+  m.Clear(); m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "0"); index.SetMainDicomTags(a[2], m);
+  m.Clear(); m.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "0"); index.SetMainDicomTags(a[3], m);
+
+  std::list<int64_t> s;
+
+  index.LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "0");
+  ASSERT_EQ(2u, 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.LookupTagValue(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());
+  ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end());
+
+  index.LookupTagValue(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.LookupTagValue(s, "1");
+  ASSERT_EQ(1u, s.size());
+  ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end());
+
+
+  /*{
+      std::list<std::string> s;
+      context.GetIndex().LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059");
+      for (std::list<std::string>::iterator i = s.begin(); i != s.end(); i++)
+      {
+        std::cout << "*** " << *i << std::endl;;
+      }      
+      }*/
+
+
+}