diff Plugins/Engine/OrthancPluginDatabase.cpp @ 3187:4bbadcd03966

refactoring retrieval of metadata from database
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Feb 2019 12:06:19 +0100
parents c0d7aee8c3f8
children 6f89d22a6ec0
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Feb 01 09:28:12 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Feb 04 12:06:19 2019 +0100
@@ -390,21 +390,34 @@
   void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target,
                                              int64_t id)
   {
-    std::list<MetadataType> metadata;
-    ListAvailableMetadata(metadata, id);
+    // TODO - Add primitive in SDK
 
     target.clear();
 
-    for (std::list<MetadataType>::const_iterator
-           it = metadata.begin(); it != metadata.end(); ++it)
+    ResetAnswers();
+    CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id));
+
+    if (type_ != _OrthancPluginDatabaseAnswerType_None &&
+        type_ != _OrthancPluginDatabaseAnswerType_Int32)
     {
-      std::string value;
-      if (!LookupMetadata(value, id, *it))
+      throw OrthancException(ErrorCode_DatabasePlugin);
+    }
+
+    target.clear();
+
+    if (type_ == _OrthancPluginDatabaseAnswerType_Int32)
+    {
+      for (std::list<int32_t>::const_iterator 
+             it = answerInt32_.begin(); it != answerInt32_.end(); ++it)
       {
-        throw OrthancException(ErrorCode_DatabasePlugin);
+        MetadataType type = static_cast<MetadataType>(*it);
+
+        std::string value;
+        if (LookupMetadata(value, id, type))
+        {
+          target[type] = value;
+        }
       }
-
-      target[*it] = value;
     }
   }
 
@@ -624,31 +637,6 @@
   }
 
 
-  void OrthancPluginDatabase::ListAvailableMetadata(std::list<MetadataType>& target,
-                                                    int64_t id)
-  {
-    ResetAnswers();
-    CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id));
-
-    if (type_ != _OrthancPluginDatabaseAnswerType_None &&
-        type_ != _OrthancPluginDatabaseAnswerType_Int32)
-    {
-      throw OrthancException(ErrorCode_DatabasePlugin);
-    }
-
-    target.clear();
-
-    if (type_ == _OrthancPluginDatabaseAnswerType_Int32)
-    {
-      for (std::list<int32_t>::const_iterator 
-             it = answerInt32_.begin(); it != answerInt32_.end(); ++it)
-      {
-        target.push_back(static_cast<MetadataType>(*it));
-      }
-    }
-  }
-
-
   void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target,
                                                        int64_t id)
   {
@@ -1431,4 +1419,14 @@
       CheckSuccess(extensions_.tagMostRecentPatient(payload_, patient));
     }
   }
+
+
+  bool OrthancPluginDatabase::LookupResourceAndParent(int64_t& id,
+                                                      ResourceType& type,
+                                                      std::string& parentPublicId,
+                                                      const std::string& publicId)
+  {
+    // TODO - Add primitive in SDK
+    return ILookupResourceAndParent::Apply(*this, id, type, parentPublicId, publicId);
+  }
 }