changeset 6616:efa9c6284f83

More detailed error in modifications
author Alain Mazy <am@orthanc.team>
date Wed, 11 Mar 2026 21:15:36 +0100
parents 2c557f38484a
children 55e17dc7ef0d
files OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp	Wed Mar 04 14:12:36 2026 +0100
+++ b/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp	Wed Mar 11 21:15:36 2026 +0100
@@ -807,12 +807,21 @@
                    mainPatientTag != mainPatientTags.end(); ++mainPatientTag)
               {
                 if (targetPatientTags.HasTag(*mainPatientTag) &&
-                    (!modification_->IsReplaced(*mainPatientTag) ||
+                    ((!modification_->IsReplaced(*mainPatientTag) && targetPatientTags.GetStringValue(*mainPatientTag, "", false).size() > 0) ||
                      modification_->GetReplacementAsString(*mainPatientTag) != targetPatientTags.GetStringValue(*mainPatientTag, "", false)))
                 {
-                  throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study.  " 
-                    "The Patient already exists and has other studies.  All the 'Replace' tags should match the existing patient main dicom tags "
-                    "and you should specify all Patient MainDicomTags in your query.  Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format());
+                  if (!modification_->IsReplaced(*mainPatientTag))
+                  {
+                    throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study.  " 
+                      "The Patient already exists and has other studies.  All the 'Replace' tags should match the existing patient main dicom tags "
+                      "and you should specify all Patient MainDicomTags in your query.  Try using /patients/../modify instead to modify the patient. Missing tag in the 'Replace' tags: ") + mainPatientTag->Format());
+                  }
+                  else
+                  {
+                    throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study.  " 
+                      "The Patient already exists and has other studies.  All the 'Replace' tags should match the existing patient main dicom tags "
+                      "and you should specify all Patient MainDicomTags in your query.  Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format());
+                  }
                 }
                 else if (!targetPatientTags.HasTag(*mainPatientTag) && modification_->IsReplaced(*mainPatientTag) )
                 {