changeset 5139:021d7fdcb659

more sanity checks for modifications
author Alain Mazy <am@osimis.io>
date Fri, 20 Jan 2023 17:24:16 +0100
parents 15109c3f0f7d
children b2b38f9fb9d1
files OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp	Wed Jan 18 17:58:51 2023 +0100
+++ b/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp	Fri Jan 20 17:24:16 2023 +0100
@@ -669,11 +669,24 @@
       replaceInstanceMainDicomTags |= DicomMap::IsMainDicomTag(*it, ResourceType_Instance);
     }
 
-    if (modification_->IsKept(DICOM_TAG_SOP_INSTANCE_UID) && !IsKeepSource())
+    if (modification_->IsKept(DICOM_TAG_SOP_INSTANCE_UID) 
+        && (modificationLevel == ResourceType_Series || modificationLevel == ResourceType_Study || modificationLevel == ResourceType_Patient))
     {
-      // note: we could refine this criteria -> this is valid only if all DicomUIDs are kept identical (but this can happen through Keep or Replace options)
-      throw OrthancException(ErrorCode_BadRequest,
-                             "When keeping SOPInstanceUID tag, you must set KeepSource to true to avoid deleting the modified files at the end of the process");
+      // if we keep the SOPInstanceUID, it very likely means that we are modifying existing resources 'in place'
+
+      // we must make sure we do not delete them at the end of the job
+      if (!IsKeepSource()) // note: we can refine this criteria -> this is valid only if all DicomUIDs are kept identical (but this can happen through Keep or Replace options)
+      {
+        throw OrthancException(ErrorCode_BadRequest,
+                              "When keeping SOPInstanceUID tag, you must set KeepSource to true to avoid deleting the modified files at the end of the process");
+      }
+
+      // and we must make sure that we overwite them with the modified resources
+      if (IsKeepSource() && !GetContext().IsOverwriteInstances())
+      {
+        throw OrthancException(ErrorCode_BadRequest,
+                              "When keeping SOPInstanceUID tag, you must have the 'OverwriteInstances' Orthanc configuration set to true in order to replace the modified resources");
+      }
     }
 
     if (modificationLevel == ResourceType_Study && replacePatientMainDicomTags)