Mercurial > hg > orthanc
changeset 1727:1ae29c5e52fb db-changes
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 20 Oct 2015 14:50:10 +0200 |
parents | a7c05bbfaf6a |
children | 4941494b5dd8 |
files | OrthancServer/DatabaseWrapper.h OrthancServer/DatabaseWrapperBase.cpp OrthancServer/DatabaseWrapperBase.h OrthancServer/IDatabaseWrapper.h OrthancServer/OrthancMoveRequestHandler.cpp OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ResourceFinder.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCDatabasePlugin.h Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Plugins/Samples/DatabasePlugin/Database.h UnitTestsSources/ServerIndexTests.cpp |
diffstat | 16 files changed, 93 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.h Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/DatabaseWrapper.h Tue Oct 20 14:50:10 2015 +0200 @@ -316,10 +316,11 @@ } virtual void LookupIdentifier(std::list<int64_t>& target, + ResourceType level, const DicomTag& tag, const std::string& value) { - base_.LookupIdentifier(target, tag, value); + base_.LookupIdentifier(target, level, tag, value); } virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
--- a/OrthancServer/DatabaseWrapperBase.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/DatabaseWrapperBase.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -666,21 +666,24 @@ void DatabaseWrapperBase::LookupIdentifier(std::list<int64_t>& target, + ResourceType level, const DicomTag& tag, const std::string& value) { - assert(tag == DICOM_TAG_PATIENT_ID || - tag == DICOM_TAG_STUDY_INSTANCE_UID || - tag == DICOM_TAG_SERIES_INSTANCE_UID || - tag == DICOM_TAG_SOP_INSTANCE_UID || - tag == DICOM_TAG_ACCESSION_NUMBER); + assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) || + (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) || + (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) || + (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) || + (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID)); SQLite::Statement s(db_, SQLITE_FROM_HERE, - "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?"); + "SELECT d.id FROM DicomIdentifiers as d, Resources as r WHERE " + "d.id = r.internalId AND r.resourceType=? AND d.tagGroup=? AND d.tagElement=? and d.value=?"); - s.BindInt(0, tag.GetGroup()); - s.BindInt(1, tag.GetElement()); - s.BindString(2, value); + s.BindInt(0, level); + s.BindInt(1, tag.GetGroup()); + s.BindInt(2, tag.GetElement()); + s.BindString(3, value); target.clear();
--- a/OrthancServer/DatabaseWrapperBase.h Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/DatabaseWrapperBase.h Tue Oct 20 14:50:10 2015 +0200 @@ -191,6 +191,7 @@ bool IsExistingResource(int64_t internalId); void LookupIdentifier(std::list<int64_t>& target, + ResourceType level, const DicomTag& tag, const std::string& value); };
--- a/OrthancServer/IDatabaseWrapper.h Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/IDatabaseWrapper.h Tue Oct 20 14:50:10 2015 +0200 @@ -147,6 +147,7 @@ GlobalProperty property) = 0; virtual void LookupIdentifier(std::list<int64_t>& target, + ResourceType level, const DicomTag& tag, const std::string& value) = 0;
--- a/OrthancServer/OrthancMoveRequestHandler.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/OrthancMoveRequestHandler.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -141,7 +141,7 @@ std::string value = input.GetValue(tag).AsString(); std::list<std::string> ids; - context_.GetIndex().LookupIdentifier(ids, tag, value, level); + context_.GetIndex().LookupIdentifier(ids, level, tag, value); if (ids.size() != 1) {
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -892,7 +892,7 @@ ResourceType level) { std::list<std::string> tmp; - index.LookupIdentifier(tmp, tag, value, level); + index.LookupIdentifier(tmp, level, tag, value); for (std::list<std::string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
--- a/OrthancServer/ResourceFinder.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/ResourceFinder.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -160,7 +160,7 @@ << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")"; std::list<std::string> resources; - index_.LookupIdentifier(resources, tag, value, level_); + index_.LookupIdentifier(resources, level_, tag, value); if (isFilterApplied_) {
--- a/OrthancServer/ServerIndex.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/ServerIndex.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -1889,30 +1889,27 @@ void ServerIndex::LookupIdentifier(std::list<std::string>& result, + ResourceType level, const DicomTag& tag, - const std::string& value, - ResourceType type) + const std::string& value) { - assert(tag == DICOM_TAG_PATIENT_ID || - tag == DICOM_TAG_STUDY_INSTANCE_UID || - tag == DICOM_TAG_SERIES_INSTANCE_UID || - tag == DICOM_TAG_SOP_INSTANCE_UID || - tag == DICOM_TAG_ACCESSION_NUMBER); + assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) || + (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) || + (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) || + (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) || + (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID)); result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list<int64_t> id; - db_.LookupIdentifier(id, tag, value); + db_.LookupIdentifier(id, level, tag, value); for (std::list<int64_t>::const_iterator it = id.begin(); it != id.end(); ++it) { - if (db_.GetResourceType(*it) == type) - { - result.push_back(db_.GetPublicId(*it)); - } + result.push_back(db_.GetPublicId(*it)); } }
--- a/OrthancServer/ServerIndex.h Tue Oct 20 11:21:36 2015 +0200 +++ b/OrthancServer/ServerIndex.h Tue Oct 20 14:50:10 2015 +0200 @@ -236,9 +236,9 @@ const std::string& publicId); void LookupIdentifier(std::list<std::string>& result, + ResourceType level, const DicomTag& tag, - const std::string& value, - ResourceType type); + const std::string& value); StoreStatus AddAttachment(const FileInfo& attachment, const std::string& publicId);
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -595,6 +595,7 @@ void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target, + ResourceType level, const DicomTag& tag, const std::string& value) { @@ -605,9 +606,42 @@ tmp.element = tag.GetElement(); tmp.value = value.c_str(); - CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp)); + if (extensions_.lookupIdentifier3 != NULL) + { + CheckSuccess(extensions_.lookupIdentifier3(GetContext(), payload_, Plugins::Convert(level), &tmp)); + ForwardAnswers(target); + } + else + { + // Emulate "lookupIdentifier3" if unavailable + + if (backend_.lookupIdentifier == NULL) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + + CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp)); - ForwardAnswers(target); + if (type_ != _OrthancPluginDatabaseAnswerType_None && + type_ != _OrthancPluginDatabaseAnswerType_Int64) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + + target.clear(); + + if (type_ == _OrthancPluginDatabaseAnswerType_Int64) + { + for (std::list<int64_t>::const_iterator + it = answerInt64_.begin(); it != answerInt64_.end(); ++it) + { + if (GetResourceType(*it) == level) + { + target.push_back(*it); + } + } + } + } }
--- a/Plugins/Engine/OrthancPluginDatabase.h Tue Oct 20 11:21:36 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.h Tue Oct 20 14:50:10 2015 +0200 @@ -204,6 +204,7 @@ GlobalProperty property); virtual void LookupIdentifier(std::list<int64_t>& target, + ResourceType level, const DicomTag& tag, const std::string& value);
--- a/Plugins/Engine/OrthancPlugins.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -895,7 +895,7 @@ CheckContextAvailable(); std::list<std::string> result; - pimpl_->context_->GetIndex().LookupIdentifier(result, tag, p.argument, level); + pimpl_->context_->GetIndex().LookupIdentifier(result, level, tag, p.argument); if (result.size() == 1) {
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Tue Oct 20 11:21:36 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Tue Oct 20 14:50:10 2015 +0200 @@ -522,7 +522,9 @@ void* payload, int32_t property); - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + /* Use "OrthancPluginDatabaseExtensions::lookupIdentifier3" + instead of this function as of Orthanc 0.9.5 (db v6), can be set to NULL. + Output: Use OrthancPluginDatabaseAnswerInt64() */ OrthancPluginErrorCode (*lookupIdentifier) ( /* outputs */ OrthancPluginDatabaseContext* context, @@ -661,6 +663,15 @@ /* inputs */ void* payload, int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupIdentifier3) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType, + const OrthancPluginDicomTag* tag); } OrthancPluginDatabaseExtensions; /*<! @endcond */
--- a/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Tue Oct 20 11:21:36 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Tue Oct 20 14:50:10 2015 +0200 @@ -410,6 +410,7 @@ * 0x0018) or AccessionNumber (0x0008, 0x0050). **/ virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, + OrthancPluginResourceType resourceType, uint16_t group, uint16_t element, const char* value) = 0; @@ -1297,6 +1298,7 @@ static OrthancPluginErrorCode LookupIdentifier(OrthancPluginDatabaseContext* context, void* payload, + OrthancPluginResourceType resourceType, const OrthancPluginDicomTag* tag) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); @@ -1305,7 +1307,7 @@ try { std::list<int64_t> target; - backend->LookupIdentifier(target, tag->group, tag->element, tag->value); + backend->LookupIdentifier(target, resourceType, tag->group, tag->element, tag->value); for (std::list<int64_t>::const_iterator it = target.begin(); it != target.end(); ++it) @@ -1824,7 +1826,7 @@ params.logExportedResource = LogExportedResource; params.lookupAttachment = LookupAttachment; params.lookupGlobalProperty = LookupGlobalProperty; - params.lookupIdentifier = LookupIdentifier; + params.lookupIdentifier = NULL; // Unused starting with Orthanc 0.9.5 (db v6) params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) params.lookupMetadata = LookupMetadata; params.lookupParent = LookupParent; @@ -1846,6 +1848,7 @@ extensions.getDatabaseVersion = GetDatabaseVersion; extensions.upgradeDatabase = UpgradeDatabase; extensions.clearMainDicomTags = ClearMainDicomTags; + extensions.lookupIdentifier3 = LookupIdentifier; // New in Orthanc 0.9.5 (db v6) OrthancPluginDatabaseContext* database = OrthancPluginRegisterDatabaseBackendV2(context, ¶ms, &extensions, &backend); if (!context)
--- a/Plugins/Samples/DatabasePlugin/Database.h Tue Oct 20 11:21:36 2015 +0200 +++ b/Plugins/Samples/DatabasePlugin/Database.h Tue Oct 20 14:50:10 2015 +0200 @@ -188,11 +188,13 @@ } virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, + OrthancPluginResourceType level, uint16_t group, uint16_t element, const char* value) { - base_.LookupIdentifier(target, Orthanc::DicomTag(group, element), value); + base_.LookupIdentifier(target, Orthanc::Plugins::Convert(level), + Orthanc::DicomTag(group, element), value); } virtual bool LookupMetadata(std::string& target /*out*/,
--- a/UnitTestsSources/ServerIndexTests.cpp Tue Oct 20 11:21:36 2015 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Tue Oct 20 14:50:10 2015 +0200 @@ -693,24 +693,24 @@ std::list<int64_t> s; - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "0"); + index_->LookupIdentifier(s, ResourceType_Study, 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_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "0"); + index_->LookupIdentifier(s, ResourceType_Series, 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"); + index_->LookupIdentifier(s, ResourceType_Study, 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_STUDY_INSTANCE_UID, "1"); + index_->LookupIdentifier(s, ResourceType_Study, 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"); + index_->LookupIdentifier(s, ResourceType_Series, DICOM_TAG_SERIES_INSTANCE_UID, "1"); ASSERT_EQ(0u, s.size()); /*{