changeset 7014:aeda053db543

more consistent handling of DicomWebJsonVisitor::BinaryMode_Ignore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2026 12:54:06 +0200
parents c11bace73f8c
children f1273bb03cc7
files OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.cpp OrthancFramework/UnitTestsSources/DicomMapTests.cpp OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 3 files changed, 109 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.cpp	Tue Jul 07 12:02:11 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.cpp	Tue Jul 07 12:54:06 2026 +0200
@@ -420,14 +420,17 @@
     switch (mode)
     {
       case DicomWebJsonVisitor::BinaryMode_Ignore:
-        return;
+        break;
 
       case DicomWebJsonVisitor::BinaryMode_BulkDataUri:
-        node[KEY_BULK_DATA_URI] = bulkDataUri;
+        if (!values.empty())
+        {
+          node[KEY_BULK_DATA_URI] = bulkDataUri;
+        }
+
         break;
 
       case DicomWebJsonVisitor::BinaryMode_InlineBinary:
-      {
         if (!values.empty())
         {
           std::string raw;
@@ -451,10 +454,8 @@
         }
 
         break;
-      }
 
       case DicomWebJsonVisitor::BinaryMode_ArrayOfValues:
-      {
         if (!values.empty())
         {
           node[KEY_VALUE] = Json::arrayValue;
@@ -467,7 +468,9 @@
         }
 
         break;
-      }
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
   }
 
@@ -553,6 +556,7 @@
               node[KEY_BULK_DATA_URI] = bulkDataUri;
               break;
 
+            case BinaryMode_ArrayOfValues:
             case BinaryMode_InlineBinary:
             {
               std::string tmp(static_cast<const char*>(data), size);
@@ -564,7 +568,6 @@
               break;
             }
 
-            case BinaryMode_ArrayOfValues:
             default:
               throw OrthancException(ErrorCode_ParameterOutOfRange);
           }
