Mercurial > hg > orthanc
diff OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4698:d16c3c7f11ef
new route "/tools/bulk-content" to get the content of a set of resources
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Jun 2021 16:37:12 +0200 |
parents | 569d9ef165b1 |
children | facea16b055b |
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jun 18 16:08:35 2021 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jun 18 16:37:12 2021 +0200 @@ -3092,6 +3092,60 @@ } + static void BulkContent(RestApiPostCall& call) + { + if (call.IsDocumentation()) + { + OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); + + call.GetDocumentation() + .SetTag("System") + .SetSummary("Describe a set of instances") + .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, + "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", false) + .SetDescription("Get the content all the DICOM patients, studies, series or instances " + "whose identifiers are provided in the `Resources` field, in one single call."); + return; + } + + Json::Value request; + if (!call.ParseJsonRequest(request) || + request.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadRequest, + "The body must contain a JSON object"); + } + else + { + const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); + + ServerIndex& index = OrthancRestApi::GetIndex(call); + + std::list<std::string> resources; + SerializationToolbox::ReadListOfStrings(resources, request, "Resources"); + + Json::Value answer = Json::arrayValue; + for (std::list<std::string>::const_iterator + it = resources.begin(); it != resources.end(); ++it) + { + ResourceType type; + Json::Value item; + if (index.LookupResourceType(type, *it) && + index.ExpandResource(item, *it, type, format)) + { + answer.append(item); + } + else + { + CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; + } + } + + call.GetOutput().AnswerJson(answer); + } + } + + static void BulkDelete(RestApiPostCall& call) { if (call.IsDocumentation()) @@ -3101,7 +3155,7 @@ .SetSummary("Delete a set of instances") .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", false) - .SetDescription("Dellete all the DICOM patients, studies, series or instances " + .SetDescription("Delete all the DICOM patients, studies, series or instances " "whose identifiers are provided in the `Resources` field."); return; } @@ -3257,6 +3311,7 @@ Register("/instances/{id}/reconstruct", ReconstructResource<ResourceType_Instance>); Register("/tools/reconstruct", ReconstructAllResources); + Register("/tools/bulk-content", BulkContent); Register("/tools/bulk-delete", BulkDelete); } }