diff OrthancServer/OrthancMoveRequestHandler.cpp @ 1907:5011a597b6ce

Support of Move Originator Message ID (0000,1031) in C-Store responses driven by C-Move
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Jan 2016 11:28:19 +0100
parents b1291df2f780
children 21fcfc428dc2
line wrap: on
line diff
--- a/OrthancServer/OrthancMoveRequestHandler.cpp	Tue Jan 05 17:45:27 2016 +0100
+++ b/OrthancServer/OrthancMoveRequestHandler.cpp	Thu Jan 07 11:28:19 2016 +0100
@@ -52,14 +52,17 @@
       std::vector<std::string> instances_;
       size_t position_;
       RemoteModalityParameters remote_;
+      uint16_t moveRequestID_;
 
     public:
       OrthancMoveRequestIterator(ServerContext& context,
                                  const std::string& aet,
-                                 const std::string& publicId) :
+                                 const std::string& publicId,
+                                 uint16_t moveRequestID) :
         context_(context),
         localAet_(context.GetDefaultLocalApplicationEntityTitle()),
-        position_(0)
+        position_(0),
+        moveRequestID_(moveRequestID)
       {
         LOG(INFO) << "Sending resource " << publicId << " to modality \"" << aet << "\"";
 
@@ -95,7 +98,7 @@
         {
           ReusableDicomUserConnection::Locker locker
             (context_.GetReusableDicomUserConnection(), localAet_, remote_);
-          locker.GetConnection().Store(dicom);
+          locker.GetConnection().Store(dicom, moveRequestID_);
         }
 
         return Status_Success;
@@ -184,6 +187,33 @@
     }
 
 
+    /**
+     * Retrieve the Message ID (0000,0110) for this C-MOVE request, if
+     * any. If present, this Message ID will be stored in the Move
+     * Originator Message ID (0000,1031) field of the C-MOVE response.
+     * http://dicom.nema.org/medical/dicom/current/output/html/part07.html#sect_9.3.1
+     **/
+
+    static const DicomTag MESSAGE_ID(0x0000, 0x0110);
+    const DicomValue* messageIdTmp = input.TestAndGetValue(MESSAGE_ID);
+
+    uint16_t messageId = 0;
+
+    if (messageIdTmp != NULL &&
+        !messageIdTmp->IsNull() &&
+        !messageIdTmp->IsBinary())
+    {
+      try
+      {
+        messageId = boost::lexical_cast<uint16_t>(messageIdTmp->GetContent());
+      }
+      catch (boost::bad_lexical_cast&)
+      {
+        LOG(WARNING) << "Cannot convert the Message ID (\"" << messageIdTmp ->GetContent()
+                     << "\") of an incoming C-MOVE request to an integer, assuming zero";
+      }
+    }
+
 
     /**
      * Retrieve the query level.
@@ -208,7 +238,7 @@
           LookupIdentifier(publicId, ResourceType_Study, input) ||
           LookupIdentifier(publicId, ResourceType_Patient, input))
       {
-        return new OrthancMoveRequestIterator(context_, targetAet, publicId);
+        return new OrthancMoveRequestIterator(context_, targetAet, publicId, messageId);
       }
       else
       {
@@ -229,7 +259,7 @@
 
     if (LookupIdentifier(publicId, level, input))
     {
-      return new OrthancMoveRequestIterator(context_, targetAet, publicId);
+      return new OrthancMoveRequestIterator(context_, targetAet, publicId, messageId);
     }
     else
     {