changeset 791:381f90e2b69d

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 May 2014 22:44:34 +0200
parents 331eaf9d9d69
children 111a1738e11e
files NEWS OrthancServer/FromDcmtkBridge.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h
diffstat 7 files changed, 48 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon May 05 18:55:10 2014 +0200
+++ b/NEWS	Mon May 05 22:44:34 2014 +0200
@@ -4,7 +4,7 @@
 * Dynamic negotiation of SOP classes for C-Store SCU
 * Reuse of the previous SCU connection to avoid unecessary handshakes
 * Fix missing licensing terms about reuse of some DCMTK code
-* Refactorings
+* Various code refactorings
 
 
 Version 0.7.4 (2014/04/16)
--- a/OrthancServer/FromDcmtkBridge.h	Mon May 05 18:55:10 2014 +0200
+++ b/OrthancServer/FromDcmtkBridge.h	Mon May 05 22:44:34 2014 +0200
@@ -32,13 +32,11 @@
 
 #pragma once
 
-#include "../Core/DicomFormat/DicomInstanceHasher.h"
-#include "../Core/RestApi/RestApiOutput.h"
-#include "../Core/Toolbox.h"
 #include "ServerEnumerations.h"
 
+#include "../Core/DicomFormat/DicomMap.h"
+
 #include <dcmtk/dcmdata/dcdatset.h>
-#include <dcmtk/dcmdata/dcfilefo.h>
 #include <json/json.h>
 #include <memory>
 
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon May 05 18:55:10 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon May 05 22:44:34 2014 +0200
@@ -256,7 +256,7 @@
       modification.Apply(*modified);
 
       std::string modifiedInstance;
-      if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success)
+      if (context.Store(modifiedInstance, *modified) != StoreStatus_Success)
       {
         LOG(ERROR) << "Error while storing a modified instance " << *it;
         return;
--- a/OrthancServer/ParsedDicomFile.cpp	Mon May 05 18:55:10 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Mon May 05 22:44:34 2014 +0200
@@ -1035,4 +1035,22 @@
     Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
   }
 
+
+  ParsedDicomFile::ParsedDicomFile(const char* content,
+                                   size_t size)
+  {
+    Setup(content, size);
+  }
+
+  ParsedDicomFile::ParsedDicomFile(const std::string& content)
+  {
+    if (content.size() == 0)
+    {
+      Setup(NULL, 0);
+    }
+    else
+    {
+      Setup(&content[0], content.size());
+    }
+  }
 }
--- a/OrthancServer/ParsedDicomFile.h	Mon May 05 18:55:10 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.h	Mon May 05 22:44:34 2014 +0200
@@ -60,18 +60,9 @@
     ParsedDicomFile();  // Create a minimal DICOM instance
 
     ParsedDicomFile(const char* content,
-                    size_t size)
-    {
-      Setup(content, size);
-    }
+                    size_t size);
 
-    ParsedDicomFile(const std::string& content)
-    {
-      if (content.size() == 0)
-        Setup(NULL, 0);
-      else
-        Setup(&content[0], content.size());
-    }
+    ParsedDicomFile(const std::string& content);
 
     DcmFileFormat& GetDicom()
     {
--- a/OrthancServer/ServerContext.cpp	Mon May 05 18:55:10 2014 +0200
+++ b/OrthancServer/ServerContext.cpp	Mon May 05 22:44:34 2014 +0200
@@ -247,12 +247,12 @@
 
 
   StoreStatus ServerContext::Store(std::string& resultPublicId,
-                                   DcmFileFormat& dicomInstance,
+                                   ParsedDicomFile& dicomInstance,
                                    const char* dicomBuffer,
                                    size_t dicomSize)
   {
     DicomMap dicomSummary;
-    FromDcmtkBridge::Convert(dicomSummary, *dicomInstance.getDataset());
+    FromDcmtkBridge::Convert(dicomSummary, *dicomInstance.GetDicom().getDataset());
 
     try
     {
@@ -260,7 +260,7 @@
       resultPublicId = hasher.HashInstance();
 
       Json::Value dicomJson;
-      FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset());
+      FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.GetDicom().getDataset());
       
       StoreStatus status = StoreStatus_Failure;
       if (dicomSize > 0)
@@ -283,10 +283,10 @@
 
 
   StoreStatus ServerContext::Store(std::string& resultPublicId,
-                                   DcmFileFormat& dicomInstance)
+                                   ParsedDicomFile& dicomInstance)
   {
     std::string buffer;
-    if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, dicomInstance.getDataset()))
+    if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, dicomInstance.GetDicom().getDataset()))
     {
       throw OrthancException(ErrorCode_InternalError);
     }
@@ -303,9 +303,24 @@
                                    size_t dicomSize)
   {
     ParsedDicomFile dicom(dicomBuffer, dicomSize);
-    return Store(resultPublicId, dicom.GetDicom(), dicomBuffer, dicomSize);
+    return Store(resultPublicId, dicom, dicomBuffer, dicomSize);
   }
 
+
+  StoreStatus ServerContext::Store(std::string& resultPublicId,
+                                   const std::string& dicomContent)
+  {
+    if (dicomContent.size() == 0)
+    {
+      return Store(resultPublicId, NULL, 0);
+    }
+    else
+    {
+      return Store(resultPublicId, &dicomContent[0], dicomContent.size());
+    }
+  }
+
+
   void ServerContext::SetStoreMD5ForAttachments(bool storeMD5)
   {
     LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no");
--- a/OrthancServer/ServerContext.h	Mon May 05 18:55:10 2014 +0200
+++ b/OrthancServer/ServerContext.h	Mon May 05 22:44:34 2014 +0200
@@ -125,25 +125,19 @@
                       const std::string& remoteAet);
 
     StoreStatus Store(std::string& resultPublicId,
-                      DcmFileFormat& dicomInstance,
+                      ParsedDicomFile& dicomInstance,
                       const char* dicomBuffer,
                       size_t dicomSize);
 
     StoreStatus Store(std::string& resultPublicId,
-                      DcmFileFormat& dicomInstance);
+                      ParsedDicomFile& dicomInstance);
 
     StoreStatus Store(std::string& resultPublicId,
                       const char* dicomBuffer,
                       size_t dicomSize);
 
     StoreStatus Store(std::string& resultPublicId,
-                      const std::string& dicomContent)
-    {
-      if (dicomContent.size() == 0)
-        return Store(resultPublicId, NULL, 0);
-      else
-        return Store(resultPublicId, &dicomContent[0], dicomContent.size());
-    }
+                      const std::string& dicomContent);
 
     void AnswerDicomFile(RestApiOutput& output,
                          const std::string& instancePublicId,