Mercurial > hg > orthanc
changeset 5621:732ec9feeea8 find-refactoring
introduction of FindRequest::ChildrenRetrieveSpecification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 11 May 2024 15:43:07 +0200 |
parents | 4bfd885fb45f |
children | 2c95a34af64f |
files | OrthancServer/Sources/Database/Compatibility/GenericFind.cpp OrthancServer/Sources/Database/FindRequest.cpp OrthancServer/Sources/Database/FindRequest.h OrthancServer/Sources/Database/FindResponse.cpp OrthancServer/Sources/ResourceFinder.cpp OrthancServer/Sources/ResourceFinder.h |
diffstat | 6 files changed, 121 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Sat May 11 15:11:22 2024 +0200 +++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Sat May 11 15:43:07 2024 +0200 @@ -410,8 +410,10 @@ } } - if (request.IsRetrieveChildrenIdentifiers()) + if (request.GetLevel() != ResourceType_Instance && + request.GetChildrenRetrieveSpecification(GetChildResourceType(request.GetLevel())).IsRetrieveIdentifiers()) { + // TODO-FIND: Retrieve other levels than immediate children std::list<std::string> children; transaction_.GetChildrenPublicId(children, internalId);
--- a/OrthancServer/Sources/Database/FindRequest.cpp Sat May 11 15:11:22 2024 +0200 +++ b/OrthancServer/Sources/Database/FindRequest.cpp Sat May 11 15:43:07 2024 +0200 @@ -55,6 +55,30 @@ } + FindRequest::ChildrenRetrieveSpecification& FindRequest::GetChildrenRetrieveSpecification(ResourceType level) + { + if (!IsResourceLevelAboveOrEqual(level_, level)) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + switch (level) + { + case ResourceType_Study: + return retrieveChildrenStudies_; + + case ResourceType_Series: + return retrieveChildrenSeries_; + + case ResourceType_Instance: + return retrieveChildrenInstances_; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + FindRequest::FindRequest(ResourceType level) : level_(level), hasLimits_(false), @@ -65,7 +89,6 @@ retrieveLabels_(false), retrieveAttachments_(false), retrieveParentIdentifier_(false), - retrieveChildrenIdentifiers_(false), retrieveOneInstanceIdentifier_(false) { } @@ -269,19 +292,6 @@ } - void FindRequest::SetRetrieveChildrenIdentifiers(bool retrieve) - { - if (level_ == ResourceType_Instance) - { - throw OrthancException(ErrorCode_BadParameterType); - } - else - { - retrieveChildrenIdentifiers_ = retrieve; - } - } - - void FindRequest::AddRetrieveChildrenMetadata(MetadataType metadata) { if (IsRetrieveChildrenMetadata(metadata))
--- a/OrthancServer/Sources/Database/FindRequest.h Sat May 11 15:11:22 2024 +0200 +++ b/OrthancServer/Sources/Database/FindRequest.h Sat May 11 15:43:07 2024 +0200 @@ -189,6 +189,41 @@ }; + class ChildrenRetrieveSpecification : public boost::noncopyable + { + private: + bool identifiers_; + bool count_; + + public: + ChildrenRetrieveSpecification() : + identifiers_(false), + count_(false) + { + } + + void SetRetrieveIdentifiers(bool retrieve) + { + identifiers_ = retrieve; + } + + bool IsRetrieveIdentifiers() const + { + return identifiers_; + } + + void SetRetrieveCount(bool retrieve) + { + count_ = retrieve; + } + + bool IsRetrieveCount() const + { + return count_; + } + }; + + private: // filter & ordering fields ResourceType level_; // The level of the response (the filtering on tags, labels and metadata also happens at this level) @@ -210,7 +245,9 @@ ParentRetrieveSpecification retrieveParentPatient_; ParentRetrieveSpecification retrieveParentStudy_; ParentRetrieveSpecification retrieveParentSeries_; - bool retrieveChildrenIdentifiers_; + ChildrenRetrieveSpecification retrieveChildrenStudies_; + ChildrenRetrieveSpecification retrieveChildrenSeries_; + ChildrenRetrieveSpecification retrieveChildrenInstances_; std::set<MetadataType> retrieveChildrenMetadata_; bool retrieveOneInstanceIdentifier_; @@ -346,11 +383,11 @@ return const_cast<FindRequest&>(*this).GetParentRetrieveSpecification(level); } - void SetRetrieveChildrenIdentifiers(bool retrieve); + ChildrenRetrieveSpecification& GetChildrenRetrieveSpecification(ResourceType level); - bool IsRetrieveChildrenIdentifiers() const + const ChildrenRetrieveSpecification& GetChildrenRetrieveSpecification(ResourceType level) const { - return retrieveChildrenIdentifiers_; + return const_cast<FindRequest&>(*this).GetChildrenRetrieveSpecification(level); } void AddRetrieveChildrenMetadata(MetadataType metadata);
--- a/OrthancServer/Sources/Database/FindResponse.cpp Sat May 11 15:11:22 2024 +0200 +++ b/OrthancServer/Sources/Database/FindResponse.cpp Sat May 11 15:43:07 2024 +0200 @@ -493,11 +493,11 @@ for (size_t i = 0; i < 4; i++) { + const char* level = EnumerationToString(levels[i]); + if (levels[i] != request.GetLevel() && IsResourceLevelAboveOrEqual(levels[i], request.GetLevel())) { - const char* level = EnumerationToString(levels[i]); - if (request.GetParentRetrieveSpecification(levels[i]).IsRetrieveMainDicomTags()) { DicomMap m; @@ -510,17 +510,28 @@ DebugMetadata(target[level]["Metadata"], GetMetadata(levels[i])); } } - } - if (request.IsRetrieveChildrenIdentifiers()) - { - Json::Value v = Json::arrayValue; - for (std::set<std::string>::const_iterator it = childrenIdentifiers_.begin(); - it != childrenIdentifiers_.end(); ++it) + if (levels[i] != request.GetLevel() && + IsResourceLevelAboveOrEqual(request.GetLevel(), levels[i])) { - v.append(*it); + if (request.GetChildrenRetrieveSpecification(levels[i]).IsRetrieveIdentifiers()) + { + if (levels[i] != GetChildResourceType(request.GetLevel())) + { + throw OrthancException(ErrorCode_NotImplemented); // TODO-FIND + } + else + { + Json::Value v = Json::arrayValue; + for (std::set<std::string>::const_iterator it = childrenIdentifiers_.begin(); + it != childrenIdentifiers_.end(); ++it) + { + v.append(*it); + } + target[level]["Identifiers"] = v; + } + } } - target["Children"] = v; } if (request.IsRetrieveLabels())
--- a/OrthancServer/Sources/ResourceFinder.cpp Sat May 11 15:11:22 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.cpp Sat May 11 15:43:07 2024 +0200 @@ -371,23 +371,30 @@ request_.SetRetrieveMetadata(true); request_.SetRetrieveLabels(true); - if (level == ResourceType_Series) - { - request_.AddRetrieveChildrenMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus - } - - if (level == ResourceType_Instance) + switch (level) { - request_.SetRetrieveAttachments(true); // for FileSize & FileUuid - } - else - { - request_.SetRetrieveChildrenIdentifiers(true); - } + case ResourceType_Patient: + request_.GetChildrenRetrieveSpecification(ResourceType_Study).SetRetrieveIdentifiers(true); + break; + + case ResourceType_Study: + request_.GetChildrenRetrieveSpecification(ResourceType_Series).SetRetrieveIdentifiers(true); + request_.SetRetrieveParentIdentifier(true); + break; - if (level != ResourceType_Patient) - { - request_.SetRetrieveParentIdentifier(true); + case ResourceType_Series: + request_.AddRetrieveChildrenMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus + request_.GetChildrenRetrieveSpecification(ResourceType_Instance).SetRetrieveIdentifiers(true); + request_.SetRetrieveParentIdentifier(true); + break; + + case ResourceType_Instance: + request_.SetRetrieveAttachments(true); // for FileSize & FileUuid + request_.SetRetrieveParentIdentifier(true); + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); } } } @@ -491,7 +498,7 @@ void ResourceFinder::Execute(Json::Value& target, - ServerContext& context) + ServerContext& context) const { FindResponse response; context.GetIndex().ExecuteFind(response, request_); @@ -502,6 +509,12 @@ { const FindResponse::Resource& resource = response.GetResourceByIndex(i); + { + Json::Value v; + resource.DebugExport(v, request_); + std::cout << v.toStyledString(); + } + if (expand_) { Json::Value item; @@ -607,7 +620,7 @@ bool ResourceFinder::ExecuteOneResource(Json::Value& target, - ServerContext& context) + ServerContext& context) const { Json::Value answer; Execute(answer, context);
--- a/OrthancServer/Sources/ResourceFinder.h Sat May 11 15:11:22 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.h Sat May 11 15:43:07 2024 +0200 @@ -93,9 +93,9 @@ void AddRequestedTags(const std::set<DicomTag>& tags); void Execute(Json::Value& target, - ServerContext& context); + ServerContext& context) const; bool ExecuteOneResource(Json::Value& target, - ServerContext& context); + ServerContext& context) const; }; }