diff OrthancServer/ServerIndex.cpp @ 1898:e018037d4d0e

Support of optional tags for counting resources in C-Find
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Dec 2015 19:26:38 +0100
parents 0ef4e6e66b56
children b1291df2f780
line wrap: on
line diff
--- a/OrthancServer/ServerIndex.cpp	Wed Dec 16 09:23:52 2015 +0100
+++ b/OrthancServer/ServerIndex.cpp	Mon Dec 21 19:26:38 2015 +0100
@@ -2177,4 +2177,36 @@
       instances[pos] = db_.GetPublicId(instance);
     }
   }
+
+
+  bool ServerIndex::LookupParent(std::string& target,
+                                 const std::string& publicId,
+                                 ResourceType parentType)
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+
+    ResourceType type;
+    int64_t id;
+    if (!db_.LookupResource(id, type, publicId))
+    {
+      throw OrthancException(ErrorCode_UnknownResource);
+    }
+
+    while (type != parentType)
+    {
+      int64_t parentId;
+
+      if (type == ResourceType_Patient ||    // Cannot further go up in hierarchy
+          !db_.LookupParent(parentId, id))
+      {
+        return false;
+      }
+
+      id = parentId;
+      type = GetParentResourceType(type);
+    }
+
+    target = db_.GetPublicId(id);
+    return true;
+  }
 }