comparison OrthancServer/ServerJobs/SplitStudyJob.cpp @ 2845:218e2c864d1d

serialization of SplitStudyJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 28 Sep 2018 17:59:44 +0200
parents 99863d6245b2
children d386abc18133
comparison
equal deleted inserted replaced
2844:99863d6245b2 2845:218e2c864d1d
31 **/ 31 **/
32 32
33 33
34 #include "SplitStudyJob.h" 34 #include "SplitStudyJob.h"
35 35
36 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
36 #include "../../Core/Logging.h" 37 #include "../../Core/Logging.h"
37 #include "../../Core/DicomParsing/FromDcmtkBridge.h" 38 #include "../../Core/SerializationToolbox.h"
38 39
39 namespace Orthanc 40 namespace Orthanc
40 { 41 {
41 void SplitStudyJob::CheckAllowedTag(const DicomTag& tag) const 42 void SplitStudyJob::CheckAllowedTag(const DicomTag& tag) const
42 { 43 {
48 throw OrthancException(ErrorCode_ParameterOutOfRange); 49 throw OrthancException(ErrorCode_ParameterOutOfRange);
49 } 50 }
50 } 51 }
51 52
52 53
53 void SplitStudyJob::Setup(const std::string& sourceStudy) 54 void SplitStudyJob::Setup()
54 { 55 {
55 SetPermissive(false); 56 SetPermissive(false);
56
57 keepSource_ = false;
58 sourceStudy_ = sourceStudy;
59 targetStudyUid_ = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study);
60 57
61 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Patient); 58 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Patient);
62 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Study); 59 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Study);
63 allowedTags_.erase(DICOM_TAG_STUDY_INSTANCE_UID); 60 allowedTags_.erase(DICOM_TAG_STUDY_INSTANCE_UID);
64 allowedTags_.erase(DICOM_TAG_SERIES_INSTANCE_UID); 61 allowedTags_.erase(DICOM_TAG_SERIES_INSTANCE_UID);
65
66 ResourceType type;
67
68 if (!context_.GetIndex().LookupResourceType(type, sourceStudy) ||
69 type != ResourceType_Study)
70 {
71 LOG(ERROR) << "Cannot split unknown study: " << sourceStudy;
72 throw OrthancException(ErrorCode_UnknownResource);
73 }
74
75 std::list<std::string> children;
76 context_.GetIndex().GetChildren(children, sourceStudy);
77
78 for (std::list<std::string>::const_iterator
79 it = children.begin(); it != children.end(); ++it)
80 {
81 sourceSeries_.insert(*it);
82 }
83 } 62 }
84 63
85 64
86 bool SplitStudyJob::HandleInstance(const std::string& instance) 65 bool SplitStudyJob::HandleInstance(const std::string& instance)
87 { 66 {
130 109
131 /** 110 /**
132 * Apply user-specified modifications 111 * Apply user-specified modifications
133 **/ 112 **/
134 113
135 for (Removals::const_iterator it = removals_.begin(); 114 for (std::set<DicomTag>::const_iterator it = removals_.begin();
136 it != removals_.end(); ++it) 115 it != removals_.end(); ++it)
137 { 116 {
138 modified->Remove(*it); 117 modified->Remove(*it);
139 } 118 }
140 119
190 169
191 170
192 SplitStudyJob::SplitStudyJob(ServerContext& context, 171 SplitStudyJob::SplitStudyJob(ServerContext& context,
193 const std::string& sourceStudy) : 172 const std::string& sourceStudy) :
194 SetOfInstancesJob(true /* with trailing step */), 173 SetOfInstancesJob(true /* with trailing step */),
195 context_(context) 174 context_(context),
196 { 175 keepSource_(false),
197 Setup(sourceStudy); 176 sourceStudy_(sourceStudy),
198 } 177 targetStudyUid_(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study))
199 178 {
200 179 Setup();
201 SplitStudyJob::SplitStudyJob(ServerContext& context, 180
202 const Json::Value& serialized) : 181 ResourceType type;
203 SetOfInstancesJob(serialized), 182
204 context_(context) 183 if (!context_.GetIndex().LookupResourceType(type, sourceStudy) ||
205 { 184 type != ResourceType_Study)
206 //assert(HasTrailingStep()); 185 {
207 //Setup(); 186 LOG(ERROR) << "Cannot split unknown study: " << sourceStudy;
208 } 187 throw OrthancException(ErrorCode_UnknownResource);
209 188 }
210 189
190 std::list<std::string> children;
191 context_.GetIndex().GetChildren(children, sourceStudy);
192
193 for (std::list<std::string>::const_iterator
194 it = children.begin(); it != children.end(); ++it)
195 {
196 sourceSeries_.insert(*it);
197 }
198 }
199
200
211 void SplitStudyJob::SetOrigin(const DicomInstanceOrigin& origin) 201 void SplitStudyJob::SetOrigin(const DicomInstanceOrigin& origin)
212 { 202 {
213 if (IsStarted()) 203 if (IsStarted())
214 { 204 {
215 throw OrthancException(ErrorCode_BadSequenceOfCalls); 205 throw OrthancException(ErrorCode_BadSequenceOfCalls);
298 value["TargetStudy"] = targetStudy_; 288 value["TargetStudy"] = targetStudy_;
299 } 289 }
300 290
301 value["TargetStudyUID"] = targetStudyUid_; 291 value["TargetStudyUID"] = targetStudyUid_;
302 } 292 }
303 293
304 294
295 static const char* SOURCE_STUDY = "SourceStudy";
296 static const char* SOURCE_SERIES = "SourceSeries";
297 static const char* KEEP_SOURCE = "KeepSource";
298 static const char* TARGET_STUDY = "TargetStudy";
299 static const char* TARGET_STUDY_UID = "TargetStudyUID";
300 static const char* TARGET_SERIES = "TargetSeries";
301 static const char* ORIGIN = "Origin";
302 static const char* REPLACEMENTS = "Replacements";
303 static const char* REMOVALS = "Removals";
304
305
306 SplitStudyJob::SplitStudyJob(ServerContext& context,
307 const Json::Value& serialized) :
308 SetOfInstancesJob(serialized), // (*)
309 context_(context)
310 {
311 if (!HasTrailingStep())
312 {
313 // Should have been set by (*)
314 throw OrthancException(ErrorCode_InternalError);
315 }
316
317 Setup();
318
319 keepSource_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SOURCE);
320 sourceStudy_ = SerializationToolbox::ReadString(serialized, SOURCE_STUDY);
321 SerializationToolbox::ReadSetOfStrings(sourceSeries_, serialized, SOURCE_SERIES);
322 targetStudy_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY);
323 targetStudyUid_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY_UID);
324 SerializationToolbox::ReadMapOfStrings(targetSeries_, serialized, TARGET_SERIES);
325 origin_ = DicomInstanceOrigin(serialized[ORIGIN]);
326 SerializationToolbox::ReadMapOfTags(replacements_, serialized, REPLACEMENTS);
327 SerializationToolbox::ReadSetOfTags(removals_, serialized, REMOVALS);
328 }
329
330
305 bool SplitStudyJob::Serialize(Json::Value& target) 331 bool SplitStudyJob::Serialize(Json::Value& target)
306 { 332 {
307 return true; 333 if (!SetOfInstancesJob::Serialize(target))
334 {
335 return false;
336 }
337 else
338 {
339 target[KEEP_SOURCE] = keepSource_;
340 target[SOURCE_STUDY] = sourceStudy_;
341 SerializationToolbox::WriteSetOfStrings(target, sourceSeries_, SOURCE_SERIES);
342 target[TARGET_STUDY] = targetStudy_;
343 target[TARGET_STUDY_UID] = targetStudyUid_;
344 SerializationToolbox::WriteMapOfStrings(target, targetSeries_, TARGET_SERIES);
345 origin_.Serialize(target[ORIGIN]);
346 SerializationToolbox::WriteMapOfTags(target, replacements_, REPLACEMENTS);
347 SerializationToolbox::WriteSetOfTags(target, removals_, REMOVALS);
348
349 return true;
350 }
308 } 351 }
309 } 352 }