Mercurial > hg > orthanc
changeset 1162:1ea4094d077c db-changes
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 17 Sep 2014 13:25:37 +0200 |
parents | 82cbf1480aac |
children | 059391d3f8df c200a92734c9 |
files | Core/DicomFormat/DicomTag.cpp Core/DicomFormat/DicomTag.h OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancMoveRequestHandler.cpp OrthancServer/OrthancMoveRequestHandler.h OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h Plugins/Engine/OrthancPlugins.cpp UnitTestsSources/ServerIndexTests.cpp |
diffstat | 12 files changed, 100 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- 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); + } }
--- 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<DicomTag>& target, ResourceType module); + + bool IsIdentifier() const; }; // Aliases for the most useful tags
--- 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<int64_t>& result, - DicomTag tag, - const std::string& value) + void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& 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<int64_t>& result, - const std::string& value) + void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& 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);
--- 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<int64_t>& result, - DicomTag tag, - const std::string& value); + void LookupIdentifier(std::list<int64_t>& result, + const DicomTag& tag, + const std::string& value); - void LookupTagValue(std::list<int64_t>& result, - const std::string& value); + void LookupIdentifier(std::list<int64_t>& result, + const std::string& value); void GetAllMetadata(std::map<MetadataType, std::string>& result, int64_t id);
--- 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<std::string> resources; - index_.LookupTagValue(resources, tag, value, level_); + index_.LookupIdentifier(resources, tag, value, level_); if (isFilterApplied_) {
--- 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<std::string> 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:
--- 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) :
--- 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;
--- 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<std::string>& result, - DicomTag tag, - const std::string& value, - ResourceType type) + void ServerIndex::LookupIdentifier(std::list<std::string>& result, + const DicomTag& tag, + const std::string& value, + ResourceType type) { result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list<int64_t> id; - db_->LookupTagValue(id, tag, value); + db_->LookupIdentifier(id, tag, value); for (std::list<int64_t>::const_iterator it = id.begin(); it != id.end(); ++it) @@ -1655,16 +1655,16 @@ } - void ServerIndex::LookupTagValue(std::list<std::string>& result, - DicomTag tag, - const std::string& value) + void ServerIndex::LookupIdentifier(std::list<std::string>& result, + const DicomTag& tag, + const std::string& value) { result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list<int64_t> id; - db_->LookupTagValue(id, tag, value); + db_->LookupIdentifier(id, tag, value); for (std::list<int64_t>::const_iterator it = id.begin(); it != id.end(); ++it) @@ -1674,15 +1674,15 @@ } - void ServerIndex::LookupTagValue(std::list< std::pair<ResourceType, std::string> >& result, - const std::string& value) + void ServerIndex::LookupIdentifier(std::list< std::pair<ResourceType, std::string> >& result, + const std::string& value) { result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list<int64_t> id; - db_->LookupTagValue(id, value); + db_->LookupIdentifier(id, value); for (std::list<int64_t>::const_iterator it = id.begin(); it != id.end(); ++it)
--- 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<std::string>& result, - DicomTag tag, - const std::string& value, - ResourceType type); + void LookupIdentifier(std::list<std::string>& result, + const DicomTag& tag, + const std::string& value, + ResourceType type); - void LookupTagValue(std::list<std::string>& result, - DicomTag tag, - const std::string& value); + void LookupIdentifier(std::list<std::string>& result, + const DicomTag& tag, + const std::string& value); - void LookupTagValue(std::list< std::pair<ResourceType, std::string> >& result, - const std::string& value); + void LookupIdentifier(std::list< std::pair<ResourceType, std::string> >& result, + const std::string& value); StoreStatus AddAttachment(const FileInfo& attachment, const std::string& publicId);
--- 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<std::string> result; - pimpl_->context_.GetIndex().LookupTagValue(result, tag, p.argument, level); + pimpl_->context_.GetIndex().LookupIdentifier(result, tag, p.argument, level); if (result.size() == 1) {
--- 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<int64_t> 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<std::string> 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<std::string>::iterator i = s.begin(); i != s.end(); i++) { std::cout << "*** " << *i << std::endl;;