Mercurial > hg > orthanc
changeset 5682:fd4c5e064cbe find-refactoring
started refactoring of ServerContext::Apply()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Jul 2024 11:17:34 +0200 |
parents | 77875b51cf95 |
children | 9b3816c21008 |
files | OrthancServer/Sources/Database/Compatibility/GenericFind.cpp OrthancServer/Sources/Database/FindRequest.h OrthancServer/Sources/ResourceFinder.cpp OrthancServer/Sources/ResourceFinder.h OrthancServer/Sources/Search/DatabaseConstraint.cpp OrthancServer/Sources/Search/DatabaseConstraint.h OrthancServer/Sources/ServerContext.cpp |
diffstat | 7 files changed, 96 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Tue Jul 09 11:17:34 2024 +0200 @@ -208,9 +208,15 @@ { GetChildrenIdentifiers(identifiers, transaction_, request.GetOrthancIdentifiers(), ResourceType_Series, request.GetLevel()); } + else if (request.GetMetadataConstraintsCount() == 0 && + request.GetOrdering().empty()) + { + transaction_.ApplyLookupResources(identifiers, NULL /* TODO-FIND: Could the "instancesId" information be exploited? */, + request.GetDicomTagConstraints(), request.GetLevel(), request.GetLabels(), + request.GetLabelsConstraint(), request.HasLimits() ? request.GetLimitsCount() : 0); + } else { - printf("?????????????????????????\n"); throw OrthancException(ErrorCode_NotImplemented); } }
--- a/OrthancServer/Sources/Database/FindRequest.h Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/Database/FindRequest.h Tue Jul 09 11:17:34 2024 +0200 @@ -335,6 +335,11 @@ return ordering_; } + void SetLabels(const std::set<std::string>& labels) + { + labels_ = labels; + } + void AddLabel(const std::string& label) { labels_.insert(label);
--- a/OrthancServer/Sources/ResourceFinder.cpp Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.cpp Tue Jul 09 11:17:34 2024 +0200 @@ -29,6 +29,7 @@ #include "../../OrthancFramework/Sources/OrthancException.h" #include "../../OrthancFramework/Sources/SerializationToolbox.h" #include "OrthancConfiguration.h" +#include "Search/DatabaseLookup.h" #include "ServerContext.h" #include "ServerIndex.h" @@ -452,6 +453,13 @@ } + void ResourceFinder::SetDatabaseLookup(const DatabaseLookup& lookup) + { + MainDicomTagsRegistry registry; + registry.NormalizeLookup(request_.GetDicomTagConstraints(), lookup, request_.GetLevel()); + } + + void ResourceFinder::AddRequestedTags(const DicomTag& tag) { if (DicomMap::IsMainDicomTag(tag, ResourceType_Patient)) @@ -700,6 +708,20 @@ } + void ResourceFinder::Execute(FindResponse& response, + ServerIndex& index) const + { + if (hasRequestedTags_) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + index.ExecuteFind(response, request_); + } + } + + void ResourceFinder::Execute(Json::Value& target, ServerContext& context) const { @@ -712,12 +734,6 @@ { const FindResponse::Resource& resource = response.GetResourceByIndex(i); - { - Json::Value v; - resource.DebugExport(v, request_); - std::cout << v.toStyledString(); - } - if (expand_) { Json::Value item;
--- a/OrthancServer/Sources/ResourceFinder.h Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.h Tue Jul 09 11:17:34 2024 +0200 @@ -28,6 +28,7 @@ namespace Orthanc { + class DatabaseLookup; class ServerContext; class ServerIndex; @@ -102,6 +103,8 @@ request_.SetLimits(since, count); } + void SetDatabaseLookup(const DatabaseLookup& lookup); + void SetIncludeAllMetadata(bool include) { includeAllMetadata_ = include; @@ -111,6 +114,11 @@ void AddRequestedTags(const std::set<DicomTag>& tags); + void SetLabels(const std::set<std::string>& labels) + { + request_.SetLabels(labels); + } + void AddLabel(const std::string& label) { request_.AddLabel(label); @@ -121,6 +129,14 @@ request_.SetLabelsConstraint(constraint); } + void SetRetrieveOneInstanceIdentifier(bool retrieve) + { + request_.SetRetrieveOneInstanceIdentifier(retrieve); + } + + void Execute(FindResponse& target, + ServerIndex& index) const; + void Execute(Json::Value& target, ServerContext& context) const;
--- a/OrthancServer/Sources/Search/DatabaseConstraint.cpp Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/Search/DatabaseConstraint.cpp Tue Jul 09 11:17:34 2024 +0200 @@ -153,7 +153,6 @@ const std::vector<std::string>& values, bool caseSensitive, bool mandatory) : - keyType_(DatabaseConstraint::KeyType_DicomTag), level_(level), tag_(tag), isIdentifier_(isIdentifier),
--- a/OrthancServer/Sources/Search/DatabaseConstraint.h Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/Search/DatabaseConstraint.h Tue Jul 09 11:17:34 2024 +0200 @@ -82,18 +82,9 @@ // This class is also used by the "orthanc-databases" project class DatabaseConstraint : public boost::noncopyable { - public: - enum KeyType // used for ordering and filters - { - KeyType_DicomTag, - KeyType_Metadata - }; - private: - KeyType keyType_; ResourceType level_; DicomTag tag_; - uint32_t metadataType_; // TODO: implement bool isIdentifier_; ConstraintType constraintType_; std::vector<std::string> values_;
--- a/OrthancServer/Sources/ServerContext.cpp Tue Jul 09 10:15:15 2024 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Tue Jul 09 11:17:34 2024 +0200 @@ -42,6 +42,7 @@ #include "OrthancConfiguration.h" #include "OrthancRestApi/OrthancRestApi.h" +#include "ResourceFinder.h" #include "Search/DatabaseLookup.h" #include "ServerJobs/OrthancJobUnserializer.h" #include "ServerToolbox.h" @@ -1554,8 +1555,52 @@ fastLookup->RemoveConstraint(DICOM_TAG_MODALITIES_IN_STUDY); } + const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1); + + if (false) { - const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1); + /** + * EXPERIMENTAL VERSION + **/ + + ResourceFinder finder(queryLevel, false /* TODO-FIND: don't expand for now */); + finder.SetLimits(0, lookupLimit); + finder.SetDatabaseLookup(*fastLookup); + finder.SetLabels(lookup.GetLabels()); + finder.SetLabelsConstraint(lookup.GetLabelsConstraint()); + + if (queryLevel != ResourceType_Instance) + { + finder.SetRetrieveOneInstanceIdentifier(true); + } + + FindResponse response; + finder.Execute(response, GetIndex()); + + resources.resize(response.GetSize()); + instances.resize(response.GetSize()); + + for (size_t i = 0; i < response.GetSize(); i++) + { + const FindResponse::Resource& resource = response.GetResourceByIndex(i); + resources[i] = resource.GetIdentifier(); + + if (queryLevel == ResourceType_Instance) + { + instances[i] = resource.GetIdentifier(); + } + else + { + instances[i] = resource.GetOneInstanceIdentifier(); + } + } + } + else + { + /** + * VERSION IN ORTHANC <= 1.12.4 + **/ + GetIndex().ApplyLookupResources(resources, &instances, *fastLookup, queryLevel, lookup.GetLabels(), lookup.GetLabelsConstraint(), lookupLimit); }