comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5829:963945d780d6 find-refactoring tip

tools/find ResponseContent
author Alain Mazy <am@orthanc.team>
date Mon, 07 Oct 2024 18:10:08 +0200
parents 7030fa489669
children
comparison
equal deleted inserted replaced
5828:7030fa489669 5829:963945d780d6
135 ResourceType level, 135 ResourceType level,
136 const std::string& identifier, 136 const std::string& identifier,
137 DicomToJsonFormat format, 137 DicomToJsonFormat format,
138 bool retrieveMetadata) 138 bool retrieveMetadata)
139 { 139 {
140 ResourceFinder finder(level, true /* expand */); 140 ResponseContentFlags responseContent = ResponseContentFlags_Default;
141
142 if (retrieveMetadata)
143 {
144 responseContent = static_cast<ResponseContentFlags>(static_cast<uint32_t>(responseContent) | ResponseContentFlags_Metadata);
145 }
146
147 ResourceFinder finder(level, responseContent);
141 finder.SetOrthancId(level, identifier); 148 finder.SetOrthancId(level, identifier);
142 finder.SetRetrieveMetadata(retrieveMetadata); 149 finder.SetRetrieveMetadata(retrieveMetadata);
143 150
144 return finder.ExecuteOneResource(target, context, format, retrieveMetadata); 151 return finder.ExecuteOneResource(target, context, format, retrieveMetadata);
145 } 152 }
256 call.GetBooleanArgument("expand", true)); 263 call.GetBooleanArgument("expand", true));
257 264
258 std::set<DicomTag> requestedTags; 265 std::set<DicomTag> requestedTags;
259 OrthancRestApi::GetRequestedTags(requestedTags, call); 266 OrthancRestApi::GetRequestedTags(requestedTags, call);
260 267
261 ResourceFinder finder(resourceType, expand); 268 ResourceFinder finder(resourceType, (expand ? ResponseContentFlags_Default : ResponseContentFlags_ID));
262 finder.AddRequestedTags(requestedTags); 269 finder.AddRequestedTags(requestedTags);
263 270
264 if (call.HasArgument("limit") || 271 if (call.HasArgument("limit") ||
265 call.HasArgument("since")) 272 call.HasArgument("since"))
266 { 273 {
362 { 369 {
363 /** 370 /**
364 * EXPERIMENTAL VERSION 371 * EXPERIMENTAL VERSION
365 **/ 372 **/
366 373
367 ResourceFinder finder(resourceType, true /* expand */); 374 ResourceFinder finder(resourceType, ResponseContentFlags_Default);
368 finder.AddRequestedTags(requestedTags); 375 finder.AddRequestedTags(requestedTags);
369 finder.SetOrthancId(resourceType, call.GetUriComponent("id", "")); 376 finder.SetOrthancId(resourceType, call.GetUriComponent("id", ""));
370 377
371 Json::Value json; 378 Json::Value json;
372 if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format, false /* no "Metadata" field */)) 379 if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format, false /* no "Metadata" field */))
3255 static const char* const KEY_ORDER_BY_DIRECTION = "Direction"; // New in Orthanc 1.12.5 3262 static const char* const KEY_ORDER_BY_DIRECTION = "Direction"; // New in Orthanc 1.12.5
3256 static const char* const KEY_PARENT_PATIENT = "ParentPatient"; // New in Orthanc 1.12.5 3263 static const char* const KEY_PARENT_PATIENT = "ParentPatient"; // New in Orthanc 1.12.5
3257 static const char* const KEY_PARENT_STUDY = "ParentStudy"; // New in Orthanc 1.12.5 3264 static const char* const KEY_PARENT_STUDY = "ParentStudy"; // New in Orthanc 1.12.5
3258 static const char* const KEY_PARENT_SERIES = "ParentSeries"; // New in Orthanc 1.12.5 3265 static const char* const KEY_PARENT_SERIES = "ParentSeries"; // New in Orthanc 1.12.5
3259 static const char* const KEY_QUERY_METADATA = "QueryMetadata"; // New in Orthanc 1.12.5 3266 static const char* const KEY_QUERY_METADATA = "QueryMetadata"; // New in Orthanc 1.12.5
3267 static const char* const KEY_RESPONSE_CONTENT = "ResponseContent"; // New in Orthanc 1.12.5
3260 3268
3261 if (call.IsDocumentation()) 3269 if (call.IsDocumentation())
3262 { 3270 {
3263 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); 3271 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
3264 3272
3298 "Limit the reported resources to descendants of this study (new in Orthanc 1.12.5)", true) 3306 "Limit the reported resources to descendants of this study (new in Orthanc 1.12.5)", true)
3299 .SetRequestField(KEY_PARENT_SERIES, RestApiCallDocumentation::Type_String, 3307 .SetRequestField(KEY_PARENT_SERIES, RestApiCallDocumentation::Type_String,
3300 "Limit the reported resources to descendants of this series (new in Orthanc 1.12.5)", true) 3308 "Limit the reported resources to descendants of this series (new in Orthanc 1.12.5)", true)
3301 .SetRequestField(KEY_QUERY_METADATA, RestApiCallDocumentation::Type_JsonObject, 3309 .SetRequestField(KEY_QUERY_METADATA, RestApiCallDocumentation::Type_JsonObject,
3302 "Associative array containing the filter on the values of the metadata (new in Orthanc 1.12.5)", true) 3310 "Associative array containing the filter on the values of the metadata (new in Orthanc 1.12.5)", true)
3311 .SetRequestField(KEY_RESPONSE_CONTENT, RestApiCallDocumentation::Type_JsonListOfStrings,
3312 "Defines the content of response for each returned resource. Allowed values are `MainDicomTags`, "
3313 "`Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`, `Attachments`. "
3314 "(new in Orthanc 1.12.5)", true)
3303 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " 3315 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information "
3304 "about the reported resources (if `Expand` argument is `true`)"); 3316 "about the reported resources (if `Expand` argument is `true`)");
3305 return; 3317 return;
3306 } 3318 }
3307 3319
3348 request[KEY_REQUESTED_TAGS].type() != Json::arrayValue) 3360 request[KEY_REQUESTED_TAGS].type() != Json::arrayValue)
3349 { 3361 {
3350 throw OrthancException(ErrorCode_BadRequest, 3362 throw OrthancException(ErrorCode_BadRequest,
3351 "Field \"" + std::string(KEY_REQUESTED_TAGS) + "\" must be an array"); 3363 "Field \"" + std::string(KEY_REQUESTED_TAGS) + "\" must be an array");
3352 } 3364 }
3365 else if (request.isMember(KEY_RESPONSE_CONTENT) &&
3366 request[KEY_RESPONSE_CONTENT].type() != Json::arrayValue)
3367 {
3368 throw OrthancException(ErrorCode_BadRequest,
3369 "Field \"" + std::string(KEY_RESPONSE_CONTENT) + "\" must be an array");
3370 }
3353 else if (request.isMember(KEY_LABELS) && 3371 else if (request.isMember(KEY_LABELS) &&
3354 request[KEY_LABELS].type() != Json::arrayValue) 3372 request[KEY_LABELS].type() != Json::arrayValue)
3355 { 3373 {
3356 throw OrthancException(ErrorCode_BadRequest, 3374 throw OrthancException(ErrorCode_BadRequest,
3357 "Field \"" + std::string(KEY_LABELS) + "\" must be an array of strings"); 3375 "Field \"" + std::string(KEY_LABELS) + "\" must be an array of strings");
3396 { 3414 {
3397 /** 3415 /**
3398 * EXPERIMENTAL VERSION 3416 * EXPERIMENTAL VERSION
3399 **/ 3417 **/
3400 3418
3401 bool expand = false; 3419 ResponseContentFlags responseContent = ResponseContentFlags_ID;
3402 if (request.isMember(KEY_EXPAND)) 3420
3403 { 3421 if (request.isMember(KEY_RESPONSE_CONTENT))
3404 expand = request[KEY_EXPAND].asBool(); 3422 {
3423 for (Json::ArrayIndex i = 0; i < request[KEY_RESPONSE_CONTENT].size(); ++i)
3424 {
3425 responseContent = static_cast<ResponseContentFlags>(static_cast<uint32_t>(responseContent) | StringToResponseContent(request[KEY_RESPONSE_CONTENT][i].asString()));
3426 }
3427 }
3428 else if (request.isMember(KEY_EXPAND) && request[KEY_EXPAND].asBool())
3429 {
3430 responseContent = ResponseContentFlags_Default;
3405 } 3431 }
3406 3432
3407 const ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); 3433 const ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString());
3408 3434
3409 ResourceFinder finder(level, expand); 3435 ResourceFinder finder(level, responseContent);
3410 finder.SetDatabaseLimits(context.GetDatabaseLimits(level)); 3436 finder.SetDatabaseLimits(context.GetDatabaseLimits(level));
3411 3437
3412 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); 3438 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human);
3413 3439
3414 if (request.isMember(KEY_LIMIT)) 3440 if (request.isMember(KEY_LIMIT))
3794 { 3820 {
3795 /** 3821 /**
3796 * EXPERIMENTAL VERSION 3822 * EXPERIMENTAL VERSION
3797 **/ 3823 **/
3798 3824
3799 ResourceFinder finder(end, expand); 3825 ResourceFinder finder(end, (expand ? ResponseContentFlags_Default : ResponseContentFlags_ID));
3800 finder.SetOrthancId(start, call.GetUriComponent("id", "")); 3826 finder.SetOrthancId(start, call.GetUriComponent("id", ""));
3801 finder.AddRequestedTags(requestedTags); 3827 finder.AddRequestedTags(requestedTags);
3802 3828
3803 Json::Value answer; 3829 Json::Value answer;
3804 finder.Execute(answer, context, format, false /* no "Metadata" field */); 3830 finder.Execute(answer, context, format, false /* no "Metadata" field */);