changeset 3089:fb8ee0786b1e db-changes

new extension for database plugin SDK: setResourcesContent
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 05 Jan 2019 11:39:31 +0100
parents d498ece73562
children 31244604f617
files OrthancServer/IDatabaseWrapper.h OrthancServer/ServerToolbox.cpp OrthancServer/ServerToolbox.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h Plugins/Include/orthanc/OrthancCDatabasePlugin.h
diffstat 6 files changed, 52 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/IDatabaseWrapper.h	Fri Jan 04 17:48:34 2019 +0100
+++ b/OrthancServer/IDatabaseWrapper.h	Sat Jan 05 11:39:31 2019 +0100
@@ -232,6 +232,10 @@
                                 const std::string& series,
                                 const std::string& instance) = 0;
 
+    // It is guaranteed that the resources to be modified have no main
+    // DICOM tags, and no DICOM identifiers associated with
+    // them. However, some metadata might be already existing, and
+    // have to be overwritten.
     virtual void SetResourcesContent(const ResourcesContent& content) = 0;
   };
 }
--- a/OrthancServer/ServerToolbox.cpp	Fri Jan 04 17:48:34 2019 +0100
+++ b/OrthancServer/ServerToolbox.cpp	Sat Jan 05 11:39:31 2019 +0100
@@ -100,10 +100,12 @@
 
 
   void ResourcesContent::EncodeForPlugins(
-    std::vector<OrthancPluginResourcesContentTags>& tags,
+    std::vector<OrthancPluginResourcesContentTags>& identifierTags,
+    std::vector<OrthancPluginResourcesContentTags>& mainDicomTags,
     std::vector<OrthancPluginResourcesContentMetadata>& metadata) const
   {
-    tags.reserve(tags_.size());
+    identifierTags.reserve(tags_.size());
+    mainDicomTags.reserve(tags_.size());
     metadata.reserve(metadata_.size());
 
     for (std::list<TagValue>::const_iterator
@@ -111,11 +113,18 @@
     {
       OrthancPluginResourcesContentTags tmp;
       tmp.resource = it->resourceId_;
-      tmp.isIdentifier = it->isIdentifier_;
       tmp.group = it->tag_.GetGroup();
       tmp.element = it->tag_.GetElement();
       tmp.value = it->value_.c_str();
-      tags.push_back(tmp);
+
+      if (it->isIdentifier_)
+      {
+        identifierTags.push_back(tmp);
+      }
+      else
+      {
+        mainDicomTags.push_back(tmp);
+      }
     }
 
     for (std::list<Metadata>::const_iterator
@@ -128,7 +137,7 @@
       metadata.push_back(tmp);
     }
 
-    assert(tags.size() == tags_.size() &&
+    assert(identifierTags.size() + mainDicomTags.size() == tags_.size() &&
            metadata.size() == metadata_.size());
   }
 
--- a/OrthancServer/ServerToolbox.h	Fri Jan 04 17:48:34 2019 +0100
+++ b/OrthancServer/ServerToolbox.h	Sat Jan 05 11:39:31 2019 +0100
@@ -127,8 +127,10 @@
 
     // WARNING: The resulting C structure will contain pointers to the
     // current object. Don't delete or modify it!
-    void EncodeForPlugins(std::vector<OrthancPluginResourcesContentTags>& tags,
-                          std::vector<OrthancPluginResourcesContentMetadata>& metadata) const;
+    void EncodeForPlugins(
+      std::vector<OrthancPluginResourcesContentTags>& identifierTags,
+      std::vector<OrthancPluginResourcesContentTags>& mainDicomTags,
+      std::vector<OrthancPluginResourcesContentMetadata>& metadata) const;
   };
 
   
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Jan 04 17:48:34 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Sat Jan 05 11:39:31 2019 +0100
@@ -1281,4 +1281,29 @@
       ForwardAnswers(result);
     }
   }
+
+
+  void OrthancPluginDatabase::SetResourcesContent(const Orthanc::ResourcesContent& content)
+  {
+    if (extensions_.setResourcesContent == NULL)
+    {
+      ISetResourcesContent::Apply(*this, content);
+    }
+    else
+    {
+      std::vector<OrthancPluginResourcesContentTags> identifierTags;
+      std::vector<OrthancPluginResourcesContentTags> mainDicomTags;
+      std::vector<OrthancPluginResourcesContentMetadata> metadata;
+      content.EncodeForPlugins(identifierTags, mainDicomTags, metadata);
+
+      CheckSuccess(extensions_.setResourcesContent(
+                     payload_,
+                     identifierTags.size(),
+                     (identifierTags.empty() ? NULL : &identifierTags[0]),
+                     mainDicomTags.size(),
+                     (mainDicomTags.empty() ? NULL : &mainDicomTags[0]),
+                     metadata.size(),
+                     (metadata.empty() ? NULL : &metadata[0])));
+    }
+  }
 }
--- a/Plugins/Engine/OrthancPluginDatabase.h	Fri Jan 04 17:48:34 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.h	Sat Jan 05 11:39:31 2019 +0100
@@ -352,10 +352,7 @@
       ORTHANC_OVERRIDE;
 
     virtual void SetResourcesContent(const Orthanc::ResourcesContent& content)
-      ORTHANC_OVERRIDE
-    {
-      ISetResourcesContent::Apply(*this, content);
-    }
+      ORTHANC_OVERRIDE;
   };
 }
 
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h	Fri Jan 04 17:48:34 2019 +0100
+++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h	Sat Jan 05 11:39:31 2019 +0100
@@ -158,7 +158,6 @@
   typedef struct  /* New in Orthanc 1.5.2 */
   {
     int64_t      resource;
-    uint8_t      isIdentifier;
     uint16_t     group;
     uint16_t     element;
     const char*  value;
@@ -789,9 +788,11 @@
     OrthancPluginErrorCode  (*setResourcesContent) (
       /* inputs */
       void* payload,
-      uint32_t countTags,
+      uint32_t countIdentifierTags,
+      const OrthancPluginResourcesContentTags* identifierTags,
+      uint32_t countMainDicomTags,
+      const OrthancPluginResourcesContentTags* mainDicomTags,
       uint32_t countMetadata,
-      const OrthancPluginResourcesContentTags* tags,
       const OrthancPluginResourcesContentMetadata* metadata);
 
   } OrthancPluginDatabaseExtensions;