Mercurial > hg > orthanc
changeset 5880:00f650dc07bf find-refactoring
response-content
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Wed, 27 Nov 2024 15:00:58 +0100 |
parents | 022ce5323d09 |
children | 1c549458ea5d |
files | OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/ServerEnumerations.cpp |
diffstat | 4 files changed, 118 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp Thu Nov 07 10:27:28 2024 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp Wed Nov 27 15:00:58 2024 +0100 @@ -501,11 +501,15 @@ static const std::string GET_SHORT = "short"; static const std::string GET_REQUESTED_TAGS_OLD = "requestedTags"; // This was the only option in Orthanc <= 1.12.3 static const std::string GET_REQUESTED_TAGS = "requested-tags"; + static const std::string GET_RESPONSE_CONTENT = "response-content"; + static const std::string GET_EXPAND = "expand"; static const std::string POST_SIMPLIFY = "Simplify"; static const std::string POST_FULL = "Full"; static const std::string POST_SHORT = "Short"; static const std::string POST_REQUESTED_TAGS = "RequestedTags"; + static const std::string POST_RESPONSE_CONTENT = "ResponseContent"; + static const std::string POST_EXPAND = "Expand"; static const std::string DOCUMENT_SIMPLIFY = "report the DICOM tags in human-readable format (using the symbolic name of the tags)"; @@ -634,19 +638,100 @@ } catch (OrthancException& ex) { - throw OrthancException(ErrorCode_BadRequest, std::string("Invalid requestedTags argument: ") + ex.What() + " " + ex.GetDetails()); + throw OrthancException(ErrorCode_BadRequest, std::string("Invalid requested-tags argument: ") + ex.What() + " " + ex.GetDetails()); } } } - void OrthancRestApi::DocumentRequestedTags(RestApiGetCall& call) + void OrthancRestApi::DocumentRequestedTags(RestApiCall& call) { + if (call.GetMethod() == HttpMethod_Get) + { call.GetDocumentation().SetHttpGetArgument(GET_REQUESTED_TAGS, RestApiCallDocumentation::Type_String, "If present, list the DICOM Tags you want to list in the response. This argument is a semi-column separated list " "of DICOM Tags identifiers; e.g: '" + GET_REQUESTED_TAGS + "=0010,0010;PatientBirthDate'. " "The tags requested tags are returned in the 'RequestedTags' field in the response. " "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " - "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return ", false); + "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " + "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false); + } + else if (call.GetMethod() == HttpMethod_Post) + { + call.GetDocumentation().SetRequestField(POST_REQUESTED_TAGS, RestApiCallDocumentation::Type_JsonListOfStrings, + "A list of DICOM tags to include in the response (applicable only if \"Expand\" is set to true). " + "The tags requested tags are returned in the 'RequestedTags' field in the response. " + "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " + "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " + "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false); + } + else + { + throw OrthancException(ErrorCode_InternalError); + } } + void OrthancRestApi::GetResponseContentAndExpand(ResponseContentFlags& responseContent, + const RestApiGetCall& call) + { + if (call.HasArgument(GET_RESPONSE_CONTENT)) + { + std::string s = call.GetArgument(GET_RESPONSE_CONTENT, ""); + responseContent = ResponseContentFlags_Default; + + if (!s.empty()) + { + std::set<std::string> splitResponseContent; + Toolbox::SplitString(splitResponseContent, s, ';'); + + for (std::set<std::string>::const_iterator it = splitResponseContent.begin(); it != splitResponseContent.end(); ++it) + { + responseContent = static_cast<ResponseContentFlags>(static_cast<uint32_t>(responseContent) | StringToResponseContent(*it)); + } + } + } + else if (call.HasArgument(GET_EXPAND) && call.GetBooleanArgument("expand", true)) + { + responseContent = ResponseContentFlags_ExpandTrue; + } + else + { + responseContent = ResponseContentFlags_ID; + } + } + + void OrthancRestApi::DocumentResponseContentAndExpand(RestApiCall& call) + { + if (call.GetMethod() == HttpMethod_Get) + { + call.GetDocumentation().SetHttpGetArgument(GET_RESPONSE_CONTENT, RestApiCallDocumentation::Type_String, + "Defines the content of response for each returned resource. Allowed values are `MainDicomTags`, " + "`Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`, `Attachments`. If not specified, Orthanc " + "will return `MainDicomTags`, `Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`." + "e.g: '" + GET_RESPONSE_CONTENT + "=MainDicomTags;Children " + "(new in Orthanc 1.12.5 - overrides `expand`)", false); + + call.GetDocumentation().SetHttpGetArgument(GET_EXPAND, RestApiCallDocumentation::Type_String, + "If present, retrieve detailed information about the individual resources", false); + + } + else if (call.GetMethod() == HttpMethod_Post) + { + call.GetDocumentation().SetRequestField(POST_RESPONSE_CONTENT, RestApiCallDocumentation::Type_JsonListOfStrings, + "Defines the content of response for each returned resource. (this field, if present, overrides the \"Expand\" field). " + "Allowed values are `MainDicomTags`, " + "`Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`, `Attachments`. If not specified, Orthanc " + "will return `MainDicomTags`, `Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`." + "(new in Orthanc 1.12.5)", false); + + call.GetDocumentation().SetRequestField(POST_EXPAND, RestApiCallDocumentation::Type_Boolean, + "If present, retrieve detailed information about the individual resources", false); + } + else + { + throw OrthancException(ErrorCode_InternalError); + } + + } + + }
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h Thu Nov 07 10:27:28 2024 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h Wed Nov 27 15:00:58 2024 +0100 @@ -157,6 +157,11 @@ static void GetRequestedTags(std::set<DicomTag>& requestedTags, const RestApiGetCall& call); - static void DocumentRequestedTags(RestApiGetCall& call); + static void DocumentRequestedTags(RestApiCall& call); + + static void GetResponseContentAndExpand(ResponseContentFlags& responseContent, + const RestApiGetCall& call); + + static void DocumentResponseContentAndExpand(RestApiCall& call); }; }
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Thu Nov 07 10:27:28 2024 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Wed Nov 27 15:00:58 2024 +0100 @@ -177,23 +177,22 @@ .SetDescription("List the Orthanc identifiers of all the available DICOM " + resources) .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false) - .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, - "If present, retrieve detailed information about the individual " + resources, false) .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " "about the reported " + resources + " (if `expand` argument is provided)") .SetHttpGetSample("https://orthanc.uclouvain.be/demo/" + resources + "?since=0&limit=2", true); + OrthancRestApi::DocumentResponseContentAndExpand(call); return; } - // TODO-FIND: include the FindRequest options parsing in a method (parse from get-arguments and from post payload) - // TODO-FIND: support other values for expand like expand=MainDicomTags,Labels,Parent,SeriesStatus - const bool expand = (call.HasArgument("expand") && - call.GetBooleanArgument("expand", true)); + // TODO-FIND: include the FindRequest options parsing like since, limit in a method (parse from get-arguments and from post payload) std::set<DicomTag> requestedTags; + ResponseContentFlags responseContent; + OrthancRestApi::GetRequestedTags(requestedTags, call); - - ResourceFinder finder(resourceType, (expand ? ResponseContentFlags_ExpandTrue : ResponseContentFlags_ID), OrthancRestApi::GetContext(call).GetFindStorageAccessMode()); + OrthancRestApi::GetResponseContentAndExpand(responseContent, call); + + ResourceFinder finder(resourceType, responseContent, OrthancRestApi::GetContext(call).GetFindStorageAccessMode()); finder.AddRequestedTags(requestedTags); if (call.HasArgument("limit") || @@ -3102,20 +3101,23 @@ "Limit the number of reported resources", false) .SetRequestField(KEY_SINCE, RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index (in conjunction with `Limit`)", false) - .SetRequestField(KEY_REQUESTED_TAGS, RestApiCallDocumentation::Type_JsonListOfStrings, - "A list of DICOM tags to include in the response (applicable only if \"Expand\" is set to true). " - "The tags requested tags are returned in the 'RequestedTags' field in the response. " - "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " - "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " - "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false) + // .SetRequestField(KEY_REQUESTED_TAGS, RestApiCallDocumentation::Type_JsonListOfStrings, + // "A list of DICOM tags to include in the response (applicable only if \"Expand\" is set to true). " + // "The tags requested tags are returned in the 'RequestedTags' field in the response. " + // "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " + // "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " + // "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false) .SetRequestField(KEY_ORDER_BY, RestApiCallDocumentation::Type_JsonListOfObjects, "Array of associative arrays containing the requested ordering (new in Orthanc 1.12.5)", true) - .SetRequestField(KEY_RESPONSE_CONTENT, RestApiCallDocumentation::Type_JsonListOfStrings, - "Defines the content of response for each returned resource. Allowed values are `MainDicomTags`, " - "`Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`, `Attachments`. " - "(new in Orthanc 1.12.5)", true) + // .SetRequestField(KEY_RESPONSE_CONTENT, RestApiCallDocumentation::Type_JsonListOfStrings, + // "Defines the content of response for each returned resource. Allowed values are `MainDicomTags`, " + // "`Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`, `Attachments`. " + // "(new in Orthanc 1.12.5)", true) .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " "about the reported resources (if `Expand` argument is `true`)"); + + OrthancRestApi::DocumentRequestedTags(call); + OrthancRestApi::DocumentResponseContentAndExpand(call); break; case FindType_Count: doc.SetSummary("Count local resources")
--- a/OrthancServer/Sources/ServerEnumerations.cpp Thu Nov 07 10:27:28 2024 +0100 +++ b/OrthancServer/Sources/ServerEnumerations.cpp Wed Nov 27 15:00:58 2024 +0100 @@ -623,6 +623,10 @@ { return ResponseContentFlags_MainDicomTags; } + else if (value == "RequestedTags") + { + return ResponseContentFlags_RequestedTags; + } else if (value == "Metadata") { return ResponseContentFlags_Metadata;