changeset 1139:f167b672db94

/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Sep 2014 16:38:28 +0200
parents 4c4fdee093de
children 94c5f6623b3a
files NEWS OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h
diffstat 4 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Sep 10 13:16:08 2014 +0200
+++ b/NEWS	Wed Sep 10 16:38:28 2014 +0200
@@ -7,6 +7,7 @@
 * Creation of ZIP archives for media storage, with DICOMDIR
 * Support of index-only mode (using the "StoreDicom" option)
 * Plugins can implement a custom storage area
+* "/tools/lookup" URI to map DICOM UIDs to Orthanc identifiers
 
 Minor
 -----
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed Sep 10 13:16:08 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed Sep 10 16:38:28 2014 +0200
@@ -781,6 +781,35 @@
   }
 
 
+  static void Lookup(RestApiPostCall& call)
+  {
+    typedef std::list< std::pair<ResourceType, std::string> >  Resources;
+
+    std::string tag = call.GetPostBody();
+    Resources resources;
+
+    OrthancRestApi::GetIndex(call).LookupTagValue(resources, tag);
+
+    Json::Value result = Json::arrayValue;
+    
+    for (Resources::const_iterator it = resources.begin();
+         it != resources.end(); it++)
+    {     
+      ResourceType type = it->first;
+      const std::string& id = it->second;
+      
+      Json::Value item = Json::objectValue;
+      item["Type"] = EnumerationToString(type);
+      item["ID"] = id;
+      item["Path"] = GetBasePath(type, id);
+    
+      result.append(item);
+    }
+
+    call.GetOutput().AnswerJson(result);
+  }
+
+
   void OrthancRestApi::RegisterResources()
   {
     Register("/instances", ListResources<ResourceType_Instance>);
@@ -849,6 +878,8 @@
     Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
     Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
 
+    Register("/tools/lookup", Lookup);
+
     Register("/instances/{id}/content/*", GetRawContent);
   }
 }
--- a/OrthancServer/ServerIndex.cpp	Wed Sep 10 13:16:08 2014 +0200
+++ b/OrthancServer/ServerIndex.cpp	Wed Sep 10 16:38:28 2014 +0200
@@ -1663,7 +1663,7 @@
   }
 
 
-  void ServerIndex::LookupTagValue(std::list<std::string>& result,
+  void ServerIndex::LookupTagValue(std::list< std::pair<ResourceType, std::string> >& result,
                                    const std::string& value)
   {
     result.clear();
@@ -1676,7 +1676,8 @@
     for (std::list<int64_t>::const_iterator 
            it = id.begin(); it != id.end(); ++it)
     {
-      result.push_back(db_->GetPublicId(*it));
+      result.push_back(std::make_pair(db_->GetResourceType(*it),
+                                      db_->GetPublicId(*it)));
     }
   }
 
--- a/OrthancServer/ServerIndex.h	Wed Sep 10 13:16:08 2014 +0200
+++ b/OrthancServer/ServerIndex.h	Wed Sep 10 16:38:28 2014 +0200
@@ -225,7 +225,7 @@
                         DicomTag tag,
                         const std::string& value);
 
-    void LookupTagValue(std::list<std::string>& result,
+    void LookupTagValue(std::list< std::pair<ResourceType, std::string> >& result,
                         const std::string& value);
 
     StoreStatus AddAttachment(const FileInfo& attachment,