# HG changeset patch # User Sebastien Jodogne # Date 1445345410 -7200 # Node ID 1ae29c5e52fbb9f3cace36d17f993c6fd42719f9 # Parent a7c05bbfaf6a991a857e15aad040bf96ade62fe9 fix diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/DatabaseWrapper.h --- 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& 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& target, diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/DatabaseWrapperBase.cpp --- 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& 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(); diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/DatabaseWrapperBase.h --- 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& target, + ResourceType level, const DicomTag& tag, const std::string& value); }; diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/IDatabaseWrapper.h --- 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& target, + ResourceType level, const DicomTag& tag, const std::string& value) = 0; diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/OrthancMoveRequestHandler.cpp --- 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 ids; - context_.GetIndex().LookupIdentifier(ids, tag, value, level); + context_.GetIndex().LookupIdentifier(ids, level, tag, value); if (ids.size() != 1) { diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- 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 tmp; - index.LookupIdentifier(tmp, tag, value, level); + index.LookupIdentifier(tmp, level, tag, value); for (std::list::const_iterator it = tmp.begin(); it != tmp.end(); ++it) diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/ResourceFinder.cpp --- 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 resources; - index_.LookupIdentifier(resources, tag, value, level_); + index_.LookupIdentifier(resources, level_, tag, value); if (isFilterApplied_) { diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/ServerIndex.cpp --- 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& 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 id; - db_.LookupIdentifier(id, tag, value); + db_.LookupIdentifier(id, level, tag, value); for (std::list::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)); } } diff -r a7c05bbfaf6a -r 1ae29c5e52fb OrthancServer/ServerIndex.h --- 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& 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); diff -r a7c05bbfaf6a -r 1ae29c5e52fb Plugins/Engine/OrthancPluginDatabase.cpp --- 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& 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::const_iterator + it = answerInt64_.begin(); it != answerInt64_.end(); ++it) + { + if (GetResourceType(*it) == level) + { + target.push_back(*it); + } + } + } + } } diff -r a7c05bbfaf6a -r 1ae29c5e52fb Plugins/Engine/OrthancPluginDatabase.h --- 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& target, + ResourceType level, const DicomTag& tag, const std::string& value); diff -r a7c05bbfaf6a -r 1ae29c5e52fb Plugins/Engine/OrthancPlugins.cpp --- 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 result; - pimpl_->context_->GetIndex().LookupIdentifier(result, tag, p.argument, level); + pimpl_->context_->GetIndex().LookupIdentifier(result, level, tag, p.argument); if (result.size() == 1) { diff -r a7c05bbfaf6a -r 1ae29c5e52fb Plugins/Include/orthanc/OrthancCDatabasePlugin.h --- 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; /*& 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(payload); @@ -1305,7 +1307,7 @@ try { std::list target; - backend->LookupIdentifier(target, tag->group, tag->element, tag->value); + backend->LookupIdentifier(target, resourceType, tag->group, tag->element, tag->value); for (std::list::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) diff -r a7c05bbfaf6a -r 1ae29c5e52fb Plugins/Samples/DatabasePlugin/Database.h --- 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& 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*/, diff -r a7c05bbfaf6a -r 1ae29c5e52fb UnitTestsSources/ServerIndexTests.cpp --- 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 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()); /*{