# HG changeset patch # User Sebastien Jodogne # Date 1714829119 -7200 # Node ID a906dc19264c315be987da23b7d16dd2c99f0f9d # Parent 862b54b4cfe2707f98eb2afa6a0b3b76549887f5 created FindResponse::Resource::Format() diff -r 862b54b4cfe2 -r a906dc19264c OrthancServer/Sources/Database/Compatibility/GenericFind.cpp --- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Sat May 04 11:35:34 2024 +0200 +++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp Sat May 04 15:25:19 2024 +0200 @@ -40,8 +40,8 @@ !request.GetOrthancIdentifiers().HasInstanceId() && request.GetDicomTagConstraintsCount() == 0 && request.GetMetadataConstraintsCount() == 0 && - request.GetOrdering().empty() && - request.GetLabels().empty()) + request.GetLabels().empty() && + request.GetOrdering().empty()) { if (request.HasLimits()) { @@ -64,9 +64,9 @@ const std::string& identifier) { int64_t internalId; - ResourceType t; - if (!transaction_.LookupResource(internalId, t, identifier) || - t != request.GetLevel()) + ResourceType level; + if (!transaction_.LookupResource(internalId, level, identifier) || + level != request.GetLevel()) { throw OrthancException(ErrorCode_InternalError); } @@ -94,6 +94,37 @@ } } + if (request.IsRetrieveMetadata()) + { + transaction_.GetAllMetadata(resource->GetMetadata(), internalId); + } + + if (request.IsRetrieveLabels()) + { + transaction_.ListLabels(resource->GetLabels(), internalId); + } + + if (request.IsRetrieveAttachments()) + { + std::set attachments; + transaction_.ListAvailableAttachments(attachments, internalId); + + for (std::set::const_iterator it = attachments.begin(); it != attachments.end(); ++it) + { + FileInfo info; + int64_t revision; + if (transaction_.LookupAttachment(info, revision, internalId, *it) && + info.GetContentType() == *it) + { + resource->AddAttachment(info); + } + else + { + throw OrthancException(ErrorCode_InternalError); + } + } + } + if (request.IsRetrieveParentIdentifier()) { int64_t parentId; @@ -107,23 +138,22 @@ } } - // TODO-FIND: Continue - - - /** - * Sanity checks - **/ + if (request.IsRetrieveChildrenIdentifiers()) + { + std::list children; + transaction_.GetChildrenPublicId(children, internalId); - if (request.IsRetrieveMainDicomTags()) - { - DicomMap tmp; - resource->GetMainDicomTags(tmp); - if (tmp.GetSize() == 0) + for (std::list::const_iterator it = children.begin(); it != children.end(); ++it) { - throw OrthancException(ErrorCode_InternalError); + resource->AddChildIdentifier(GetChildResourceType(level), *it); } } + if (request.IsRetrieveChildrenMetadata()) + { + // TODO-FIND + throw OrthancException(ErrorCode_NotImplemented); + } response.Add(resource.release()); } diff -r 862b54b4cfe2 -r a906dc19264c OrthancServer/Sources/Database/FindResponse.cpp --- a/OrthancServer/Sources/Database/FindResponse.cpp Sat May 04 11:35:34 2024 +0200 +++ b/OrthancServer/Sources/Database/FindResponse.cpp Sat May 04 15:25:19 2024 +0200 @@ -324,6 +324,115 @@ } + void FindResponse::Resource::Format(Json::Value& target, + const FindRequest& request) const + { + /** + + TODO-FIND: + + - Metadata / Series / ExpectedNumberOfInstances + + - Metadata / Series / Status + + - Metadata / Instance / FileSize + + - Metadata / Instance / FileUuid + + - Metadata / Instance / IndexInSeries + + - Metadata / AnonymizedFrom + + - Metadata / ModifiedFrom + + **/ + + target = Json::objectValue; + target["ID"] = identifier_; + target["Type"] = GetResourceTypeText(level_, false, true); + + if (request.IsRetrieveMetadata()) + { + Json::Value metadata = Json::objectValue; + + for (std::map::const_iterator + it = metadata_.begin(); it != metadata_.end(); ++it) + { + metadata[EnumerationToString(it->first)] = it->second; + } + + target["Metadata"] = metadata; + } + + if (request.IsRetrieveLabels()) + { + Json::Value labels = Json::arrayValue; + + for (std::set::const_iterator it = labels_.begin(); it != labels_.end(); ++it) + { + labels.append(*it); + } + + target["Labels"] = labels; + } + + if (request.IsRetrieveParentIdentifier()) + { + switch (level_) + { + case ResourceType_Patient: + break; + + case ResourceType_Study: + target["ParentPatient"] = GetParentIdentifier(); + break; + + case ResourceType_Series: + target["ParentStudy"] = GetParentIdentifier(); + break; + + case ResourceType_Instance: + target["ParentSeries"] = GetParentIdentifier(); + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + } + + if (request.IsRetrieveChildrenIdentifiers()) + { + Json::Value c = Json::arrayValue; + + const std::set& children = GetChildrenAtLevel(GetChildResourceType(level_)).GetIdentifiers(); + + for (std::set::const_iterator + it = children.begin(); it != children.end(); ++it) + { + c.append(*it); + } + + switch (level_) + { + case ResourceType_Patient: + target["Studies"] = c; + break; + + case ResourceType_Study: + target["Series"] = c; + break; + + case ResourceType_Series: + target["Instances"] = c; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + } + } + + FindResponse::~FindResponse() { for (size_t i = 0; i < items_.size(); i++) diff -r 862b54b4cfe2 -r a906dc19264c OrthancServer/Sources/Database/FindResponse.h --- a/OrthancServer/Sources/Database/FindResponse.h Sat May 04 11:35:34 2024 +0200 +++ b/OrthancServer/Sources/Database/FindResponse.h Sat May 04 15:25:19 2024 +0200 @@ -77,6 +77,11 @@ ChildrenAtLevel& GetChildrenAtLevel(ResourceType level); + const ChildrenAtLevel& GetChildrenAtLevel(ResourceType level) const + { + return const_cast(*this).GetChildrenAtLevel(level); + } + public: Resource(ResourceType level, const std::string& identifier) : @@ -127,6 +132,11 @@ void AddLabel(const std::string& label); + std::set& GetLabels() + { + return labels_; + } + const std::set& GetLabels() const { return labels_; @@ -135,6 +145,11 @@ void AddMetadata(MetadataType metadata, const std::string& value); + std::map& GetMetadata() + { + return metadata_; + } + const std::map& GetMetadata() const { return metadata_; @@ -154,6 +169,9 @@ bool LookupAttachment(FileInfo& target, FileContentType type) const; + + void Format(Json::Value& target, + const FindRequest& request) const; }; private: