comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4853:b3d0a3a4d890

Added links to download attachments from the Orthanc Explorer
author Alain Mazy <am@osimis.io>
date Thu, 16 Dec 2021 14:48:46 +0100
parents ec1e9571b645
children 8b51d65584f0
comparison
equal deleted inserted replaced
4851:abb0e1c2b88d 4853:b3d0a3a4d890
1926 call.GetDocumentation() 1926 call.GetDocumentation()
1927 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) 1927 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
1928 .SetSummary("List attachments") 1928 .SetSummary("List attachments")
1929 .SetDescription("Get the list of attachments that are associated with the given " + r) 1929 .SetDescription("Get the list of attachments that are associated with the given " + r)
1930 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") 1930 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
1931 .SetHttpGetArgument("full", RestApiCallDocumentation::Type_String,
1932 "If present, retrieve the attachments list and their numerical ids", false)
1931 .AddAnswerType(MimeType_Json, "JSON array containing the names of the attachments") 1933 .AddAnswerType(MimeType_Json, "JSON array containing the names of the attachments")
1932 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/attachments", true); 1934 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/attachments", true);
1933 return; 1935 return;
1934 } 1936 }
1935 1937
1936 const std::string resourceType = call.GetFullUri() [0]; 1938 const std::string resourceType = call.GetFullUri() [0];
1937 const std::string publicId = call.GetUriComponent("id", ""); 1939 const std::string publicId = call.GetUriComponent("id", "");
1938 std::set<FileContentType> attachments; 1940 std::set<FileContentType> attachments;
1939 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str())); 1941 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str()));
1940 1942
1941 Json::Value result = Json::arrayValue; 1943 Json::Value result;
1942 1944
1943 for (std::set<FileContentType>::const_iterator 1945 if (call.HasArgument("full"))
1944 it = attachments.begin(); it != attachments.end(); ++it) 1946 {
1945 { 1947 result = Json::objectValue;
1946 result.append(EnumerationToString(*it)); 1948
1949 for (std::set<FileContentType>::const_iterator
1950 it = attachments.begin(); it != attachments.end(); ++it)
1951 {
1952 std::string key = EnumerationToString(*it);
1953 result[key] = static_cast<uint16_t>(*it);
1954 }
1955 }
1956 else
1957 {
1958 result = Json::arrayValue;
1959
1960 for (std::set<FileContentType>::const_iterator
1961 it = attachments.begin(); it != attachments.end(); ++it)
1962 {
1963 result.append(EnumerationToString(*it));
1964 }
1947 } 1965 }
1948 1966
1949 call.GetOutput().AnswerJson(result); 1967 call.GetOutput().AnswerJson(result);
1950 } 1968 }
1951 1969