diff Plugins/Engine/OrthancPluginDatabase.cpp @ 1727:1ae29c5e52fb db-changes

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 14:50:10 +0200
parents 2b812969e136
children 4941494b5dd8
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Tue Oct 20 11:21:36 2015 +0200
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Tue Oct 20 14:50:10 2015 +0200
@@ -595,6 +595,7 @@
 
 
   void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target,
+                                               ResourceType level,
                                                const DicomTag& tag,
                                                const std::string& value)
   {
@@ -605,9 +606,42 @@
     tmp.element = tag.GetElement();
     tmp.value = value.c_str();
 
-    CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp));
+    if (extensions_.lookupIdentifier3 != NULL)
+    {
+      CheckSuccess(extensions_.lookupIdentifier3(GetContext(), payload_, Plugins::Convert(level), &tmp));
+      ForwardAnswers(target);
+    }
+    else
+    {
+      // Emulate "lookupIdentifier3" if unavailable
+
+      if (backend_.lookupIdentifier == NULL)
+      {
+        throw OrthancException(ErrorCode_DatabasePlugin);
+      }
+
+      CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp));
 
-    ForwardAnswers(target);
+      if (type_ != _OrthancPluginDatabaseAnswerType_None &&
+          type_ != _OrthancPluginDatabaseAnswerType_Int64)
+      {
+        throw OrthancException(ErrorCode_DatabasePlugin);
+      }
+
+      target.clear();
+
+      if (type_ == _OrthancPluginDatabaseAnswerType_Int64)
+      {
+        for (std::list<int64_t>::const_iterator 
+               it = answerInt64_.begin(); it != answerInt64_.end(); ++it)
+        {
+          if (GetResourceType(*it) == level)
+          {
+            target.push_back(*it);
+          }
+        }
+      }
+    }
   }