diff OrthancServer/Sources/OrthancMoveRequestHandler.cpp @ 4165:e34c89e89aac

Fix compatibility with C-MOVE SCU requests issued by Ambra
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2020 17:05:13 +0200
parents 05b8fd21089c
children 067c679626a2
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancMoveRequestHandler.cpp	Mon Aug 24 15:34:11 2020 +0200
+++ b/OrthancServer/Sources/OrthancMoveRequestHandler.cpp	Tue Aug 25 17:05:13 2020 +0200
@@ -205,6 +205,23 @@
   }
 
 
+  static bool IsNonEmptyTag(const DicomMap& dicom,
+                            const DicomTag& tag)
+  {
+    const DicomValue* value = dicom.TestAndGetValue(tag);
+    if (value == NULL ||
+        value->IsNull() ||
+        value->IsBinary())
+    {
+      return false;
+    }
+    else
+    {
+      return !value->GetContent().empty();
+    }
+  }
+
+
   bool OrthancMoveRequestHandler::LookupIdentifiers(std::vector<std::string>& publicIds,
                                                     ResourceType level,
                                                     const DicomMap& input)
@@ -218,8 +235,17 @@
         break;
 
       case ResourceType_Study:
-        tag = (input.HasTag(DICOM_TAG_ACCESSION_NUMBER) ? 
-               DICOM_TAG_ACCESSION_NUMBER : DICOM_TAG_STUDY_INSTANCE_UID);
+        // The test below using "IsNonEmptyTag()" fixes compatibility
+        // with Ambra C-FIND SCU:
+        // https://groups.google.com/g/orthanc-users/c/yIUnZ9v9-Zs/m/GQPXiAOiCQAJ
+        if (IsNonEmptyTag(input, DICOM_TAG_ACCESSION_NUMBER))
+        {
+          tag = DICOM_TAG_ACCESSION_NUMBER;
+        }
+        else
+        {
+          tag = DICOM_TAG_STUDY_INSTANCE_UID;
+        }
         break;
         
       case ResourceType_Series:
@@ -373,7 +399,7 @@
     }
     else
     {
-      throw OrthancException(ErrorCode_BadRequest, "Invalid fields in a C-MOVE request");
+      throw OrthancException(ErrorCode_BadRequest, "No DICOM identifier provided in the C-MOVE request for this query retrieve level");
     }
   }
 }