# HG changeset patch # User Sebastien Jodogne # Date 1624453069 -7200 # Node ID 8ffe2fdb541ff8441d1ac51b1989c6cb41209ce0 # Parent 8866981e2f58fcebca4c3367506ac0bb37a9cd29 added argument "Metadata" to "/tools/bulk-content" diff -r 8866981e2f58 -r 8ffe2fdb541f OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Wed Jun 23 14:33:46 2021 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Wed Jun 23 14:57:49 2021 +0200 @@ -3113,8 +3113,29 @@ } + static void AddMetadata(Json::Value& target, + ServerIndex& index, + const std::string& resource, + ResourceType level) + { + target = Json::objectValue; + + std::map content; + index.GetAllMetadata(content, resource, level); + + for (std::map::const_iterator + it = content.begin(); it != content.end(); ++it) + { + target[EnumerationToString(it->first)] = it->second; + } + } + + static void BulkContent(RestApiPostCall& call) { + static const char* const LEVEL = "Level"; + static const char* const METADATA = "Metadata"; + if (call.IsDocumentation()) { OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); @@ -3124,10 +3145,12 @@ .SetSummary("Describe a set of instances") .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true) - .SetRequestField("Level", RestApiCallDocumentation::Type_String, + .SetRequestField(LEVEL, RestApiCallDocumentation::Type_String, "This optional argument specifies the level of interest (can be `Patient`, `Study`, `Series` or " "`Instance`). Orthanc will loop over the items inside `Resources`, and explorer upward or " "downward in the DICOM hierarchy in order to find the level of interest.", false) + .SetRequestField(METADATA, RestApiCallDocumentation::Type_Boolean, + "If set to `true` (default value), the metadata associated with the resources will also be retrieved.", false) .SetDescription("Get the content all the DICOM patients, studies, series or instances " "whose identifiers are provided in the `Resources` field, in one single call."); return; @@ -3142,10 +3165,14 @@ } else { - static const char* const LEVEL = "Level"; - const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); + bool metadata = true; + if (request.isMember(METADATA)) + { + metadata = SerializationToolbox::ReadBoolean(request, METADATA); + } + ServerIndex& index = OrthancRestApi::GetIndex(call); Json::Value answer = Json::arrayValue; @@ -3243,6 +3270,11 @@ Json::Value item; if (index.ExpandResource(item, *it, level, format)) { + if (metadata) + { + AddMetadata(item[METADATA], index, *it, level); + } + answer.append(item); } } @@ -3256,11 +3288,16 @@ for (std::list::const_iterator it = resources.begin(); it != resources.end(); ++it) { - ResourceType type; + ResourceType level; Json::Value item; - if (index.LookupResourceType(type, *it) && - index.ExpandResource(item, *it, type, format)) + if (index.LookupResourceType(level, *it) && + index.ExpandResource(item, *it, level, format)) { + if (metadata) + { + AddMetadata(item[METADATA], index, *it, level); + } + answer.append(item); } else