Mercurial > hg > orthanc
changeset 5710:a786da7599d5 find-refactoring-clean
integration find-refactoring->find-refactoring-clean
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Jul 2024 18:55:22 +0200 |
parents | c8d21a09aae6 (current diff) 476b1db52110 (diff) |
children | 31eb66eaed86 |
files | OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancWebDav.cpp |
diffstat | 4 files changed, 79 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- 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<MetadataType, std::string>& metadata = resource.GetMetadata(level); + + Json::Value tmp; + + for (std::map<MetadataType, std::string>::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 <enum ResourceType resourceType> @@ -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<DicomTag> 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); }
--- 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) {
--- 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) {
--- 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<DicomTag> 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; }; }