# HG changeset patch # User Sebastien Jodogne # Date 1720803322 -7200 # Node ID a786da7599d5b2ad502529fa18f861c5741cf60b # Parent c8d21a09aae679133d83c2140cc020fba685cb8c# Parent 476b1db521101593bd012f3dc99159aeaf56f616 integration find-refactoring->find-refactoring-clean diff -r c8d21a09aae6 -r a786da7599d5 OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jul 12 17:58:15 2024 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jul 12 18:55:22 2024 +0200 @@ -129,6 +129,49 @@ } + 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.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, format); + + 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 ---------------------- template @@ -164,7 +207,6 @@ ResourceFinder finder(resourceType, expand); finder.AddRequestedTags(requestedTags); - finder.SetFormat(OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human)); if (call.HasArgument("limit") || call.HasArgument("since")) @@ -190,7 +232,7 @@ } Json::Value answer; - finder.Execute(answer, OrthancRestApi::GetContext(call)); + finder.Execute(answer, OrthancRestApi::GetContext(call), OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human)); call.GetOutput().AnswerJson(answer); } @@ -218,13 +260,14 @@ std::set requestedTags; OrthancRestApi::GetRequestedTags(requestedTags, call); + const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human); + ResourceFinder finder(resourceType, true /* expand */); finder.AddRequestedTags(requestedTags); - finder.SetFormat(OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human)); finder.SetOrthancId(resourceType, call.GetUriComponent("id", "")); Json::Value json; - if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call))) + if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format)) { call.GetOutput().AnswerJson(json); } @@ -3133,7 +3176,8 @@ ResourceFinder finder(level, expand); finder.SetDatabaseLimits(context.GetDatabaseLimits(level)); - finder.SetFormat(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human)); + + const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); if (request.isMember(KEY_LIMIT)) { @@ -3242,7 +3286,7 @@ } Json::Value answer; - finder.Execute(answer, context); + finder.Execute(answer, context, format); call.GetOutput().AnswerJson(answer); } } @@ -3283,10 +3327,9 @@ ResourceFinder finder(end, expand); finder.SetOrthancId(start, call.GetUriComponent("id", "")); finder.AddRequestedTags(requestedTags); - finder.SetFormat(format); Json::Value answer; - finder.Execute(answer, OrthancRestApi::GetContext(call)); + finder.Execute(answer, OrthancRestApi::GetContext(call), format); call.GetOutput().AnswerJson(answer); } diff -r c8d21a09aae6 -r a786da7599d5 OrthancServer/Sources/OrthancWebDav.cpp --- a/OrthancServer/Sources/OrthancWebDav.cpp Fri Jul 12 17:58:15 2024 +0200 +++ b/OrthancServer/Sources/OrthancWebDav.cpp Fri Jul 12 18:55:22 2024 +0200 @@ -1447,7 +1447,7 @@ finder.SetDatabaseLookup(query); Json::Value expanded; - finder.Execute(expanded, context); + finder.Execute(expanded, context, DicomToJsonFormat_Human); if (expanded.size() != 1) { diff -r c8d21a09aae6 -r a786da7599d5 OrthancServer/Sources/ResourceFinder.cpp --- a/OrthancServer/Sources/ResourceFinder.cpp Fri Jul 12 17:58:15 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.cpp Fri Jul 12 18:55:22 2024 +0200 @@ -190,7 +190,8 @@ void ResourceFinder::Expand(Json::Value& target, const FindResponse::Resource& resource, - ServerIndex& index) const + ServerIndex& index, + DicomToJsonFormat format) const { /** * This method closely follows "SerializeExpandedResource()" in @@ -382,7 +383,7 @@ allMainDicomTags.ExtractResourceInformation(levelMainDicomTags, resource.GetLevel()); target[MAIN_DICOM_TAGS] = Json::objectValue; - FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format_); + FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format); if (resource.GetLevel() == ResourceType_Study) { @@ -390,7 +391,7 @@ allMainDicomTags.ExtractPatientInformation(patientMainDicomTags); target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue; - FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format_); + FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format); } } @@ -481,7 +482,6 @@ limitsSince_(0), limitsCount_(0), expand_(expand), - format_(DicomToJsonFormat_Human), allowStorageAccess_(true), hasRequestedTags_(false), includeAllMetadata_(false) @@ -1002,24 +1002,28 @@ void ResourceFinder::Execute(Json::Value& target, - ServerContext& context) const + ServerContext& context, + DicomToJsonFormat format) const { class Visitor : public IVisitor { private: const ResourceFinder& that_; - ServerIndex& index_; - Json::Value& target_; - bool hasRequestedTags_; + ServerIndex& index_; + Json::Value& target_; + DicomToJsonFormat format_; + bool hasRequestedTags_; public: Visitor(const ResourceFinder& that, ServerIndex& index, Json::Value& target, + DicomToJsonFormat format, bool hasRequestedTags) : that_(that), index_(index), target_(target), + format_(format), hasRequestedTags_(hasRequestedTags) { } @@ -1030,13 +1034,13 @@ if (that_.expand_) { Json::Value item; - that_.Expand(item, resource, index_); + that_.Expand(item, resource, index_, format_); if (hasRequestedTags_) { static const char* const REQUESTED_TAGS = "RequestedTags"; item[REQUESTED_TAGS] = Json::objectValue; - FromDcmtkBridge::ToJson(item[REQUESTED_TAGS], requestedTags, that_.format_); + FromDcmtkBridge::ToJson(item[REQUESTED_TAGS], requestedTags, format_); } target_.append(item); @@ -1054,16 +1058,17 @@ target = Json::arrayValue; - Visitor visitor(*this, context.GetIndex(), target, hasRequestedTags_); + Visitor visitor(*this, context.GetIndex(), target, format, hasRequestedTags_); Execute(visitor, context); } bool ResourceFinder::ExecuteOneResource(Json::Value& target, - ServerContext& context) const + ServerContext& context, + DicomToJsonFormat format) const { Json::Value answer; - Execute(answer, context); + Execute(answer, context, format); if (answer.type() != Json::arrayValue) { diff -r c8d21a09aae6 -r a786da7599d5 OrthancServer/Sources/ResourceFinder.h --- a/OrthancServer/Sources/ResourceFinder.h Fri Jul 12 17:58:15 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.h Fri Jul 12 18:55:22 2024 +0200 @@ -66,7 +66,6 @@ uint64_t limitsSince_; uint64_t limitsCount_; bool expand_; - DicomToJsonFormat format_; bool allowStorageAccess_; bool hasRequestedTags_; std::set requestedPatientTags_; @@ -97,10 +96,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: @@ -125,11 +120,6 @@ request_.SetOrthancId(level, id); } - void SetFormat(DicomToJsonFormat format) - { - format_ = format; - } - void SetLimitsSince(uint64_t since); void SetLimitsCount(uint64_t count); @@ -175,6 +165,11 @@ request_.SetRetrieveAttachments(retrieve); } + void Expand(Json::Value& target, + const FindResponse::Resource& resource, + ServerIndex& index, + DicomToJsonFormat format) const; + void Execute(FindResponse& target, ServerIndex& index) const; @@ -182,9 +177,11 @@ ServerContext& context) const; void Execute(Json::Value& target, - ServerContext& context) const; + ServerContext& context, + DicomToJsonFormat format) const; bool ExecuteOneResource(Json::Value& target, - ServerContext& context) const; + ServerContext& context, + DicomToJsonFormat format) const; }; }