Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp @ 4715:fb98db281d1d
"/studies/{id}/merge" accepts instances inside its "Resources" parameter
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Jun 2021 16:02:29 +0200 |
parents | 8f9090b137f1 |
children | 783f8a048035 94616af363ec |
comparison
equal
deleted
inserted
replaced
4714:8ffe2fdb541f | 4715:fb98db281d1d |
---|---|
40 #include "../ServerContext.h" | 40 #include "../ServerContext.h" |
41 | 41 |
42 | 42 |
43 namespace Orthanc | 43 namespace Orthanc |
44 { | 44 { |
45 static void RegisterSeries(std::map<std::string, std::string>& target, | |
46 const std::string& series) | |
47 { | |
48 // Generate a target SeriesInstanceUID for this series | |
49 if (target.find(series) == target.end()) | |
50 { | |
51 target[series] = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series); | |
52 } | |
53 } | |
54 | |
55 | |
45 void MergeStudyJob::AddSourceSeriesInternal(const std::string& series) | 56 void MergeStudyJob::AddSourceSeriesInternal(const std::string& series) |
46 { | 57 { |
47 // Generate a target SeriesInstanceUID for this series | 58 RegisterSeries(seriesUidMap_, series); |
48 seriesUidMap_[series] = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series); | |
49 | 59 |
50 // Add all the instances of the series as to be processed | 60 // Add all the instances of the series as to be processed |
51 std::list<std::string> instances; | 61 std::list<std::string> instances; |
52 GetContext().GetIndex().GetChildren(instances, series); | 62 GetContext().GetIndex().GetChildren(instances, series); |
53 | 63 |
238 { | 248 { |
239 SetOrigin(DicomInstanceOrigin::FromRest(call)); | 249 SetOrigin(DicomInstanceOrigin::FromRest(call)); |
240 } | 250 } |
241 | 251 |
242 | 252 |
243 void MergeStudyJob::AddSource(const std::string& studyOrSeries) | 253 void MergeStudyJob::AddSource(const std::string& publicId) |
244 { | 254 { |
245 ResourceType level; | 255 ResourceType level; |
246 | 256 |
247 if (IsStarted()) | 257 if (IsStarted()) |
248 { | 258 { |
249 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 259 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
250 } | 260 } |
251 else if (!GetContext().GetIndex().LookupResourceType(level, studyOrSeries)) | 261 else if (!GetContext().GetIndex().LookupResourceType(level, publicId)) |
252 { | 262 { |
253 throw OrthancException(ErrorCode_UnknownResource, | 263 throw OrthancException(ErrorCode_UnknownResource, |
254 "Cannot find this resource: " + studyOrSeries); | 264 "Cannot find this resource: " + publicId); |
255 } | 265 } |
256 else | 266 else |
257 { | 267 { |
258 switch (level) | 268 switch (level) |
259 { | 269 { |
260 case ResourceType_Study: | 270 case ResourceType_Study: |
261 AddSourceStudyInternal(studyOrSeries); | 271 AddSourceStudyInternal(publicId); |
262 break; | 272 break; |
263 | 273 |
264 case ResourceType_Series: | 274 case ResourceType_Series: |
265 AddSourceSeries(studyOrSeries); | 275 AddSourceSeries(publicId); |
276 break; | |
277 | |
278 case ResourceType_Instance: | |
279 AddSourceInstance(publicId); | |
266 break; | 280 break; |
267 | 281 |
268 default: | 282 default: |
269 throw OrthancException(ErrorCode_UnknownResource, | 283 throw OrthancException(ErrorCode_UnknownResource, |
270 "This resource is neither a study, nor a series: " + | 284 "This resource is neither a study, nor a series, nor an instance: " + |
271 studyOrSeries + " is a " + | 285 publicId + " is a " + std::string(EnumerationToString(level))); |
272 std::string(EnumerationToString(level))); | |
273 } | 286 } |
274 } | 287 } |
275 } | 288 } |
276 | 289 |
277 | 290 |
319 { | 332 { |
320 AddSourceStudyInternal(study); | 333 AddSourceStudyInternal(study); |
321 } | 334 } |
322 } | 335 } |
323 | 336 |
337 | |
338 void MergeStudyJob::AddSourceInstance(const std::string& instance) | |
339 { | |
340 std::string parentStudy, parentSeries; | |
341 | |
342 if (IsStarted()) | |
343 { | |
344 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
345 } | |
346 else if (!GetContext().GetIndex().LookupParent(parentSeries, instance, ResourceType_Series) || | |
347 !GetContext().GetIndex().LookupParent(parentStudy, parentSeries, ResourceType_Study)) | |
348 { | |
349 throw OrthancException(ErrorCode_UnknownResource, | |
350 "This resource is not an instance: " + instance); | |
351 } | |
352 else if (parentStudy == targetStudy_) | |
353 { | |
354 throw OrthancException(ErrorCode_UnknownResource, | |
355 "Cannot merge instance " + instance + | |
356 " into its parent study " + targetStudy_); | |
357 } | |
358 else | |
359 { | |
360 RegisterSeries(seriesUidMap_, parentSeries); | |
361 AddInstance(instance); | |
362 } | |
363 } | |
364 | |
324 | 365 |
325 void MergeStudyJob::GetPublicContent(Json::Value& value) | 366 void MergeStudyJob::GetPublicContent(Json::Value& value) |
326 { | 367 { |
327 CleaningInstancesJob::GetPublicContent(value); | 368 CleaningInstancesJob::GetPublicContent(value); |
328 value["TargetStudy"] = targetStudy_; | 369 value["TargetStudy"] = targetStudy_; |