comparison OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 5495:4b3f5986eca1

Added a 'KeepLabels' option in /modify routes (default = false)
author Alain Mazy <am@osimis.io>
date Mon, 22 Jan 2024 17:14:11 +0100
parents 48b8dae6dc77
children c1ed59a5bdc2
comparison
equal deleted inserted replaced
5491:42e6593aa78e 5495:4b3f5986eca1
208 * Retrieve the original instance from the DICOM cache. 208 * Retrieve the original instance from the DICOM cache.
209 **/ 209 **/
210 210
211 std::unique_ptr<DicomInstanceHasher> originalHasher; 211 std::unique_ptr<DicomInstanceHasher> originalHasher;
212 std::unique_ptr<ParsedDicomFile> modified; 212 std::unique_ptr<ParsedDicomFile> modified;
213 213 std::set<std::string> instanceLabels;
214 std::set<std::string> seriesLabels;
215 std::set<std::string> studyLabels;
216 std::set<std::string> patientLabels;
217
214 try 218 try
215 { 219 {
216 ServerContext::DicomCacheLocker locker(GetContext(), instance); 220 ServerContext::DicomCacheLocker locker(GetContext(), instance);
217 ParsedDicomFile& original = locker.GetDicom(); 221 ParsedDicomFile& original = locker.GetDicom();
218 222
232 236
233 { 237 {
234 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here 238 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here
235 239
236 modification_->Apply(*modified); 240 modification_->Apply(*modified);
241
242 if (modification_->AreLabelsKept())
243 {
244 GetContext().GetIndex().ListLabels(instanceLabels, instance, ResourceType_Instance);
245 // we must also save the parent labels. This instance might currently be the only one in the hierarchy and therefore it might be in charge of restoring all labels of the hierarchy
246 GetContext().GetIndex().ListLabels(seriesLabels, originalHasher->HashSeries(), ResourceType_Series);
247 GetContext().GetIndex().ListLabels(studyLabels, originalHasher->HashStudy(), ResourceType_Study);
248 GetContext().GetIndex().ListLabels(patientLabels, originalHasher->HashPatient(), ResourceType_Patient);
249 }
237 } 250 }
238 251
239 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()); 252 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject());
240 253
241 if (transcode_) 254 if (transcode_)
315 if (result.GetStatus() != StoreStatus_Success && result.GetStatus() != StoreStatus_AlreadyStored) // when retrying a job, we might save the same data again 328 if (result.GetStatus() != StoreStatus_Success && result.GetStatus() != StoreStatus_AlreadyStored) // when retrying a job, we might save the same data again
316 { 329 {
317 throw OrthancException(ErrorCode_CannotStoreInstance, 330 throw OrthancException(ErrorCode_CannotStoreInstance,
318 "Error while storing a modified instance " + instance); 331 "Error while storing a modified instance " + instance);
319 } 332 }
333
334 {
335 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here
336
337 if (modification_->AreLabelsKept())
338 {
339 GetContext().GetIndex().AddLabels(instance, ResourceType_Instance, instanceLabels);
340 GetContext().GetIndex().AddLabels(modifiedHasher.HashSeries(), ResourceType_Series, seriesLabels);
341 GetContext().GetIndex().AddLabels(modifiedHasher.HashStudy(), ResourceType_Study, studyLabels);
342 GetContext().GetIndex().AddLabels(modifiedHasher.HashPatient(), ResourceType_Patient, patientLabels);
343 }
344 }
345
320 346
321 /** 347 /**
322 * The assertion below will fail if automated transcoding to a 348 * The assertion below will fail if automated transcoding to a
323 * lossy transfer syntax is enabled in the Orthanc core, and if 349 * lossy transfer syntax is enabled in the Orthanc core, and if
324 * the source instance is not in this transfer syntax. 350 * the source instance is not in this transfer syntax.