comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4714:8ffe2fdb541f

added argument "Metadata" to "/tools/bulk-content"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Jun 2021 14:57:49 +0200
parents facea16b055b
children 758fe3ffb336
comparison
equal deleted inserted replaced
4713:8866981e2f58 4714:8ffe2fdb541f
3111 } 3111 }
3112 } 3112 }
3113 } 3113 }
3114 3114
3115 3115
3116 static void AddMetadata(Json::Value& target,
3117 ServerIndex& index,
3118 const std::string& resource,
3119 ResourceType level)
3120 {
3121 target = Json::objectValue;
3122
3123 std::map<MetadataType, std::string> content;
3124 index.GetAllMetadata(content, resource, level);
3125
3126 for (std::map<MetadataType, std::string>::const_iterator
3127 it = content.begin(); it != content.end(); ++it)
3128 {
3129 target[EnumerationToString(it->first)] = it->second;
3130 }
3131 }
3132
3133
3116 static void BulkContent(RestApiPostCall& call) 3134 static void BulkContent(RestApiPostCall& call)
3117 { 3135 {
3136 static const char* const LEVEL = "Level";
3137 static const char* const METADATA = "Metadata";
3138
3118 if (call.IsDocumentation()) 3139 if (call.IsDocumentation())
3119 { 3140 {
3120 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); 3141 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
3121 3142
3122 call.GetDocumentation() 3143 call.GetDocumentation()
3123 .SetTag("System") 3144 .SetTag("System")
3124 .SetSummary("Describe a set of instances") 3145 .SetSummary("Describe a set of instances")
3125 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, 3146 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings,
3126 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true) 3147 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true)
3127 .SetRequestField("Level", RestApiCallDocumentation::Type_String, 3148 .SetRequestField(LEVEL, RestApiCallDocumentation::Type_String,
3128 "This optional argument specifies the level of interest (can be `Patient`, `Study`, `Series` or " 3149 "This optional argument specifies the level of interest (can be `Patient`, `Study`, `Series` or "
3129 "`Instance`). Orthanc will loop over the items inside `Resources`, and explorer upward or " 3150 "`Instance`). Orthanc will loop over the items inside `Resources`, and explorer upward or "
3130 "downward in the DICOM hierarchy in order to find the level of interest.", false) 3151 "downward in the DICOM hierarchy in order to find the level of interest.", false)
3152 .SetRequestField(METADATA, RestApiCallDocumentation::Type_Boolean,
3153 "If set to `true` (default value), the metadata associated with the resources will also be retrieved.", false)
3131 .SetDescription("Get the content all the DICOM patients, studies, series or instances " 3154 .SetDescription("Get the content all the DICOM patients, studies, series or instances "
3132 "whose identifiers are provided in the `Resources` field, in one single call."); 3155 "whose identifiers are provided in the `Resources` field, in one single call.");
3133 return; 3156 return;
3134 } 3157 }
3135 3158
3140 throw OrthancException(ErrorCode_BadRequest, 3163 throw OrthancException(ErrorCode_BadRequest,
3141 "The body must contain a JSON object"); 3164 "The body must contain a JSON object");
3142 } 3165 }
3143 else 3166 else
3144 { 3167 {
3145 static const char* const LEVEL = "Level";
3146
3147 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); 3168 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human);
3169
3170 bool metadata = true;
3171 if (request.isMember(METADATA))
3172 {
3173 metadata = SerializationToolbox::ReadBoolean(request, METADATA);
3174 }
3148 3175
3149 ServerIndex& index = OrthancRestApi::GetIndex(call); 3176 ServerIndex& index = OrthancRestApi::GetIndex(call);
3150 3177
3151 Json::Value answer = Json::arrayValue; 3178 Json::Value answer = Json::arrayValue;
3152 3179
3241 it = interest.begin(); it != interest.end(); ++it) 3268 it = interest.begin(); it != interest.end(); ++it)
3242 { 3269 {
3243 Json::Value item; 3270 Json::Value item;
3244 if (index.ExpandResource(item, *it, level, format)) 3271 if (index.ExpandResource(item, *it, level, format))
3245 { 3272 {
3273 if (metadata)
3274 {
3275 AddMetadata(item[METADATA], index, *it, level);
3276 }
3277
3246 answer.append(item); 3278 answer.append(item);
3247 } 3279 }
3248 } 3280 }
3249 } 3281 }
3250 else 3282 else
3254 SerializationToolbox::ReadListOfStrings(resources, request, "Resources"); 3286 SerializationToolbox::ReadListOfStrings(resources, request, "Resources");
3255 3287
3256 for (std::list<std::string>::const_iterator 3288 for (std::list<std::string>::const_iterator
3257 it = resources.begin(); it != resources.end(); ++it) 3289 it = resources.begin(); it != resources.end(); ++it)
3258 { 3290 {
3259 ResourceType type; 3291 ResourceType level;
3260 Json::Value item; 3292 Json::Value item;
3261 if (index.LookupResourceType(type, *it) && 3293 if (index.LookupResourceType(level, *it) &&
3262 index.ExpandResource(item, *it, type, format)) 3294 index.ExpandResource(item, *it, level, format))
3263 { 3295 {
3296 if (metadata)
3297 {
3298 AddMetadata(item[METADATA], index, *it, level);
3299 }
3300
3264 answer.append(item); 3301 answer.append(item);
3265 } 3302 }
3266 else 3303 else
3267 { 3304 {
3268 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; 3305 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it;