Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5825:881cd0965146 find-refactoring
added OrderBy support in SQLite
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Fri, 04 Oct 2024 19:03:14 +0200 |
parents | 272b0d0eef38 |
children | d73dfb4548c6 |
comparison
equal
deleted
inserted
replaced
5819:7c2b4fa94633 | 5825:881cd0965146 |
---|---|
3246 static const char* const KEY_QUERY = "Query"; | 3246 static const char* const KEY_QUERY = "Query"; |
3247 static const char* const KEY_REQUESTED_TAGS = "RequestedTags"; | 3247 static const char* const KEY_REQUESTED_TAGS = "RequestedTags"; |
3248 static const char* const KEY_SINCE = "Since"; | 3248 static const char* const KEY_SINCE = "Since"; |
3249 static const char* const KEY_LABELS = "Labels"; // New in Orthanc 1.12.0 | 3249 static const char* const KEY_LABELS = "Labels"; // New in Orthanc 1.12.0 |
3250 static const char* const KEY_LABELS_CONSTRAINT = "LabelsConstraint"; // New in Orthanc 1.12.0 | 3250 static const char* const KEY_LABELS_CONSTRAINT = "LabelsConstraint"; // New in Orthanc 1.12.0 |
3251 static const char* const KEY_ORDER_BY = "OrderBy"; // New in Orthanc 1.12.5 | |
3252 static const char* const KEY_ORDER_BY_KEY = "Key"; // New in Orthanc 1.12.5 | |
3253 static const char* const KEY_ORDER_BY_TYPE = "Type"; // New in Orthanc 1.12.5 | |
3254 static const char* const KEY_ORDER_BY_DIRECTION = "Direction"; // New in Orthanc 1.12.5 | |
3255 | |
3251 | 3256 |
3252 if (call.IsDocumentation()) | 3257 if (call.IsDocumentation()) |
3253 { | 3258 { |
3254 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); | 3259 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); |
3255 | 3260 |
3279 "Associative array containing the filter on the values of the DICOM tags", true) | 3284 "Associative array containing the filter on the values of the DICOM tags", true) |
3280 .SetRequestField(KEY_LABELS, RestApiCallDocumentation::Type_JsonListOfStrings, | 3285 .SetRequestField(KEY_LABELS, RestApiCallDocumentation::Type_JsonListOfStrings, |
3281 "List of strings specifying which labels to look for in the resources (new in Orthanc 1.12.0)", true) | 3286 "List of strings specifying which labels to look for in the resources (new in Orthanc 1.12.0)", true) |
3282 .SetRequestField(KEY_LABELS_CONSTRAINT, RestApiCallDocumentation::Type_String, | 3287 .SetRequestField(KEY_LABELS_CONSTRAINT, RestApiCallDocumentation::Type_String, |
3283 "Constraint on the labels, can be `All`, `Any`, or `None` (defaults to `All`, new in Orthanc 1.12.0)", true) | 3288 "Constraint on the labels, can be `All`, `Any`, or `None` (defaults to `All`, new in Orthanc 1.12.0)", true) |
3289 .SetRequestField(KEY_ORDER_BY, RestApiCallDocumentation::Type_JsonListOfObjects, | |
3290 "Array of associative arrays containing the requested ordering", true) | |
3284 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " | 3291 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " |
3285 "about the reported resources (if `Expand` argument is `true`)"); | 3292 "about the reported resources (if `Expand` argument is `true`)"); |
3286 return; | 3293 return; |
3287 } | 3294 } |
3288 | 3295 |
3340 else if (request.isMember(KEY_LABELS_CONSTRAINT) && | 3347 else if (request.isMember(KEY_LABELS_CONSTRAINT) && |
3341 request[KEY_LABELS_CONSTRAINT].type() != Json::stringValue) | 3348 request[KEY_LABELS_CONSTRAINT].type() != Json::stringValue) |
3342 { | 3349 { |
3343 throw OrthancException(ErrorCode_BadRequest, | 3350 throw OrthancException(ErrorCode_BadRequest, |
3344 "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be an array of strings"); | 3351 "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be an array of strings"); |
3352 } | |
3353 else if (request.isMember(KEY_ORDER_BY) && | |
3354 request[KEY_ORDER_BY].type() != Json::arrayValue) | |
3355 { | |
3356 throw OrthancException(ErrorCode_BadRequest, | |
3357 "Field \"" + std::string(KEY_ORDER_BY) + "\" must be an array"); | |
3345 } | 3358 } |
3346 else if (true) | 3359 else if (true) |
3347 { | 3360 { |
3348 /** | 3361 /** |
3349 * EXPERIMENTAL VERSION | 3362 * EXPERIMENTAL VERSION |
3463 finder.SetLabelsConstraint(LabelsConstraint_None); | 3476 finder.SetLabelsConstraint(LabelsConstraint_None); |
3464 } | 3477 } |
3465 else | 3478 else |
3466 { | 3479 { |
3467 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\""); | 3480 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\""); |
3481 } | |
3482 } | |
3483 | |
3484 if (request.isMember(KEY_ORDER_BY)) // New in Orthanc 1.12.5 | |
3485 { | |
3486 for (Json::Value::ArrayIndex i = 0; i < request[KEY_ORDER_BY].size(); i++) | |
3487 { | |
3488 if (request[KEY_ORDER_BY][i].type() != Json::objectValue) | |
3489 { | |
3490 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY) + "\" must contain objects"); | |
3491 } | |
3492 else | |
3493 { | |
3494 const Json::Value& order = request[KEY_ORDER_BY][i]; | |
3495 FindRequest::OrderingDirection direction; | |
3496 std::string directionString; | |
3497 std::string typeString; | |
3498 | |
3499 if (!order.isMember(KEY_ORDER_BY_KEY) || order[KEY_ORDER_BY_KEY].type() != Json::stringValue) | |
3500 { | |
3501 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_KEY) + "\" must be a string"); | |
3502 } | |
3503 | |
3504 if (!order.isMember(KEY_ORDER_BY_DIRECTION) || order[KEY_ORDER_BY_DIRECTION].type() != Json::stringValue) | |
3505 { | |
3506 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_DIRECTION) + "\" must be \"ASC\" or \"DESC\""); | |
3507 } | |
3508 | |
3509 Toolbox::ToLowerCase(directionString, order[KEY_ORDER_BY_DIRECTION].asString()); | |
3510 if (directionString == "asc") | |
3511 { | |
3512 direction = FindRequest::OrderingDirection_Ascending; | |
3513 } | |
3514 else if (directionString == "desc") | |
3515 { | |
3516 direction = FindRequest::OrderingDirection_Descending; | |
3517 } | |
3518 else | |
3519 { | |
3520 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_DIRECTION) + "\" must be \"ASC\" or \"DESC\""); | |
3521 } | |
3522 | |
3523 if (!order.isMember(KEY_ORDER_BY_TYPE) || order[KEY_ORDER_BY_TYPE].type() != Json::stringValue) | |
3524 { | |
3525 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_TYPE) + "\" must be \"DicomTag\" or \"Metadata\""); | |
3526 } | |
3527 | |
3528 Toolbox::ToLowerCase(typeString, order[KEY_ORDER_BY_TYPE].asString()); | |
3529 if (typeString == "dicomtag") | |
3530 { | |
3531 DicomTag tag = FromDcmtkBridge::ParseTag(order[KEY_ORDER_BY_KEY].asString()); | |
3532 finder.AddOrdering(tag, direction); | |
3533 } | |
3534 else if (typeString == "metadata") | |
3535 { | |
3536 MetadataType metadata = StringToMetadata(order[KEY_ORDER_BY_KEY].asString()); | |
3537 finder.AddOrdering(metadata, direction); | |
3538 } | |
3539 else | |
3540 { | |
3541 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_TYPE) + "\" must be \"DicomTag\" or \"Metadata\""); | |
3542 } | |
3543 } | |
3468 } | 3544 } |
3469 } | 3545 } |
3470 | 3546 |
3471 Json::Value answer; | 3547 Json::Value answer; |
3472 finder.Execute(answer, context, format, false /* no "Metadata" field */); | 3548 finder.Execute(answer, context, format, false /* no "Metadata" field */); |