changeset 1736:b953c6eef28d

ToJson: IncludePrivateTags and IncludeUnknownTags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Oct 2015 16:52:23 +0200
parents a001f6226c7c
children ec66a16aa398
files OrthancServer/FromDcmtkBridge.cpp OrthancServer/FromDcmtkBridge.h OrthancServer/ParsedDicomFile.cpp OrthancServer/ServerEnumerations.h UnitTestsSources/FromDcmtkTests.cpp
diffstat 5 files changed, 61 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/FromDcmtkBridge.cpp	Wed Oct 21 16:25:09 2015 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Wed Oct 21 16:52:23 2015 +0200
@@ -332,7 +332,7 @@
       {
         target.SetValue(element->getTag().getGTag(),
                         element->getTag().getETag(),
-                        ConvertLeafElement(*element, encoding));
+                        ConvertLeafElement(*element, DicomToJsonFlags_Default, encoding));
       }
     }
   }
@@ -364,6 +364,7 @@
 
 
   DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element,
+                                                  DicomToJsonFlags flags,
                                                   Encoding encoding)
   {
     if (!element.isLeaf())
@@ -700,7 +701,7 @@
 
     if (element.isLeaf())
     {
-      std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, encoding));
+      std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, flags, encoding));
       LeafValueToJson(target, *v, format, maxStringLength);
     }
     else
@@ -740,11 +741,22 @@
         throw OrthancException(ErrorCode_InternalError);
       }
 
-      if ((flags & DicomToJsonFlags_IncludePrivateTags) ||
-          !element->getTag().isPrivate())
+      if (!(flags & DicomToJsonFlags_IncludePrivateTags) &&
+          element->getTag().isPrivate())
+      {
+        continue;
+      }
+
+      if (!(flags & DicomToJsonFlags_IncludeUnknownTags))
       {
-        FromDcmtkBridge::ToJson(parent, *element, format, flags, maxStringLength, encoding);
+        DictionaryLocker locker;
+        if (locker->findEntry(element->getTag(), NULL) == NULL)
+        {
+          continue;
+        }
       }
+
+      FromDcmtkBridge::ToJson(parent, *element, format, flags, maxStringLength, encoding);
     }
   }
 
--- a/OrthancServer/FromDcmtkBridge.h	Wed Oct 21 16:25:09 2015 +0200
+++ b/OrthancServer/FromDcmtkBridge.h	Wed Oct 21 16:52:23 2015 +0200
@@ -65,6 +65,7 @@
     static bool IsUnknownTag(const DicomTag& tag);
 
     static DicomValue* ConvertLeafElement(DcmElement& element,
+                                          DicomToJsonFlags flags,
                                           Encoding encoding);
 
     static void ToJson(Json::Value& parent,
--- a/OrthancServer/ParsedDicomFile.cpp	Wed Oct 21 16:25:09 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed Oct 21 16:52:23 2015 +0200
@@ -763,7 +763,8 @@
         return false;
       }
 
-      std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, GetEncoding()));
+      std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement
+                                  (*element, DicomToJsonFlags_Default, GetEncoding()));
       
       if (v.get() == NULL)
       {
--- a/OrthancServer/ServerEnumerations.h	Wed Oct 21 16:25:09 2015 +0200
+++ b/OrthancServer/ServerEnumerations.h	Wed Oct 21 16:52:23 2015 +0200
@@ -110,10 +110,11 @@
 
   enum DicomToJsonFlags
   {
-    DicomToJsonFlags_IncludeBinary      = (1 << 0),
-    DicomToJsonFlags_IncludePrivateTags = (1 << 1),
-    DicomToJsonFlags_IncludeUnknownTags = (1 << 2),
-    DicomToJsonFlags_IncludePixelData   = (1 << 3),
+    DicomToJsonFlags_IncludeBinary           = (1 << 0),
+    DicomToJsonFlags_IncludePrivateTags      = (1 << 1),
+    DicomToJsonFlags_IncludeUnknownTags      = (1 << 2),
+    DicomToJsonFlags_IncludePixelData        = (1 << 3),
+    DicomToJsonFlags_DataUriSchemeForBinary  = (1 << 4),
 
     // Some predefined combinations
     DicomToJsonFlags_None               = 0,
--- a/UnitTestsSources/FromDcmtkTests.cpp	Wed Oct 21 16:25:09 2015 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Wed Oct 21 16:52:23 2015 +0200
@@ -523,20 +523,51 @@
 
 TEST(ParsedDicomFile, ToJsonFlags)
 {
+  FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7053, 0x1000), EVR_PN, "MyPrivateTag", 1, 1);
+  FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), EVR_PN, "Declared public tag", 1, 1);
+
   {
     ParsedDicomFile f;
-    f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false);
+    f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false);  // Even group => public tag
+    f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false);  // Even group => public, unknown tag
+    f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false);  // Odd group => private tag
 
     Json::Value v;
     f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
     ASSERT_EQ(Json::objectValue, v.type());
-    ASSERT_EQ(5, v.getMemberNames().size());
-    ASSERT_FALSE(v.isMember("7053-1000"));
+    ASSERT_EQ(6, v.getMemberNames().size());
+    ASSERT_FALSE(v.isMember("7052,1000"));
+    ASSERT_FALSE(v.isMember("7053,1000"));
+    ASSERT_TRUE(v.isMember("7050,1000"));
+    ASSERT_EQ(Json::stringValue, v["7050,1000"].type());
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
 
     f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0);
     ASSERT_EQ(Json::objectValue, v.type());
-    ASSERT_EQ(6, v.getMemberNames().size());
+    ASSERT_EQ(7, v.getMemberNames().size());
+    ASSERT_FALSE(v.isMember("7052,1000"));
+    ASSERT_TRUE(v.isMember("7050,1000"));
     ASSERT_TRUE(v.isMember("7053,1000"));
-    ASSERT_EQ(Json::nullValue, v["7053,1000"].type());
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
+    ASSERT_EQ(Json::nullValue, v["7053,1000"].type());  // TODO SHOULD BE STRING
+
+    f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludeUnknownTags, 0);
+    ASSERT_EQ(Json::objectValue, v.type());
+    ASSERT_EQ(7, v.getMemberNames().size());
+    ASSERT_TRUE(v.isMember("7050,1000"));
+    ASSERT_TRUE(v.isMember("7052,1000"));
+    ASSERT_FALSE(v.isMember("7053,1000"));
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
+    ASSERT_EQ(Json::nullValue, v["7052,1000"].type());  // TODO SHOULD BE STRING
+
+    f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags), 0);
+    ASSERT_EQ(Json::objectValue, v.type());
+    ASSERT_EQ(8, v.getMemberNames().size());
+    ASSERT_TRUE(v.isMember("7050,1000"));
+    ASSERT_TRUE(v.isMember("7052,1000"));
+    ASSERT_TRUE(v.isMember("7053,1000"));
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
+    ASSERT_EQ(Json::nullValue, v["7052,1000"].type());  // TODO SHOULD BE STRING
+    ASSERT_EQ(Json::nullValue, v["7053,1000"].type());  // TODO SHOULD BE STRING
   }
 }