# HG changeset patch # User Sebastien Jodogne # Date 1410953137 -7200 # Node ID 1ea4094d077cccb254dea1367a6cafa92f1cd649 # Parent 82cbf1480aacf5fe27316649536803cce1081fbd refactoring diff -r 82cbf1480aac -r 1ea4094d077c Core/DicomFormat/DicomTag.cpp --- a/Core/DicomFormat/DicomTag.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/Core/DicomFormat/DicomTag.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -244,4 +244,14 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } } + + + bool DicomTag::IsIdentifier() const + { + return (*this == DICOM_TAG_PATIENT_ID || + *this == DICOM_TAG_STUDY_INSTANCE_UID || + *this == DICOM_TAG_ACCESSION_NUMBER || + *this == DICOM_TAG_SERIES_INSTANCE_UID || + *this == DICOM_TAG_SOP_INSTANCE_UID); + } } diff -r 82cbf1480aac -r 1ea4094d077c Core/DicomFormat/DicomTag.h --- a/Core/DicomFormat/DicomTag.h Wed Sep 17 12:38:28 2014 +0200 +++ b/Core/DicomFormat/DicomTag.h Wed Sep 17 13:25:37 2014 +0200 @@ -86,6 +86,8 @@ static void GetTagsForModule(std::set& target, ResourceType module); + + bool IsIdentifier() const; }; // Aliases for the most useful tags diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -539,18 +539,35 @@ } } + + static void SetMainDicomTagsInternal(SQLite::Statement& s, + int64_t id, + const DicomElement& element) + { + s.BindInt64(0, id); + s.BindInt(1, element.GetTag().GetGroup()); + s.BindInt(2, element.GetTag().GetElement()); + s.BindString(3, element.GetValue().AsString()); + s.Run(); + } + + void DatabaseWrapper::SetMainDicomTags(int64_t id, const DicomMap& tags) { DicomArray flattened(tags); for (size_t i = 0; i < flattened.GetSize(); i++) { - SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)"); - s.BindInt64(0, id); - s.BindInt(1, flattened.GetElement(i).GetTag().GetGroup()); - s.BindInt(2, flattened.GetElement(i).GetTag().GetElement()); - s.BindString(3, flattened.GetElement(i).GetValue().AsString()); - s.Run(); + if (flattened.GetElement(i).GetTag().IsIdentifier()) + { + SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)"); + SetMainDicomTagsInternal(s, id, flattened.GetElement(i)); + } + else + { + SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifier VALUES(?, ?, ?, ?)"); + SetMainDicomTagsInternal(s, id, flattened.GetElement(i)); + } } } @@ -567,6 +584,15 @@ s.ColumnInt(2), s.ColumnString(3)); } + + SQLite::Statement s2(db_, SQLITE_FROM_HERE, "SELECT * FROM DicomIdentifiers WHERE id=?"); + s2.BindInt64(0, id); + while (s2.Step()) + { + map.SetValue(s2.ColumnInt(1), + s2.ColumnInt(2), + s2.ColumnString(3)); + } } @@ -1052,12 +1078,17 @@ } - void DatabaseWrapper::LookupTagValue(std::list& result, - DicomTag tag, - const std::string& value) + void DatabaseWrapper::LookupIdentifier(std::list& result, + const DicomTag& tag, + const std::string& value) { + if (!tag.IsIdentifier()) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + SQLite::Statement s(db_, SQLITE_FROM_HERE, - "SELECT id FROM MainDicomTags WHERE tagGroup=? AND tagElement=? and value=?"); + "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?"); s.BindInt(0, tag.GetGroup()); s.BindInt(1, tag.GetElement()); @@ -1072,11 +1103,11 @@ } - void DatabaseWrapper::LookupTagValue(std::list& result, - const std::string& value) + void DatabaseWrapper::LookupIdentifier(std::list& result, + const std::string& value) { SQLite::Statement s(db_, SQLITE_FROM_HERE, - "SELECT id FROM MainDicomTags WHERE value=?"); + "SELECT id FROM DicomIdentifiers WHERE value=?"); s.BindString(0, value); diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/DatabaseWrapper.h Wed Sep 17 13:25:37 2014 +0200 @@ -229,12 +229,12 @@ bool IsExistingResource(int64_t internalId); - void LookupTagValue(std::list& result, - DicomTag tag, - const std::string& value); + void LookupIdentifier(std::list& result, + const DicomTag& tag, + const std::string& value); - void LookupTagValue(std::list& result, - const std::string& value); + void LookupIdentifier(std::list& result, + const std::string& value); void GetAllMetadata(std::map& result, int64_t id); diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/OrthancFindRequestHandler.cpp --- a/OrthancServer/OrthancFindRequestHandler.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/OrthancFindRequestHandler.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -320,7 +320,7 @@ << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")"; std::list resources; - index_.LookupTagValue(resources, tag, value, level_); + index_.LookupIdentifier(resources, tag, value, level_); if (isFilterApplied_) { diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/OrthancMoveRequestHandler.cpp --- a/OrthancServer/OrthancMoveRequestHandler.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/OrthancMoveRequestHandler.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -101,7 +101,7 @@ } - bool OrthancMoveRequestHandler::LookupResource(std::string& publicId, + bool OrthancMoveRequestHandler::LookupIdentifier(std::string& publicId, DicomTag tag, const DicomMap& input) { @@ -113,7 +113,7 @@ std::string value = input.GetValue(tag).AsString(); std::list ids; - context_.GetIndex().LookupTagValue(ids, tag, value); + context_.GetIndex().LookupIdentifier(ids, tag, value); if (ids.size() != 1) { @@ -155,19 +155,19 @@ switch (level) { case ResourceType_Patient: - ok = LookupResource(publicId, DICOM_TAG_PATIENT_ID, input); + ok = LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input); break; case ResourceType_Study: - ok = LookupResource(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); + ok = LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); break; case ResourceType_Series: - ok = LookupResource(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); + ok = LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); break; case ResourceType_Instance: - ok = LookupResource(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); + ok = LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); break; default: diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/OrthancMoveRequestHandler.h --- a/OrthancServer/OrthancMoveRequestHandler.h Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/OrthancMoveRequestHandler.h Wed Sep 17 13:25:37 2014 +0200 @@ -41,9 +41,9 @@ private: ServerContext& context_; - bool LookupResource(std::string& publicId, - DicomTag tag, - const DicomMap& input); + bool LookupIdentifier(std::string& publicId, + DicomTag tag, + const DicomMap& input); public: OrthancMoveRequestHandler(ServerContext& context) : diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -794,7 +794,7 @@ std::string tag = call.GetPostBody(); Resources resources; - OrthancRestApi::GetIndex(call).LookupTagValue(resources, tag); + OrthancRestApi::GetIndex(call).LookupIdentifier(resources, tag); Json::Value result = Json::arrayValue; diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/ServerIndex.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -1632,17 +1632,17 @@ - void ServerIndex::LookupTagValue(std::list& result, - DicomTag tag, - const std::string& value, - ResourceType type) + void ServerIndex::LookupIdentifier(std::list& result, + const DicomTag& tag, + const std::string& value, + ResourceType type) { result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list id; - db_->LookupTagValue(id, tag, value); + db_->LookupIdentifier(id, tag, value); for (std::list::const_iterator it = id.begin(); it != id.end(); ++it) @@ -1655,16 +1655,16 @@ } - void ServerIndex::LookupTagValue(std::list& result, - DicomTag tag, - const std::string& value) + void ServerIndex::LookupIdentifier(std::list& result, + const DicomTag& tag, + const std::string& value) { result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list id; - db_->LookupTagValue(id, tag, value); + db_->LookupIdentifier(id, tag, value); for (std::list::const_iterator it = id.begin(); it != id.end(); ++it) @@ -1674,15 +1674,15 @@ } - void ServerIndex::LookupTagValue(std::list< std::pair >& result, - const std::string& value) + void ServerIndex::LookupIdentifier(std::list< std::pair >& result, + const std::string& value) { result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list id; - db_->LookupTagValue(id, value); + db_->LookupIdentifier(id, value); for (std::list::const_iterator it = id.begin(); it != id.end(); ++it) diff -r 82cbf1480aac -r 1ea4094d077c OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Wed Sep 17 12:38:28 2014 +0200 +++ b/OrthancServer/ServerIndex.h Wed Sep 17 13:25:37 2014 +0200 @@ -216,17 +216,17 @@ /* out */ unsigned int& countInstances, const std::string& publicId); - void LookupTagValue(std::list& result, - DicomTag tag, - const std::string& value, - ResourceType type); + void LookupIdentifier(std::list& result, + const DicomTag& tag, + const std::string& value, + ResourceType type); - void LookupTagValue(std::list& result, - DicomTag tag, - const std::string& value); + void LookupIdentifier(std::list& result, + const DicomTag& tag, + const std::string& value); - void LookupTagValue(std::list< std::pair >& result, - const std::string& value); + void LookupIdentifier(std::list< std::pair >& result, + const std::string& value); StoreStatus AddAttachment(const FileInfo& attachment, const std::string& publicId); diff -r 82cbf1480aac -r 1ea4094d077c Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -618,7 +618,7 @@ } std::list result; - pimpl_->context_.GetIndex().LookupTagValue(result, tag, p.argument, level); + pimpl_->context_.GetIndex().LookupIdentifier(result, tag, p.argument, level); if (result.size() == 1) { diff -r 82cbf1480aac -r 1ea4094d077c UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Wed Sep 17 12:38:28 2014 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed Sep 17 13:25:37 2014 +0200 @@ -545,7 +545,7 @@ -TEST_P(DatabaseWrapperTest, LookupTagValue) +TEST_P(DatabaseWrapperTest, LookupIdentifier) { int64_t a[] = { index_->CreateResource("a", ResourceType_Study), // 0 @@ -562,29 +562,29 @@ std::list s; - index_->LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "0"); + index_->LookupIdentifier(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"); + 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()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end()); - index_->LookupTagValue(s, DICOM_TAG_STUDY_INSTANCE_UID, "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_->LookupTagValue(s, "1"); + index_->LookupIdentifier(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"); + context.GetIndex().LookupIdentifier(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;;