changeset 5440:99fa307438e1 debug-telemis

DicomStoreUserConnection: improved logs
author Alain Mazy <am@osimis.io>
date Wed, 22 Nov 2023 21:18:16 +0100
parents 54b717b1d27e
children ac68a4383e51
files OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h
diffstat 2 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp	Wed Nov 22 13:10:34 2023 +0100
+++ b/OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.cpp	Wed Nov 22 21:18:16 2023 +0100
@@ -254,7 +254,8 @@
     DicomTransferSyntax transferSyntax,
     bool hasPreferred,
     DicomTransferSyntax preferred,
-    bool alwaysRenegotiate)
+    bool alwaysRenegotiate,
+    bool enableLogs)
   {
     /**
      * Step 1: Check whether this presentation context is already
@@ -269,17 +270,25 @@
     // The association must be re-negotiated
     if (association_->IsOpen())
     {
-      CLOG(INFO, DICOM) << "Re-negotiating DICOM association with "
-                        << parameters_.GetRemoteModality().GetApplicationEntityTitle();
+      if (enableLogs)
+      {
+        CLOG(INFO, DICOM) << "Re-negotiating DICOM association with "
+                          << parameters_.GetRemoteModality().GetApplicationEntityTitle()
+                          << " for SOPClassUID " << sopClassUid;
+      }
 
       // Don't renegociate if we know that the remote modality was
       // already proposed this individual transfer syntax (**)
-      if (!alwaysRenegotiate &&
+      if (!alwaysRenegotiate && 
           proposedOriginalClasses_.find(std::make_pair(sopClassUid, transferSyntax)) != proposedOriginalClasses_.end())
       {
-        CLOG(INFO, DICOM) << "The remote modality has already rejected SOP class UID \""
-                          << sopClassUid << "\" with transfer syntax \""
-                          << GetTransferSyntaxUid(transferSyntax) << "\", don't renegotiate";
+        if (enableLogs)
+        {
+          CLOG(INFO, DICOM) << "The remote modality has already rejected SOP class UID \""
+                            << sopClassUid << "\" with transfer syntax \""
+                            << GetTransferSyntaxUid(transferSyntax) << "\", don't renegotiate";
+        }
+
         return false;
       }
     }
@@ -378,7 +387,7 @@
 
     uint8_t presID;
     if (!NegotiatePresentationContext(presID, sopClassUid, transferSyntax, proposeUncompressedSyntaxes_,
-                                      DicomTransferSyntax_LittleEndianExplicit, alwaysRenegotiate))
+                                      DicomTransferSyntax_LittleEndianExplicit, alwaysRenegotiate, true))
     {
       throw OrthancException(ErrorCode_NetworkProtocol,
                              "No valid presentation context was negotiated for "
@@ -489,7 +498,7 @@
     // syntax. We don't use the return code: Transcoding is possible
     // even if the "sourceSyntax" is not supported.
     uint8_t presID;
-    NegotiatePresentationContext(presID, sopClassUid, sourceSyntax, hasPreferred, preferred, alwaysRenegotiate);
+    NegotiatePresentationContext(presID, sopClassUid, sourceSyntax, hasPreferred, preferred, alwaysRenegotiate, false);
 
     std::map<DicomTransferSyntax, uint8_t> contexts;
     if (association_->LookupAcceptedPresentationContext(contexts, sopClassUid))
@@ -529,6 +538,12 @@
     std::set<DicomTransferSyntax> accepted;
     LookupTranscoding(accepted, sopClassUid, sourceSyntax, true, preferredTransferSyntax, alwaysRenegotiate);
 
+    if (accepted.size() == 0)
+    {
+      throw OrthancException(ErrorCode_NoPresentationContext, "Cannot store instance of SOPClassUID " + 
+                              sopClassUid + ", the destination has not accepted any TransferSyntax for this SOPClassUID.");
+    }
+
     if (accepted.find(sourceSyntax) != accepted.end())
     {
       // No need for transcoding
@@ -634,7 +649,8 @@
           s += " " + std::string(GetTransferSyntaxUid(*it));
         }
         
-        throw OrthancException(ErrorCode_NotImplemented, "Cannot transcode from " +
+        throw OrthancException(ErrorCode_NotImplemented, "Cannot transcode instance of SOPClassUID " + 
+                               sopClassUid + " from " +
                                std::string(GetTransferSyntaxUid(sourceSyntax)) +
                                " to one of [" + s + " ]");
       }
--- a/OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h	Wed Nov 22 13:10:34 2023 +0100
+++ b/OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h	Wed Nov 22 21:18:16 2023 +0100
@@ -95,7 +95,8 @@
                                       DicomTransferSyntax transferSyntax,
                                       bool hasPreferred,
                                       DicomTransferSyntax preferred,
-                                      bool alwaysRenegotiate);
+                                      bool alwaysRenegotiate,
+                                      bool enableLogs);
 
 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
     void LookupTranscoding(std::set<DicomTransferSyntax>& acceptedSyntaxes,