changeset 4502:e3e759cbd19c

refactoring IStoreRequestHandler
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Feb 2021 15:50:14 +0100
parents 11c2ddb4e2ca
children b525e0c3cff0
files OrthancFramework/Sources/DicomNetworking/IStoreRequestHandler.h OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp OrthancServer/Sources/main.cpp
diffstat 3 files changed, 22 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/IStoreRequestHandler.h	Tue Feb 09 15:24:36 2021 +0100
+++ b/OrthancFramework/Sources/DicomNetworking/IStoreRequestHandler.h	Tue Feb 09 15:50:14 2021 +0100
@@ -28,6 +28,8 @@
 #include <string>
 #include <json/value.h>
 
+class DcmDataset;
+
 namespace Orthanc
 {
   class IStoreRequestHandler : public boost::noncopyable
@@ -37,9 +39,7 @@
     {
     }
 
-    virtual void Handle(const std::string& dicomFile,
-                        const DicomMap& dicomSummary,
-                        const Json::Value& dicomJson,
+    virtual void Handle(DcmDataset& dicom,
                         const std::string& remoteIp,
                         const std::string& remoteAet,
                         const std::string& calledAet) = 0;
--- a/OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp	Tue Feb 09 15:24:36 2021 +0100
+++ b/OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp	Tue Feb 09 15:50:14 2021 +0100
@@ -154,30 +154,6 @@
         // is present and the options opt_bitPreserving and opt_ignore are not set.
         if ((imageDataSet != NULL) && (*imageDataSet != NULL))
         {
-          DicomMap summary;
-          Json::Value dicomJson;
-          std::string buffer;
-
-          try
-          {
-            std::set<DicomTag> ignoreTagLength;
-
-            // TODO => Parameters in class "DicomServer"
-            FromDcmtkBridge::ExtractDicomSummary(summary, **imageDataSet, ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
-            FromDcmtkBridge::ExtractDicomAsJson(dicomJson, **imageDataSet, DicomToJsonFormat_Full,
-                                                DicomToJsonFlags_Default, ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
-
-            if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, **imageDataSet))
-            {
-              CLOG(ERROR, DICOM) << "cannot write DICOM file to memory";
-              rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources;
-            }
-          }
-          catch (...)
-          {
-            rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources;
-          }
-
           // check the image to make sure it is consistent, i.e. that its sopClass and sopInstance correspond
           // to those mentioned in the request. If not, set the status in the response message variable.
           if (rsp->DimseStatus == STATUS_Success)
@@ -206,7 +182,7 @@
               {
                 try
                 {
-                  cbdata->handler->Handle(buffer, summary, dicomJson, *cbdata->remoteIp, cbdata->remoteAET, cbdata->calledAET);
+                  cbdata->handler->Handle(**imageDataSet, *cbdata->remoteIp, cbdata->remoteAET, cbdata->calledAET);
                 }
                 catch (OrthancException& e)
                 {
@@ -214,7 +190,7 @@
 
                   if (e.GetErrorCode() == ErrorCode_InexistentTag)
                   {
-                    summary.LogMissingTagsForStore();
+                    FromDcmtkBridge::LogMissingTagsForStore(**imageDataSet);
                   }
                   else
                   {
--- a/OrthancServer/Sources/main.cpp	Tue Feb 09 15:24:36 2021 +0100
+++ b/OrthancServer/Sources/main.cpp	Tue Feb 09 15:50:14 2021 +0100
@@ -83,13 +83,27 @@
   }
 
 
-  virtual void Handle(const std::string& dicomFile,
-                      const DicomMap& dicomSummary,
-                      const Json::Value& dicomJson,
+  virtual void Handle(DcmDataset& dicom,
                       const std::string& remoteIp,
                       const std::string& remoteAet,
                       const std::string& calledAet) ORTHANC_OVERRIDE 
   {
+    DicomMap dicomSummary;
+    Json::Value dicomJson;
+    std::string dicomFile;
+
+    const std::set<DicomTag> ignoreTagLength;
+
+    // TODO => Parameters in class "DicomServer"
+    FromDcmtkBridge::ExtractDicomSummary(dicomSummary, dicom, ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
+    FromDcmtkBridge::ExtractDicomAsJson(dicomJson, dicom, DicomToJsonFormat_Full,
+                                        DicomToJsonFlags_Default, ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength);
+
+    if (!FromDcmtkBridge::SaveToMemoryBuffer(dicomFile, dicom))
+    {
+      throw OrthancException(ErrorCode_InternalError, "Cannot write DICOM file to memory");
+    }
+    
     if (dicomFile.size() > 0)
     {
       DicomInstanceToStore toStore;