# HG changeset patch # User Sebastien Jodogne # Date 1377780623 -7200 # Node ID 2c739f76d0bb5e3ddf71515b6538990ab7ea3b00 # Parent 1b2cdc855bd3121a302fc34498f09e43b795da4e lookup tag values diff -r 1b2cdc855bd3 -r 2c739f76d0bb OrthancServer/DatabaseWrapper.cpp --- 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& 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& 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)); + } + } } diff -r 1b2cdc855bd3 -r 2c739f76d0bb OrthancServer/DatabaseWrapper.h --- 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& result, + DicomTag tag, + const std::string& value); + + void LookupTagValue(std::list& result, + const std::string& value); }; } diff -r 1b2cdc855bd3 -r 2c739f76d0bb OrthancServer/ServerIndex.cpp --- 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& result, + DicomTag tag, + const std::string& value) + { + result.clear(); + + boost::mutex::scoped_lock lock(mutex_); + + std::list id; + db_->LookupTagValue(id, tag, value); + + for (std::list::const_iterator + it = id.begin(); it != id.end(); it++) + { + result.push_back(db_->GetPublicId(*it)); + } + } + + + void ServerIndex::LookupTagValue(std::list& result, + const std::string& value) + { + result.clear(); + + boost::mutex::scoped_lock lock(mutex_); + + std::list id; + db_->LookupTagValue(id, value); + + for (std::list::const_iterator + it = id.begin(); it != id.end(); it++) + { + result.push_back(db_->GetPublicId(*it)); + } + } } diff -r 1b2cdc855bd3 -r 2c739f76d0bb OrthancServer/ServerIndex.h --- 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& result, + DicomTag tag, + const std::string& value); + + void LookupTagValue(std::list& result, + const std::string& value); }; } diff -r 1b2cdc855bd3 -r 2c739f76d0bb UnitTests/ServerIndex.cpp --- 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 #include +#include 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 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 s; + context.GetIndex().LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059"); + for (std::list::iterator i = s.begin(); i != s.end(); i++) + { + std::cout << "*** " << *i << std::endl;; + } + }*/ + + +}