# HG changeset patch # User Sebastien Jodogne # Date 1715434987 -7200 # Node ID 732ec9feeea81e46960c2535256a1a1ff52fbcf9 # Parent 4bfd885fb45f805c7f23fe720b787fc002632087 introduction of FindRequest::ChildrenRetrieveSpecification diff -r 4bfd885fb45f -r 732ec9feeea8 OrthancServer/Sources/Database/Compatibility/GenericFind.cpp --- 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 children; transaction_.GetChildrenPublicId(children, internalId); diff -r 4bfd885fb45f -r 732ec9feeea8 OrthancServer/Sources/Database/FindRequest.cpp --- 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)) diff -r 4bfd885fb45f -r 732ec9feeea8 OrthancServer/Sources/Database/FindRequest.h --- 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 retrieveChildrenMetadata_; bool retrieveOneInstanceIdentifier_; @@ -346,11 +383,11 @@ return const_cast(*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(*this).GetChildrenRetrieveSpecification(level); } void AddRetrieveChildrenMetadata(MetadataType metadata); diff -r 4bfd885fb45f -r 732ec9feeea8 OrthancServer/Sources/Database/FindResponse.cpp --- 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::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::const_iterator it = childrenIdentifiers_.begin(); + it != childrenIdentifiers_.end(); ++it) + { + v.append(*it); + } + target[level]["Identifiers"] = v; + } + } } - target["Children"] = v; } if (request.IsRetrieveLabels()) diff -r 4bfd885fb45f -r 732ec9feeea8 OrthancServer/Sources/ResourceFinder.cpp --- 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); diff -r 4bfd885fb45f -r 732ec9feeea8 OrthancServer/Sources/ResourceFinder.h --- 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& tags); void Execute(Json::Value& target, - ServerContext& context); + ServerContext& context) const; bool ExecuteOneResource(Json::Value& target, - ServerContext& context); + ServerContext& context) const; }; }