Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4694:da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Jun 2021 17:37:47 +0200 |
parents | b1d87d41874e |
children | 569d9ef165b1 |
comparison
equal
deleted
inserted
replaced
4693:45bce660ce3a | 4694:da1edb7d6332 |
---|---|
42 #include "../../../OrthancFramework/Sources/HttpServer/HttpContentNegociation.h" | 42 #include "../../../OrthancFramework/Sources/HttpServer/HttpContentNegociation.h" |
43 #include "../../../OrthancFramework/Sources/Images/Image.h" | 43 #include "../../../OrthancFramework/Sources/Images/Image.h" |
44 #include "../../../OrthancFramework/Sources/Images/ImageProcessing.h" | 44 #include "../../../OrthancFramework/Sources/Images/ImageProcessing.h" |
45 #include "../../../OrthancFramework/Sources/Logging.h" | 45 #include "../../../OrthancFramework/Sources/Logging.h" |
46 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h" | 46 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h" |
47 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | |
47 | 48 |
48 #include "../OrthancConfiguration.h" | 49 #include "../OrthancConfiguration.h" |
49 #include "../Search/DatabaseLookup.h" | 50 #include "../Search/DatabaseLookup.h" |
50 #include "../ServerContext.h" | 51 #include "../ServerContext.h" |
51 #include "../ServerToolbox.h" | 52 #include "../ServerToolbox.h" |
276 .SetDescription("Delete the DICOM " + resource + " whose Orthanc identifier is provided in the URL") | 277 .SetDescription("Delete the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
277 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); | 278 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); |
278 return; | 279 return; |
279 } | 280 } |
280 | 281 |
281 Json::Value result; | 282 Json::Value remainingAncestor; |
282 if (OrthancRestApi::GetContext(call).DeleteResource(result, call.GetUriComponent("id", ""), resourceType)) | 283 if (OrthancRestApi::GetContext(call).DeleteResource(remainingAncestor, call.GetUriComponent("id", ""), resourceType)) |
283 { | 284 { |
284 call.GetOutput().AnswerJson(result); | 285 call.GetOutput().AnswerJson(remainingAncestor); |
285 } | 286 } |
286 } | 287 } |
287 | 288 |
288 | 289 |
289 // Get information about a single patient ----------------------------------- | 290 // Get information about a single patient ----------------------------------- |
3101 | 3102 |
3102 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | 3103 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
3103 } | 3104 } |
3104 | 3105 |
3105 | 3106 |
3107 static void BulkDelete(RestApiPostCall& call) | |
3108 { | |
3109 if (call.IsDocumentation()) | |
3110 { | |
3111 call.GetDocumentation() | |
3112 .SetTag("System") | |
3113 .SetSummary("Delete a set of instances") | |
3114 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3115 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", false) | |
3116 .SetDescription("Dellete all the DICOM patients, studies, series or instances " | |
3117 "whose identifiers are provided in the `Resources` field."); | |
3118 return; | |
3119 } | |
3120 | |
3121 ServerContext& context = OrthancRestApi::GetContext(call); | |
3122 | |
3123 Json::Value request; | |
3124 if (!call.ParseJsonRequest(request) || | |
3125 request.type() != Json::objectValue) | |
3126 { | |
3127 throw OrthancException(ErrorCode_BadRequest, | |
3128 "The body must contain a JSON object"); | |
3129 } | |
3130 else | |
3131 { | |
3132 std::set<std::string> resources; | |
3133 SerializationToolbox::ReadSetOfStrings(resources, request, "Resources"); | |
3134 | |
3135 for (std::set<std::string>::const_iterator | |
3136 it = resources.begin(); it != resources.end(); ++it) | |
3137 { | |
3138 ResourceType type; | |
3139 Json::Value remainingAncestor; // Unused | |
3140 | |
3141 if (!context.GetIndex().LookupResourceType(type, *it) || | |
3142 !context.DeleteResource(remainingAncestor, *it, type)) | |
3143 { | |
3144 CLOG(INFO, HTTP) << "Unknown resource during a bulk deletion: " << *it; | |
3145 } | |
3146 } | |
3147 | |
3148 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | |
3149 } | |
3150 } | |
3151 | |
3152 | |
3106 void OrthancRestApi::RegisterResources() | 3153 void OrthancRestApi::RegisterResources() |
3107 { | 3154 { |
3108 Register("/instances", ListResources<ResourceType_Instance>); | 3155 Register("/instances", ListResources<ResourceType_Instance>); |
3109 Register("/patients", ListResources<ResourceType_Patient>); | 3156 Register("/patients", ListResources<ResourceType_Patient>); |
3110 Register("/series", ListResources<ResourceType_Series>); | 3157 Register("/series", ListResources<ResourceType_Series>); |
3219 Register("/patients/{id}/reconstruct", ReconstructResource<ResourceType_Patient>); | 3266 Register("/patients/{id}/reconstruct", ReconstructResource<ResourceType_Patient>); |
3220 Register("/studies/{id}/reconstruct", ReconstructResource<ResourceType_Study>); | 3267 Register("/studies/{id}/reconstruct", ReconstructResource<ResourceType_Study>); |
3221 Register("/series/{id}/reconstruct", ReconstructResource<ResourceType_Series>); | 3268 Register("/series/{id}/reconstruct", ReconstructResource<ResourceType_Series>); |
3222 Register("/instances/{id}/reconstruct", ReconstructResource<ResourceType_Instance>); | 3269 Register("/instances/{id}/reconstruct", ReconstructResource<ResourceType_Instance>); |
3223 Register("/tools/reconstruct", ReconstructAllResources); | 3270 Register("/tools/reconstruct", ReconstructAllResources); |
3271 | |
3272 Register("/tools/bulk-delete", BulkDelete); | |
3224 } | 3273 } |
3225 } | 3274 } |