changeset 1686:14a32b2fa63e

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 Oct 2015 13:57:26 +0200
parents 22e7e2ba99db
children 4d80fc990dae
files OrthancServer/DicomInstanceToStore.cpp OrthancServer/FromDcmtkBridge.cpp OrthancServer/FromDcmtkBridge.h OrthancServer/Internals/StoreScp.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h OrthancServer/ServerEnumerations.h
diffstat 7 files changed, 52 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomInstanceToStore.cpp	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/DicomInstanceToStore.cpp	Wed Oct 07 13:57:26 2015 +0200
@@ -109,7 +109,8 @@
     if (!json_.HasContent())
     {
       json_.Allocate();
-      FromDcmtkBridge::ToJson(json_.GetContent(), GetDataset(parsed_.GetContent()));
+      FromDcmtkBridge::ToJson(json_.GetContent(), GetDataset(parsed_.GetContent()), 
+                              DicomToJsonFormat_Full, 256 /* max string length */);
     }
   }
 
--- a/OrthancServer/FromDcmtkBridge.cpp	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Wed Oct 07 13:57:26 2015 +0200
@@ -575,43 +575,26 @@
   }
 
 
-  static void StoreElement(Json::Value& target,
-                           DcmElement& element,
-                           unsigned int maxStringLength,
-                           Encoding encoding);
-
-  static void StoreItem(Json::Value& target,
-                        DcmItem& item,
-                        unsigned int maxStringLength,
-                        Encoding encoding)
-  {
-    target = Json::Value(Json::objectValue);
+  static void DatasetToJson(Json::Value& target,
+                            DcmItem& item,
+                            DicomToJsonFormat format,
+                            unsigned int maxStringLength,
+                            Encoding encoding);
 
-    for (unsigned long i = 0; i < item.card(); i++)
-    {
-      DcmElement* element = item.getElement(i);
-      StoreElement(target, *element, maxStringLength, encoding);
-    }
-  }
-
-
-  static void StoreElement(Json::Value& target,
-                           DcmElement& element,
-                           unsigned int maxStringLength,
-                           Encoding encoding)
+  static void ElementToJson(Json::Value& target,
+                            DcmElement& element,
+                            DicomToJsonFormat format,
+                            unsigned int maxStringLength,
+                            Encoding encoding)
   {
     assert(target.type() == Json::objectValue);
 
     DicomTag tag(FromDcmtkBridge::GetTag(element));
     const std::string formattedTag = tag.Format();
 
-#if 0
-    const std::string tagName = FromDcmtkBridge::GetName(tag);
-#else
     // This version of the code gives access to the name of the private tags
     DcmTag tagbis(element.getTag());
     const std::string tagName(tagbis.getTagName());      
-#endif
 
     if (element.isLeaf())
     {
@@ -660,7 +643,7 @@
       {
         DcmItem* child = sequence.getItem(i);
         Json::Value& v = children.append(Json::objectValue);
-        StoreItem(v, *child, maxStringLength, encoding);
+        DatasetToJson(v, *child, format, maxStringLength, encoding);
       }  
 
       target[formattedTag]["Name"] = tagName;
@@ -670,17 +653,35 @@
   }
 
 
+  static void DatasetToJson(Json::Value& target,
+                            DcmItem& item,
+                            DicomToJsonFormat format,
+                            unsigned int maxStringLength,
+                            Encoding encoding)
+  {
+    target = Json::objectValue;
+
+    for (unsigned long i = 0; i < item.card(); i++)
+    {
+      DcmElement* element = item.getElement(i);
+      ElementToJson(target, *element, format, maxStringLength, encoding);
+    }
+  }
+
+
   void FromDcmtkBridge::ToJson(Json::Value& root, 
                                DcmDataset& dataset,
+                               DicomToJsonFormat format,
                                unsigned int maxStringLength)
   {
-    StoreItem(root, dataset, maxStringLength, DetectEncoding(dataset));
+    DatasetToJson(root, dataset, format, maxStringLength, DetectEncoding(dataset));
   }
 
 
 
   void FromDcmtkBridge::ToJson(Json::Value& target, 
                                const std::string& path,
+                               DicomToJsonFormat format,
                                unsigned int maxStringLength)
   {
     DcmFileFormat dicom;
@@ -690,7 +691,7 @@
     }
     else
     {
-      FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength);
+      FromDcmtkBridge::ToJson(target, *dicom.getDataset(), format, maxStringLength);
     }
   }
 
--- a/OrthancServer/FromDcmtkBridge.h	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/FromDcmtkBridge.h	Wed Oct 07 13:57:26 2015 +0200
@@ -71,11 +71,13 @@
 
     static void ToJson(Json::Value& target, 
                        DcmDataset& dataset,
-                       unsigned int maxStringLength = 256);       
+                       DicomToJsonFormat format,
+                       unsigned int maxStringLength);
 
     static void ToJson(Json::Value& target, 
                        const std::string& path,
-                       unsigned int maxStringLength = 256);
+                       DicomToJsonFormat format,
+                       unsigned int maxStringLength);
 
     static std::string GetName(const DicomTag& tag);
 
--- a/OrthancServer/Internals/StoreScp.cpp	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/Internals/StoreScp.cpp	Wed Oct 07 13:57:26 2015 +0200
@@ -168,7 +168,8 @@
           try
           {
             FromDcmtkBridge::Convert(summary, **imageDataSet);
-            FromDcmtkBridge::ToJson(dicomJson, **imageDataSet);       
+            FromDcmtkBridge::ToJson(dicomJson, **imageDataSet,
+                                    DicomToJsonFormat_Full, 256 /* max string length */);
 
             if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, **imageDataSet))
             {
--- a/OrthancServer/ParsedDicomFile.cpp	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed Oct 07 13:57:26 2015 +0200
@@ -1364,18 +1364,11 @@
     Replace(DICOM_TAG_SPECIFIC_CHARACTER_SET, s, DicomReplaceMode_InsertIfAbsent);
   }
 
-  void ParsedDicomFile::ToJson(Json::Value& target, bool simplify)
+  void ParsedDicomFile::ToJson(Json::Value& target, 
+                               DicomToJsonFormat format,
+                               unsigned int maxStringLength)
   {
-    if (simplify)
-    {
-      Json::Value tmp;
-      FromDcmtkBridge::ToJson(tmp, *pimpl_->file_->getDataset());
-      SimplifyTags(target, tmp);
-    }
-    else
-    {
-      FromDcmtkBridge::ToJson(target, *pimpl_->file_->getDataset());
-    }
+    FromDcmtkBridge::ToJson(target, *pimpl_->file_->getDataset(), format, maxStringLength);
   }
 
 
--- a/OrthancServer/ParsedDicomFile.h	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.h	Wed Oct 07 13:57:26 2015 +0200
@@ -123,7 +123,8 @@
     void SetEncoding(Encoding encoding);
 
     void ToJson(Json::Value& target, 
-                bool simplify);
+                DicomToJsonFormat format,
+                unsigned int maxStringLength);
 
     bool HasTag(const DicomTag& tag) const;
 
--- a/OrthancServer/ServerEnumerations.h	Wed Oct 07 10:13:42 2015 +0200
+++ b/OrthancServer/ServerEnumerations.h	Wed Oct 07 13:57:26 2015 +0200
@@ -100,6 +100,13 @@
     ValueRepresentation_Time
   };
 
+  enum DicomToJsonFormat
+  {
+    DicomToJsonFormat_Full,
+    DicomToJsonFormat_Short,
+    DicomToJsonFormat_Simple
+  };
+
 
   /**
    * WARNING: Do not change the explicit values in the enumerations