changeset 730:309e686b41e7

better logging about nonexistent tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Feb 2014 14:51:19 +0100
parents 948720c72586
children be0dadf5b3d4
files Core/DicomFormat/DicomMap.cpp Core/Enumerations.h Core/OrthancException.cpp NEWS OrthancServer/Internals/StoreScp.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerToolbox.cpp OrthancServer/ServerToolbox.h OrthancServer/main.cpp
diffstat 9 files changed, 112 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp	Mon Feb 24 13:50:40 2014 +0100
+++ b/Core/DicomFormat/DicomMap.cpp	Tue Feb 25 14:51:19 2014 +0100
@@ -199,7 +199,7 @@
     }
     else
     {
-      throw OrthancException("Inexistent tag");
+      throw OrthancException(ErrorCode_InexistentTag);
     }
   }
 
--- a/Core/Enumerations.h	Mon Feb 24 13:50:40 2014 +0100
+++ b/Core/Enumerations.h	Tue Feb 25 14:51:19 2014 +0100
@@ -67,7 +67,8 @@
     ErrorCode_UnknownResource,
     ErrorCode_IncompatibleDatabaseVersion,
     ErrorCode_FullStorage,
-    ErrorCode_CorruptedFile
+    ErrorCode_CorruptedFile,
+    ErrorCode_InexistentTag
   };
 
   /**
--- a/Core/OrthancException.cpp	Mon Feb 24 13:50:40 2014 +0100
+++ b/Core/OrthancException.cpp	Tue Feb 25 14:51:19 2014 +0100
@@ -108,6 +108,9 @@
       case ErrorCode_CorruptedFile:
         return "Corrupted file (inconsistent MD5 hash)";
 
+      case ErrorCode_InexistentTag:
+        return "Inexistent tag";
+
       case ErrorCode_Custom:
       default:
         return "???";
--- a/NEWS	Mon Feb 24 13:50:40 2014 +0100
+++ b/NEWS	Tue Feb 25 14:51:19 2014 +0100
@@ -1,6 +1,7 @@
 Pending changes in the mainline
 ===============================
 
+* Better logging about inexistent tags
 
 
 Version 0.7.3 (2014/02/14)
--- a/OrthancServer/Internals/StoreScp.cpp	Mon Feb 24 13:50:40 2014 +0100
+++ b/OrthancServer/Internals/StoreScp.cpp	Tue Feb 25 14:51:19 2014 +0100
@@ -33,6 +33,7 @@
 #include "StoreScp.h"
 
 #include "../FromDcmtkBridge.h"
+#include "../ServerToolbox.h"
 #include "../ToDcmtkBridge.h"
 #include "../../Core/OrthancException.h"
 
@@ -57,7 +58,7 @@
       uint32_t messageID;
     };
 
-
+    
     static void
     storeScpCallback(
       void *callbackData,
@@ -155,7 +156,15 @@
               catch (OrthancException& e)
               {
                 rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources;
-                LOG(ERROR) << "Exception while storing DICOM: " << e.What();
+
+                if (e.GetErrorCode() == ErrorCode_InexistentTag)
+                {
+                  LogMissingRequiredTag(summary);
+                }
+                else
+                {
+                  LOG(ERROR) << "Exception while storing DICOM: " << e.What();
+                }
               }
             }
           }
--- a/OrthancServer/ServerContext.cpp	Mon Feb 24 13:50:40 2014 +0100
+++ b/OrthancServer/ServerContext.cpp	Tue Feb 25 14:51:19 2014 +0100
@@ -238,19 +238,31 @@
     DicomMap dicomSummary;
     FromDcmtkBridge::Convert(dicomSummary, *dicomInstance.getDataset());
 
-    DicomInstanceHasher hasher(dicomSummary);
-    resultPublicId = hasher.HashInstance();
+    try
+    {
+      DicomInstanceHasher hasher(dicomSummary);
+      resultPublicId = hasher.HashInstance();
 
-    Json::Value dicomJson;
-    FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset());
+      Json::Value dicomJson;
+      FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset());
       
-    StoreStatus status = StoreStatus_Failure;
-    if (dicomSize > 0)
+      StoreStatus status = StoreStatus_Failure;
+      if (dicomSize > 0)
+      {
+        status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, "");
+      }   
+
+      return status;
+    }
+    catch (OrthancException& e)
     {
-      status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, "");
-    }   
+      if (e.GetErrorCode() == ErrorCode_InexistentTag)
+      {
+        LogMissingRequiredTag(dicomSummary);
+      }
 
-    return status;
+      throw e;
+    }
   }
 
 
--- a/OrthancServer/ServerToolbox.cpp	Mon Feb 24 13:50:40 2014 +0100
+++ b/OrthancServer/ServerToolbox.cpp	Tue Feb 25 14:51:19 2014 +0100
@@ -35,6 +35,7 @@
 #include "../Core/OrthancException.h"
 
 #include <cassert>
+#include <glog/logging.h>
 
 namespace Orthanc
 {
@@ -82,4 +83,71 @@
       }
     }
   }
+
+
+  void LogMissingRequiredTag(const DicomMap& summary)
+  {
+    std::string s, t;
+
+    if (summary.HasTag(DICOM_TAG_PATIENT_ID))
+    {
+      if (t.size() > 0)
+        t += ", ";
+      t += "PatientID=" + summary.GetValue(DICOM_TAG_PATIENT_ID).AsString();
+    }
+    else
+    {
+      if (s.size() > 0)
+        s += ", ";
+      s += "PatientID";
+    }
+
+    if (summary.HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
+    {
+      if (t.size() > 0)
+        t += ", ";
+      t += "StudyInstanceUID=" + summary.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString();
+    }
+    else
+    {
+      if (s.size() > 0)
+        s += ", ";
+      s += "StudyInstanceUID";
+    }
+
+    if (summary.HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
+    {
+      if (t.size() > 0)
+        t += ", ";
+      t += "SeriesInstanceUID=" + summary.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString();
+    }
+    else
+    {
+      if (s.size() > 0)
+        s += ", ";
+      s += "SeriesInstanceUID";
+    }
+
+    if (summary.HasTag(DICOM_TAG_SOP_INSTANCE_UID))
+    {
+      if (t.size() > 0)
+        t += ", ";
+      t += "SOPInstanceUID=" + summary.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString();
+    }
+    else
+    {
+      if (s.size() > 0)
+        s += ", ";
+      s += "SOPInstanceUID";
+    }
+
+    if (t.size() == 0)
+    {
+      LOG(ERROR) << "Store has failed because all the required tags (" << s << ") are missing (is it a DICOMDIR file?)";
+    }
+    else
+    {
+      LOG(ERROR) << "Store has failed because required tags (" << s << ") are missing for the following instance: " << t;
+    }
+  }
 }
--- a/OrthancServer/ServerToolbox.h	Mon Feb 24 13:50:40 2014 +0100
+++ b/OrthancServer/ServerToolbox.h	Tue Feb 25 14:51:19 2014 +0100
@@ -32,10 +32,14 @@
 
 #pragma once
 
+#include "../Core/DicomFormat/DicomMap.h"
+
 #include <json/json.h>
 
 namespace Orthanc
 {
   void SimplifyTags(Json::Value& target,
                     const Json::Value& source);
+
+  void LogMissingRequiredTag(const DicomMap& summary);
 }
--- a/OrthancServer/main.cpp	Mon Feb 24 13:50:40 2014 +0100
+++ b/OrthancServer/main.cpp	Tue Feb 25 14:51:19 2014 +0100
@@ -46,6 +46,7 @@
 #include "ServerContext.h"
 #include "OrthancFindRequestHandler.h"
 #include "OrthancMoveRequestHandler.h"
+#include "ServerToolbox.h"
 
 using namespace Orthanc;