changeset 524:43d4ba62a9ba

share ExtraMainDicomTags with the core of Orthanc
author Alain Mazy <am@osimis.io>
date Tue, 28 Jun 2022 18:37:28 +0200
parents f32d11e0555d
children a4c93eea9403
files NEWS Plugin/Configuration.cpp Plugin/DicomWebFormatter.cpp Plugin/WadoRs.cpp
diffstat 4 files changed, 63 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Jun 24 17:06:51 2022 +0200
+++ b/NEWS	Tue Jun 28 18:37:28 2022 +0200
@@ -1,6 +1,10 @@
 Pending changes in the mainline
 ===============================
 
+* if using "MainDicomTags" mode for "SeriesMetadata" and "StudiesMetadata",
+  the plugin now returns the "ExtraMainDicomTags" that have been configured on Orthanc side.
+* Now able to return sequences stored in "ExtraMainDicomTags" (with Orthanc 1.11.1)
+
 Version 1.8 (2022-05-09)
 ========================
 
--- a/Plugin/Configuration.cpp	Fri Jun 24 17:06:51 2022 +0200
+++ b/Plugin/Configuration.cpp	Tue Jun 28 18:37:28 2022 +0200
@@ -318,7 +318,7 @@
             const std::string& tagName = content[t].asString();
             Orthanc::DicomTag tag(0, 0);
             OrthancPlugins::ParseTag(tag, tagName);
-            Orthanc::DicomMap::AddMainDicomTag(tag, tagName, level);
+            Orthanc::DicomMap::AddMainDicomTag(tag, level);
           }
         }
       }
--- a/Plugin/DicomWebFormatter.cpp	Fri Jun 24 17:06:51 2022 +0200
+++ b/Plugin/DicomWebFormatter.cpp	Tue Jun 28 18:37:28 2022 +0200
@@ -175,6 +175,46 @@
     }
   }
 
+
+  static void ToShortDicomAsJson(Json::Value& target, const Json::Value& fullJsonSource)
+  {
+    // printf("%s", fullJsonSource.toStyledString().c_str());
+
+    if (fullJsonSource.isArray() && target.isArray())
+    {
+      for (Json::Value::ArrayIndex i = 0; i < fullJsonSource.size(); ++i)
+      {
+        Json::Value& child = target.append(Json::objectValue);
+        ToShortDicomAsJson(child, fullJsonSource[i]);
+      }
+    }
+    else if (fullJsonSource.isObject() && target.isObject())
+    {
+      const Json::Value::Members& members = fullJsonSource.getMemberNames();
+      for (Json::Value::Members::const_iterator member = members.begin();
+           member != members.end(); ++member)
+      {
+        target[*member] = Json::objectValue;
+        const Json::Value& jsonSourceMember = fullJsonSource[*member];
+        if (jsonSourceMember.isMember("Type"))
+        {
+          if (jsonSourceMember["Type"] == "String")
+          {
+            target[*member] = jsonSourceMember["Value"];
+          }
+          else if (jsonSourceMember["Type"] == "Sequence")
+          {
+            target[*member] = Json::arrayValue;
+            ToShortDicomAsJson(target[*member], jsonSourceMember["Value"]);
+          }
+          else if (jsonSourceMember["Type"] == "Null")
+          {
+            target[*member] = Json::nullValue;
+          }
+        }
+      }
+    }
+  }
                   
   void DicomWebFormatter::HttpWriter::AddOrthancMap(const Orthanc::DicomMap& value)
   {
@@ -183,13 +223,23 @@
     std::set<Orthanc::DicomTag> tags;
     value.GetTags(tags);
     
+    // construct a "short" DicomAsJson that can be used in CreateDicom
     for (std::set<Orthanc::DicomTag>::const_iterator
            it = tags.begin(); it != tags.end(); ++it)
     {
-      std::string s;
-      if (value.LookupStringValue(s, *it, false))
+      const Orthanc::DicomValue& v = value.GetValue(*it);
+      if (v.IsSequence())
       {
-        json[it->Format()] = s;
+        json[it->Format()] = Json::arrayValue;
+        ToShortDicomAsJson(json[it->Format()], v.GetSequenceContent());
+      }
+      else
+      {
+        std::string s;
+        if (value.LookupStringValue(s, *it, false))
+        {
+          json[it->Format()] = s;
+        }
       }
     }
     
--- a/Plugin/WadoRs.cpp	Fri Jun 24 17:06:51 2022 +0200
+++ b/Plugin/WadoRs.cpp	Tue Jun 28 18:37:28 2022 +0200
@@ -484,16 +484,16 @@
       switch (level)
       {
         case Orthanc::ResourceType_Study:
-          uri = "/studies/" + orthancId;
+          uri = "/studies/" + orthancId + "?full";
           break;
             
         case Orthanc::ResourceType_Series:
-          uri = "/series/" + orthancId;
+          uri = "/series/" + orthancId + "?full";
           parentField = "ParentStudy";
           break;
             
         case Orthanc::ResourceType_Instance:
-          uri = "/instances/" + orthancId;
+          uri = "/instances/" + orthancId + "?full";
           parentField = "ParentSeries";
           break;
 
@@ -514,13 +514,13 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
       }
 
-      dicom.ParseMainDicomTags(value[MAIN_DICOM_TAGS], level);
+      dicom.FromDicomAsJson(value[MAIN_DICOM_TAGS], false /* append */, true /* parseSequences */);
 
       if (level == Orthanc::ResourceType_Study)
       {
         if (value.isMember(PATIENT_MAIN_DICOM_TAGS))
         {
-          dicom.ParseMainDicomTags(value[PATIENT_MAIN_DICOM_TAGS], Orthanc::ResourceType_Patient);
+          dicom.FromDicomAsJson(value[PATIENT_MAIN_DICOM_TAGS], true /* append */, true /* parseSequences */);
         }
         else
         {