@@ -583,6 +586,13 @@
                                      ValueRepresentation vr,
                                      const std::vector<int64_t>& values)
   {
+    /**
+     * "If an attribute is present in DICOM but empty (i.e., Value
+     * Length is 0), it shall be preserved in the DICOM JSON attribute
+     * object containing no "Value", "BulkDataURI" or "InlineBinary"."
+     * https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_f.2.5.html
+     **/
+
     assert((vr == ValueRepresentation_OtherWord && tag != DICOM_TAG_PIXEL_DATA) ||
            vr == ValueRepresentation_OtherLong ||
            vr == ValueRepresentation_OtherVeryLong ||
@@ -596,33 +606,26 @@
     if (tag.GetElement() != 0x0000 &&
         vr != ValueRepresentation_NotSupported)
     {
-      Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
-      node[KEY_VR] = EnumerationToString(vr);
-
-      /**
-       * "If an attribute is present in DICOM but empty (i.e., Value
-       * Length is 0), it shall be preserved in the DICOM JSON
-       * attribute object containing no "Value", "BulkDataURI" or
-       * "InlineBinary"."
-       * https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_f.2.5.html
-       **/
-      if (!values.empty())
+      if (vr == ValueRepresentation_OtherWord ||
+          vr == ValueRepresentation_OtherLong ||
+          vr == ValueRepresentation_OtherVeryLong)
       {
-        if (vr == ValueRepresentation_OtherWord ||
-            vr == ValueRepresentation_OtherLong ||
-            vr == ValueRepresentation_OtherVeryLong)
-        {
-          BinaryMode mode;
-          std::string bulkDataUri;
+        BinaryMode mode;
+        std::string bulkDataUri;
 
-          if (formatter_ == NULL)
-          {
-            mode = BinaryMode_ArrayOfValues;  // This was the default in Orthanc <= 1.12.11
-          }
-          else
-          {
-            mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr);
-          }
+        if (formatter_ == NULL)
+        {
+          mode = BinaryMode_ArrayOfValues;  // This was the default in Orthanc <= 1.12.11
+        }
+        else
+        {
+          mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr);
+        }
+
+        if (mode != BinaryMode_Ignore)
+        {
+          Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
+          node[KEY_VR] = EnumerationToString(vr);
 
           switch (vr)
           {
@@ -642,7 +645,13 @@
               throw OrthancException(ErrorCode_InternalError);
           }
         }
-        else
+      }
+      else
+      {
+        Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
+        node[KEY_VR] = EnumerationToString(vr);
+
+        if (!values.empty())
         {
           Json::Value content = Json::arrayValue;
           for (size_t i = 0; i < values.size(); i++)
@@ -665,6 +674,13 @@
                                     ValueRepresentation vr,
                                     const std::vector<double>& values)
   {
+    /**
+     * "If an attribute is present in DICOM but empty (i.e., Value
+     * Length is 0), it shall be preserved in the DICOM JSON attribute
+     * object containing no "Value", "BulkDataURI" or "InlineBinary"."
+     * https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_f.2.5.html
+     **/
+
     assert(vr == ValueRepresentation_FloatingPointDouble ||
            vr == ValueRepresentation_FloatingPointSingle ||
            vr == ValueRepresentation_OtherDouble ||
@@ -673,32 +689,25 @@
     if (tag.GetElement() != 0x0000 &&
         vr != ValueRepresentation_NotSupported)
     {
-      Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
-      node[KEY_VR] = EnumerationToString(vr);
-
-      /**
-       * "If an attribute is present in DICOM but empty (i.e., Value
-       * Length is 0), it shall be preserved in the DICOM JSON
-       * attribute object containing no "Value", "BulkDataURI" or
-       * "InlineBinary"."
-       * https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_f.2.5.html
-       **/
-      if (!values.empty())
+      if (vr == ValueRepresentation_OtherDouble ||
+          vr == ValueRepresentation_OtherFloat)
       {
-        if (vr == ValueRepresentation_OtherDouble ||
-            vr == ValueRepresentation_OtherFloat)
-        {
-          BinaryMode mode;
-          std::string bulkDataUri;
+        BinaryMode mode;
+        std::string bulkDataUri;
 
-          if (formatter_ == NULL)
-          {
-            mode = BinaryMode_ArrayOfValues;  // This was the default in Orthanc <= 1.12.11
-          }
-          else
-          {
-            mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr);
-          }
+        if (formatter_ == NULL)
+        {
+          mode = BinaryMode_ArrayOfValues;  // This was the default in Orthanc <= 1.12.11
+        }
+        else
+        {
+          mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr);
+        }
+
+        if (mode != BinaryMode_Ignore)
+        {
+          Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
+          node[KEY_VR] = EnumerationToString(vr);
 
           switch (vr)
           {
@@ -714,7 +723,13 @@
               throw OrthancException(ErrorCode_InternalError);
           }
         }
-        else
+      }
+      else
+      {
+        Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
+        node[KEY_VR] = EnumerationToString(vr);
+
+        if (!values.empty())
         {
           Json::Value content = Json::arrayValue;
           for (size_t i = 0; i < values.size(); i++)
--- a/OrthancFramework/UnitTestsSources/DicomMapTests.cpp	Tue Jul 07 12:02:11 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/DicomMapTests.cpp	Tue Jul 07 12:54:06 2026 +0200
@@ -1250,11 +1250,7 @@
       visitor.VisitIntegers(parentTags, parentIndexes, tag, *it, values);
 
       const Json::Value& result = visitor.GetResult();
-      ASSERT_TRUE(result.isMember("00660041"));
-      ASSERT_EQ(EnumerationToString(*it), result["00660041"]["vr"].asString());
-      ASSERT_FALSE(result["00660041"].isMember("BulkDataURI"));
-      ASSERT_FALSE(result["00660041"].isMember("Value"));
-      ASSERT_FALSE(result["00660041"].isMember("InlineBinary"));
+      ASSERT_FALSE(result.isMember("00660041"));
     }
 
     {
@@ -1315,11 +1311,7 @@
       visitor.VisitIntegers(parentTags, parentIndexes, tag, *it, values);
 
       const Json::Value& result = visitor.GetResult();
-      ASSERT_TRUE(result.isMember("00660041"));
-      ASSERT_EQ(EnumerationToString(*it), result["00660041"]["vr"].asString());
-      ASSERT_FALSE(result["00660041"].isMember("BulkDataURI"));
-      ASSERT_FALSE(result["00660041"].isMember("Value"));
-      ASSERT_FALSE(result["00660041"].isMember("InlineBinary"));
+      ASSERT_FALSE(result.isMember("00660041"));
     }
 
     {
@@ -1472,11 +1464,7 @@
       visitor.VisitDoubles(parentTags, parentIndexes, tag, *it, values);
 
       const Json::Value& result = visitor.GetResult();
-      ASSERT_TRUE(result.isMember("00660027"));
-      ASSERT_EQ(EnumerationToString(*it), result["00660027"]["vr"].asString());
-      ASSERT_FALSE(result["00660027"].isMember("BulkDataURI"));
-      ASSERT_FALSE(result["00660027"].isMember("Value"));
-      ASSERT_FALSE(result["00660027"].isMember("InlineBinary"));
+      ASSERT_FALSE(result.isMember("00660027"));
     }
 
     {
@@ -1536,11 +1524,7 @@
       visitor.VisitDoubles(parentTags, parentIndexes, tag, *it, values);
 
       const Json::Value& result = visitor.GetResult();
-      ASSERT_TRUE(result.isMember("00660027"));
-      ASSERT_EQ(EnumerationToString(*it), result["00660027"]["vr"].asString());
-      ASSERT_FALSE(result["00660027"].isMember("BulkDataURI"));
-      ASSERT_FALSE(result["00660027"].isMember("Value"));
-      ASSERT_FALSE(result["00660027"].isMember("InlineBinary"));
+      ASSERT_FALSE(result.isMember("00660027"));
     }
 
     {
@@ -1799,23 +1783,29 @@
 #if DCMTK_VERSION_NUMBER >= 361
     ASSERT_EQ("US", result["00080301"]["vr"].asString());
     ASSERT_EQ(17u, result["00080301"]["Value"][0].asUInt());
-
-    ASSERT_EQ("OD", result["7FE00009"]["vr"].asString());
-    ASSERT_EQ("OL", result["00660040"]["vr"].asString());
 #endif
 
-    ASSERT_EQ("OW", result["00281201"]["vr"].asString());
-    ASSERT_EQ("OF", result["00640009"]["vr"].asString());
-
     switch (*mode)
     {
       case DicomWebJsonVisitor::BinaryMode_Ignore:
-        ASSERT_FALSE(result["00281201"].isMember("Value"));
-        ASSERT_FALSE(result["00281201"].isMember("BulkDataURI"));
-        ASSERT_FALSE(result["00281201"].isMember("InlineBinary"));
+#if DCMTK_VERSION_NUMBER >= 361
+        ASSERT_FALSE(result.isMember("7FE00009"));
+        ASSERT_FALSE(result.isMember("00660040"));
+#endif
+
+        ASSERT_FALSE(result.isMember("00281201"));
+        ASSERT_FALSE(result.isMember("00640009"));
         break;
 
       case DicomWebJsonVisitor::BinaryMode_BulkDataUri:
+#if DCMTK_VERSION_NUMBER >= 361
+        ASSERT_EQ("OD", result["7FE00009"]["vr"].asString());
+        ASSERT_EQ("OL", result["00660040"]["vr"].asString());
+#endif
+
+        ASSERT_EQ("OW", result["00281201"]["vr"].asString());
+        ASSERT_EQ("OF", result["00640009"]["vr"].asString());
+
         ASSERT_FALSE(result["00281201"].isMember("Value"));
         ASSERT_TRUE(result["00281201"].isMember("BulkDataURI"));
         ASSERT_FALSE(result["00281201"].isMember("InlineBinary"));
@@ -1827,6 +1817,14 @@
         break;
 
       case DicomWebJsonVisitor::BinaryMode_ArrayOfValues:
+#if DCMTK_VERSION_NUMBER >= 361
+        ASSERT_EQ("OD", result["7FE00009"]["vr"].asString());
+        ASSERT_EQ("OL", result["00660040"]["vr"].asString());
+#endif
+
+        ASSERT_EQ("OW", result["00281201"]["vr"].asString());
+        ASSERT_EQ("OF", result["00640009"]["vr"].asString());
+
         ASSERT_TRUE(result["00281201"].isMember("Value"));
         ASSERT_FALSE(result["00281201"].isMember("BulkDataURI"));
         ASSERT_FALSE(result["00281201"].isMember("InlineBinary"));
@@ -1842,6 +1840,14 @@
         break;
 
       case DicomWebJsonVisitor::BinaryMode_InlineBinary:
+#if DCMTK_VERSION_NUMBER >= 361
+        ASSERT_EQ("OD", result["7FE00009"]["vr"].asString());
+        ASSERT_EQ("OL", result["00660040"]["vr"].asString());
+#endif
+
+        ASSERT_EQ("OW", result["00281201"]["vr"].asString());
+        ASSERT_EQ("OF", result["00640009"]["vr"].asString());
+
         ASSERT_FALSE(result["00281201"].isMember("Value"));
         ASSERT_FALSE(result["00281201"].isMember("BulkDataURI"));
         ASSERT_TRUE(result["00281201"].isMember("InlineBinary"));
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Jul 07 12:02:11 2026 +0200
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Jul 07 12:54:06 2026 +0200
@@ -1071,7 +1071,7 @@
   /**
    * The available modes to export a binary DICOM tag into a DICOMweb
    * JSON or XML document. Binary DICOM tags correspond to the tags
-   * whose value representation is "other" (OB, OW, OL, OV, OF, or OD).
+   * whose value representation is "other" (OB, OD, OF, OL, OV, or OW).
    **/
   typedef enum ORTHANC_PLUGIN_SINCE_SDK("1.5.4")
   {