comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4883:504624b0a062

Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
author Alain Mazy <am@osimis.io>
date Wed, 09 Feb 2022 13:10:11 +0100
parents 81dfdcf16e16
children 6eff25f70121
comparison
equal deleted inserted replaced
4882:6971ea27a2a9 4883:504624b0a062
2046 operations.append("compressed-md5"); 2046 operations.append("compressed-md5");
2047 } 2047 }
2048 2048
2049 operations.append("compressed-size"); 2049 operations.append("compressed-size");
2050 operations.append("data"); 2050 operations.append("data");
2051 operations.append("info");
2051 operations.append("is-compressed"); 2052 operations.append("is-compressed");
2052 2053
2053 if (info.GetUncompressedMD5() != "") 2054 if (info.GetUncompressedMD5() != "")
2054 { 2055 {
2055 operations.append("md5"); 2056 operations.append("md5");
2061 if (info.GetCompressedMD5() != "" && 2062 if (info.GetCompressedMD5() != "" &&
2062 info.GetUncompressedMD5() != "") 2063 info.GetUncompressedMD5() != "")
2063 { 2064 {
2064 operations.append("verify-md5"); 2065 operations.append("verify-md5");
2065 } 2066 }
2067
2068 operations.append("uuid");
2066 2069
2067 call.GetOutput().AnswerJson(operations); 2070 call.GetOutput().AnswerJson(operations);
2068 } 2071 }
2069 } 2072 }
2070 2073
2149 { 2152 {
2150 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedSize()), MimeType_PlainText); 2153 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedSize()), MimeType_PlainText);
2151 } 2154 }
2152 } 2155 }
2153 2156
2157 static void GetAttachmentInfo(RestApiGetCall& call)
2158 {
2159 if (call.IsDocumentation())
2160 {
2161 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
2162 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
2163 AddAttachmentDocumentation(call, r);
2164 call.GetDocumentation()
2165 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
2166 .SetSummary("Get info about the attachment")
2167 .SetDescription("Get all the information about the attachment associated with the given " + r)
2168 .AddAnswerType(MimeType_Json, "JSON object containing the information about the attachment")
2169 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/dicom/info", true);
2170 return;
2171 }
2172
2173 FileInfo info;
2174 if (GetAttachmentInfo(info, call))
2175 {
2176 Json::Value result = Json::objectValue;
2177 result["Uuid"] = info.GetUuid();
2178 result["ContentType"] = info.GetContentType();
2179 result["UncompressedSize"] = Json::Value::UInt64(info.GetUncompressedSize());
2180 result["CompressedSize"] = Json::Value::UInt64(info.GetCompressedSize());
2181 result["UncompressedMD5"] = info.GetUncompressedMD5();
2182 result["CompressedMD5"] = info.GetCompressedMD5();
2183
2184 call.GetOutput().AnswerJson(result);
2185 }
2186 }
2154 2187
2155 static void GetAttachmentCompressedSize(RestApiGetCall& call) 2188 static void GetAttachmentCompressedSize(RestApiGetCall& call)
2156 { 2189 {
2157 if (call.IsDocumentation()) 2190 if (call.IsDocumentation())
2158 { 2191 {
3694 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/data", GetAttachmentData<1>); 3727 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/data", GetAttachmentData<1>);
3695 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed); 3728 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed);
3696 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5); 3729 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5);
3697 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize); 3730 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize);
3698 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>); 3731 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>);
3732 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/info", GetAttachmentInfo);
3699 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment); 3733 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment);
3700 } 3734 }
3701 3735
3702 Register("/tools/invalidate-tags", InvalidateTags); 3736 Register("/tools/invalidate-tags", InvalidateTags);
3703 Register("/tools/lookup", Lookup); 3737 Register("/tools/lookup", Lookup);