comparison OrthancServer/ServerJobs/DicomModalityStoreJob.cpp @ 3734:4fc24b69446a storage-commitment

triggering storage commitment scu from REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Mar 2020 13:22:02 +0100
parents 2a170a8f1faf
children 77183afbf55e
comparison
equal deleted inserted replaced
3731:e7ff4f9b34bd 3734:4fc24b69446a
70 catch (OrthancException& e) 70 catch (OrthancException& e)
71 { 71 {
72 LOG(WARNING) << "An instance was removed after the job was issued: " << instance; 72 LOG(WARNING) << "An instance was removed after the job was issued: " << instance;
73 return false; 73 return false;
74 } 74 }
75
76 std::string sopClassUid, sopInstanceUid;
75 77
76 if (HasMoveOriginator()) 78 if (HasMoveOriginator())
77 { 79 {
78 connection_->Store(dicom, moveOriginatorAet_, moveOriginatorId_); 80 connection_->Store(sopClassUid, sopInstanceUid, dicom, moveOriginatorAet_, moveOriginatorId_);
79 } 81 }
80 else 82 else
81 { 83 {
82 connection_->Store(dicom); 84 connection_->Store(sopClassUid, sopInstanceUid, dicom);
85 }
86
87 if (storageCommitment_)
88 {
89 sopClassUids_.push_back(sopClassUid);
90 sopInstanceUids_.push_back(sopInstanceUid);
91
92 if (sopClassUids_.size() != sopInstanceUids_.size() ||
93 sopClassUids_.size() > GetInstancesCount())
94 {
95 throw OrthancException(ErrorCode_InternalError);
96 }
97
98 if (sopClassUids_.size() == GetInstancesCount())
99 {
100 LOG(INFO) << "Sending storage commitment request to modality: "
101 << remote_.GetApplicationEntityTitle();
102
103 assert(IsStarted());
104 OpenConnection();
105
106 connection_->RequestStorageCommitment(transactionUid_, sopClassUids_, sopInstanceUids_);
107 }
83 } 108 }
84 109
85 //boost::this_thread::sleep(boost::posix_time::milliseconds(500)); 110 //boost::this_thread::sleep(boost::posix_time::milliseconds(500));
86 111
87 return true; 112 return true;
95 120
96 121
97 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context) : 122 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context) :
98 context_(context), 123 context_(context),
99 localAet_("ORTHANC"), 124 localAet_("ORTHANC"),
100 moveOriginatorId_(0) // By default, not a C-MOVE 125 moveOriginatorId_(0), // By default, not a C-MOVE
126 storageCommitment_(false) // By default, no storage commitment
101 { 127 {
102 } 128 }
103 129
104 130
105 void DicomModalityStoreJob::SetLocalAet(const std::string& aet) 131 void DicomModalityStoreJob::SetLocalAet(const std::string& aet)
177 { 203 {
178 connection_.reset(NULL); 204 connection_.reset(NULL);
179 } 205 }
180 206
181 207
208 void DicomModalityStoreJob::ResetStorageCommitment()
209 {
210 if (storageCommitment_)
211 {
212 transactionUid_ = Toolbox::GenerateDicomPrivateUniqueIdentifier();
213 sopClassUids_.reserve(GetInstancesCount());
214 sopInstanceUids_.reserve(GetInstancesCount());
215 }
216 }
217
218
219 void DicomModalityStoreJob::Start()
220 {
221 SetOfInstancesJob::Start();
222 ResetStorageCommitment();
223 }
224
225
226 void DicomModalityStoreJob::Reset()
227 {
228 SetOfInstancesJob::Reset();
229
230 /**
231 * "After the N-EVENT-REPORT has been sent, the Transaction UID is
232 * no longer active and shall not be reused for other
233 * transactions." => Need to reset the transaction UID here
234 * http://dicom.nema.org/medical/dicom/2019a/output/chtml/part04/sect_J.3.3.html
235 **/
236 ResetStorageCommitment();
237 }
238
239
240 void DicomModalityStoreJob::EnableStorageCommitment(bool enabled)
241 {
242 storageCommitment_ = enabled;
243 }
244
245
182 void DicomModalityStoreJob::GetPublicContent(Json::Value& value) 246 void DicomModalityStoreJob::GetPublicContent(Json::Value& value)
183 { 247 {
184 SetOfInstancesJob::GetPublicContent(value); 248 SetOfInstancesJob::GetPublicContent(value);
185 249
186 value["LocalAet"] = localAet_; 250 value["LocalAet"] = localAet_;
188 252
189 if (HasMoveOriginator()) 253 if (HasMoveOriginator())
190 { 254 {
191 value["MoveOriginatorAET"] = GetMoveOriginatorAet(); 255 value["MoveOriginatorAET"] = GetMoveOriginatorAet();
192 value["MoveOriginatorID"] = GetMoveOriginatorId(); 256 value["MoveOriginatorID"] = GetMoveOriginatorId();
257 }
258
259 if (storageCommitment_)
260 {
261 value["StorageCommitmentTransactionUID"] = transactionUid_;
193 } 262 }
194 } 263 }
195 264
196 265
197 static const char* LOCAL_AET = "LocalAet"; 266 static const char* LOCAL_AET = "LocalAet";
198 static const char* REMOTE = "Remote"; 267 static const char* REMOTE = "Remote";
199 static const char* MOVE_ORIGINATOR_AET = "MoveOriginatorAet"; 268 static const char* MOVE_ORIGINATOR_AET = "MoveOriginatorAet";
200 static const char* MOVE_ORIGINATOR_ID = "MoveOriginatorId"; 269 static const char* MOVE_ORIGINATOR_ID = "MoveOriginatorId";
270 static const char* STORAGE_COMMITMENT = "StorageCommitment";
201 271
202 272
203 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context, 273 DicomModalityStoreJob::DicomModalityStoreJob(ServerContext& context,
204 const Json::Value& serialized) : 274 const Json::Value& serialized) :
205 SetOfInstancesJob(serialized), 275 SetOfInstancesJob(serialized),
208 localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET); 278 localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET);
209 remote_ = RemoteModalityParameters(serialized[REMOTE]); 279 remote_ = RemoteModalityParameters(serialized[REMOTE]);
210 moveOriginatorAet_ = SerializationToolbox::ReadString(serialized, MOVE_ORIGINATOR_AET); 280 moveOriginatorAet_ = SerializationToolbox::ReadString(serialized, MOVE_ORIGINATOR_AET);
211 moveOriginatorId_ = static_cast<uint16_t> 281 moveOriginatorId_ = static_cast<uint16_t>
212 (SerializationToolbox::ReadUnsignedInteger(serialized, MOVE_ORIGINATOR_ID)); 282 (SerializationToolbox::ReadUnsignedInteger(serialized, MOVE_ORIGINATOR_ID));
283 EnableStorageCommitment(SerializationToolbox::ReadBoolean(serialized, STORAGE_COMMITMENT));
213 } 284 }
214 285
215 286
216 bool DicomModalityStoreJob::Serialize(Json::Value& target) 287 bool DicomModalityStoreJob::Serialize(Json::Value& target)
217 { 288 {
223 { 294 {
224 target[LOCAL_AET] = localAet_; 295 target[LOCAL_AET] = localAet_;
225 remote_.Serialize(target[REMOTE], true /* force advanced format */); 296 remote_.Serialize(target[REMOTE], true /* force advanced format */);
226 target[MOVE_ORIGINATOR_AET] = moveOriginatorAet_; 297 target[MOVE_ORIGINATOR_AET] = moveOriginatorAet_;
227 target[MOVE_ORIGINATOR_ID] = moveOriginatorId_; 298 target[MOVE_ORIGINATOR_ID] = moveOriginatorId_;
299 target[STORAGE_COMMITMENT] = storageCommitment_;
228 return true; 300 return true;
229 } 301 }
230 } 302 }
231 } 303 }