# HG changeset patch # User Sebastien Jodogne # Date 1720801874 -7200 # Node ID 1891a8c2dbb43bfa7a8f6a962b9e9ca3b395fc85 # Parent eb56ee3c5d633bd1583ff1c589dc414f05d25f06 added ExpandResource utility diff -r eb56ee3c5d63 -r 1891a8c2dbb4 OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jul 12 17:51:52 2024 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jul 12 18:31:14 2024 +0200 @@ -129,6 +129,50 @@ } + static bool ExpandResource(Json::Value& target, + ServerIndex& index, + ResourceType level, + const std::string& identifier, + DicomToJsonFormat format, + bool retrieveMetadata) + { + ResourceFinder finder(level, true /* expand */); + finder.SetOrthancId(level, identifier); + finder.SetFormat(format); + finder.SetRetrieveMetadata(retrieveMetadata); + + FindResponse response; + finder.Execute(response, index); + + if (response.GetSize() != 1) + { + return false; + } + else + { + const FindResponse::Resource& resource = response.GetResourceByIndex(0); + finder.Expand(target, resource, index); + + if (retrieveMetadata) + { + const std::map& metadata = resource.GetMetadata(level); + + Json::Value tmp; + + for (std::map::const_iterator + it = metadata.begin(); it != metadata.end(); ++it) + { + tmp[EnumerationToString(it->first)] = it->second; + } + + target["Metadata"] = tmp; + } + + return true; + } + } + + // List all the patients, studies, series or instances ---------------------- static void AnswerListOfResources1(RestApiOutput& output, @@ -3770,9 +3814,26 @@ const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human); Json::Value resource; - if (OrthancRestApi::GetContext(call).ExpandResource(resource, current, end, format, requestedTags, true /* allowStorageAccess */)) + + if (true) { - call.GetOutput().AnswerJson(resource); + /** + * EXPERIMENTAL VERSION + **/ + if (ExpandResource(resource, OrthancRestApi::GetIndex(call), currentType, current, format, false)) + { + call.GetOutput().AnswerJson(resource); + } + } + else + { + /** + * VERSION IN ORTHANC <= 1.12.4 + **/ + if (OrthancRestApi::GetContext(call).ExpandResource(resource, current, end, format, requestedTags, true /* allowStorageAccess */)) + { + call.GetOutput().AnswerJson(resource); + } } } @@ -4203,17 +4264,34 @@ for (std::set::const_iterator it = interest.begin(); it != interest.end(); ++it) { - Json::Value item; - std::set emptyRequestedTags; // not supported for bulk content - - if (OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) + if (true) + { + /** + * EXPERIMENTAL VERSION + **/ + Json::Value item; + if (ExpandResource(item, OrthancRestApi::GetIndex(call), level, *it, format, metadata)) + { + answer.append(item); + } + } + else { - if (metadata) + /** + * VERSION IN ORTHANC <= 1.12.4 + **/ + Json::Value item; + std::set emptyRequestedTags; // not supported for bulk content + + if (OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) { - AddMetadata(item[METADATA], index, *it, level); + if (metadata) + { + AddMetadata(item[METADATA], index, *it, level); + } + + answer.append(item); } - - answer.append(item); } } } @@ -4230,19 +4308,36 @@ Json::Value item; std::set emptyRequestedTags; // not supported for bulk content - if (index.LookupResourceType(level, *it) && - OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) + if (true) { - if (metadata) + /** + * EXPERIMENTAL VERSION + **/ + if (index.LookupResourceType(level, *it) && + ExpandResource(item, OrthancRestApi::GetIndex(call), level, *it, format, metadata)) { - AddMetadata(item[METADATA], index, *it, level); + answer.append(item); } - - answer.append(item); } else { - CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; + /** + * VERSION IN ORTHANC <= 1.12.4 + **/ + if (index.LookupResourceType(level, *it) && + OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) + { + if (metadata) + { + AddMetadata(item[METADATA], index, *it, level); + } + + answer.append(item); + } + else + { + CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; + } } } } diff -r eb56ee3c5d63 -r 1891a8c2dbb4 OrthancServer/Sources/ResourceFinder.h --- a/OrthancServer/Sources/ResourceFinder.h Fri Jul 12 17:51:52 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.h Fri Jul 12 18:31:14 2024 +0200 @@ -97,10 +97,6 @@ void InjectComputedTags(DicomMap& requestedTags, const FindResponse::Resource& resource) const; - void Expand(Json::Value& target, - const FindResponse::Resource& resource, - ServerIndex& index) const; - void UpdateRequestLimits(); public: @@ -175,6 +171,10 @@ request_.SetRetrieveAttachments(retrieve); } + void Expand(Json::Value& target, + const FindResponse::Resource& resource, + ServerIndex& index) const; + void Execute(FindResponse& target, ServerIndex& index) const;