changeset 3614:4543ffad256d storage-commitment

storage commitment requests/responses to/from self are working
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 Jan 2020 17:48:43 +0100
parents c1e2b91c2ab4
children 169d57e18b39
files Core/DicomNetworking/Internals/CommandDispatcher.cpp OrthancServer/main.cpp
diffstat 2 files changed, 44 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomNetworking/Internals/CommandDispatcher.cpp	Tue Jan 21 17:01:46 2020 +0100
+++ b/Core/DicomNetworking/Internals/CommandDispatcher.cpp	Tue Jan 21 17:48:43 2020 +0100
@@ -918,16 +918,27 @@
     static void ReadSopSequence(std::vector<std::string>& sopClassUids,
                                 std::vector<std::string>& sopInstanceUids,
                                 DcmDataset& dataset,
-                                const DcmTagKey& tag)
+                                const DcmTagKey& tag,
+                                bool mandatory)
     {
+      sopClassUids.clear();
+      sopInstanceUids.clear();
+
       DcmSequenceOfItems* sequence = NULL;
       if (!dataset.findAndGetSequence(tag, sequence).good() ||
           sequence == NULL)
       {
-        char buf[64];
-        sprintf(buf, "Missing mandatory sequence in dataset: (%04X,%04X)",
-                tag.getGroup(), tag.getElement());
-        throw OrthancException(ErrorCode_NetworkProtocol, buf);
+        if (mandatory)
+        {        
+          char buf[64];
+          sprintf(buf, "Missing mandatory sequence in dataset: (%04X,%04X)",
+                  tag.getGroup(), tag.getElement());
+          throw OrthancException(ErrorCode_NetworkProtocol, buf);
+        }
+        else
+        {
+          return;
+        }
       }
 
       sopClassUids.reserve(sequence->card());
@@ -1011,7 +1022,7 @@
 
       std::vector<std::string> sopClassUid, sopInstanceUid;
       ReadSopSequence(sopClassUid, sopInstanceUid,
-                      *dataset, DCM_ReferencedSOPSequence);
+                      *dataset, DCM_ReferencedSOPSequence, true /* mandatory */);
 
       LOG(INFO) << "Incoming storage commitment request, with transaction UID: " << transactionUid;
 
@@ -1134,11 +1145,16 @@
 
       std::vector<std::string> successSopClassUid, successSopInstanceUid;
       ReadSopSequence(successSopClassUid, successSopInstanceUid,
-                      *dataset, DCM_ReferencedSOPSequence);
+                      *dataset, DCM_ReferencedSOPSequence,
+                      (report.EventTypeID == 1) /* mandatory in the case of success */);
 
       std::vector<std::string> failedSopClassUid, failedSopInstanceUid;
-      ReadSopSequence(failedSopClassUid, failedSopInstanceUid,
-                      *dataset, DCM_FailedSOPSequence);
+
+      if (report.EventTypeID == 2 /* failures exist */)
+      {
+        ReadSopSequence(failedSopClassUid, failedSopInstanceUid,
+                        *dataset, DCM_FailedSOPSequence, true);
+      }
 
       LOG(INFO) << "Incoming storage commitment report, with transaction UID: " << transactionUid;
 
--- a/OrthancServer/main.cpp	Tue Jan 21 17:01:46 2020 +0100
+++ b/OrthancServer/main.cpp	Tue Jan 21 17:48:43 2020 +0100
@@ -99,21 +99,29 @@
   // TODO - Remove this
   static void Toto(std::string* t)
   {
-    std::auto_ptr<std::string> tt(t);
+    try
+    {
+      std::auto_ptr<std::string> tt(t);
     
-    printf("Sleeping\n");
-    boost::this_thread::sleep(boost::posix_time::milliseconds(100));
-    printf("Connect back\n");
+      printf("Sleeping\n");
+      boost::this_thread::sleep(boost::posix_time::milliseconds(100));
+      printf("Connect back\n");
     
-    RemoteModalityParameters p("STGCMTSCU", "localhost", 11114, ModalityManufacturer_Generic);        
-    DicomUserConnection scu("ORTHANC", p);
+      //RemoteModalityParameters p("STGCMTSCU", "localhost", 11114, ModalityManufacturer_Generic);
+      RemoteModalityParameters p("ORTHANC", "localhost", 4242, ModalityManufacturer_Generic);
+      DicomUserConnection scu("ORTHANC", p);
 
-    std::vector<std::string> a, b, c, d;
-    a.push_back("a");  b.push_back("b");
-    a.push_back("c");  b.push_back("d");
+      std::vector<std::string> a, b, c, d;
+      a.push_back("a");  b.push_back("b");
+      a.push_back("c");  b.push_back("d");
     
-    scu.ReportStorageCommitment(tt->c_str(), a, b, c, d);
-    //scu.ReportStorageCommitment("transaction", a, b, a, b);
+      //scu.ReportStorageCommitment(tt->c_str(), a, b, c, d);
+      scu.ReportStorageCommitment(tt->c_str(), a, b, a, b);
+    }
+    catch (OrthancException& e)
+    {
+      LOG(ERROR) << "EXCEPTION: " << e.What();
+    }
 
     /**
      * "After the N-EVENT-REPORT has been sent, the Transaction UID is