diff OrthancServer/ServerIndex.cpp @ 1002:b067017a8a5b lua-scripting

anonymization refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jul 2014 16:31:14 +0200
parents 84513f2ee1f3
children a226e0959d8b
line wrap: on
line diff
--- a/OrthancServer/ServerIndex.cpp	Fri Jul 04 15:31:42 2014 +0200
+++ b/OrthancServer/ServerIndex.cpp	Fri Jul 04 16:31:14 2014 +0200
@@ -384,7 +384,8 @@
 
   StoreStatus ServerIndex::Store(const DicomMap& dicomSummary,
                                  const Attachments& attachments,
-                                 const std::string& remoteAet)
+                                 const std::string& remoteAet,
+                                 const MetadataMap* metadata)
   {
     boost::mutex::scoped_lock lock(mutex_);
     listener_->Reset();
@@ -519,7 +520,37 @@
         db_->AddAttachment(instance, *it);
       }
 
-      // Attach the metadata
+      // Attach the user-specified metadata
+      if (metadata)
+      {
+        for (MetadataMap::const_iterator 
+               it = metadata->begin(); it != metadata->end(); ++it)
+        {
+          switch (it->first.first)
+          {
+            case ResourceType_Patient:
+              db_->SetMetadata(patient, it->first.second, it->second);
+              break;
+
+            case ResourceType_Study:
+              db_->SetMetadata(study, it->first.second, it->second);
+              break;
+
+            case ResourceType_Series:
+              db_->SetMetadata(series, it->first.second, it->second);
+              break;
+
+            case ResourceType_Instance:
+              db_->SetMetadata(instance, it->first.second, it->second);
+              break;
+
+            default:
+              throw OrthancException(ErrorCode_ParameterOutOfRange);
+          }
+        }
+      }
+
+      // Attach the auto-computer metadata
       std::string now = Toolbox::GetNowIsoString();
       db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, now);
       db_->SetMetadata(series, MetadataType_LastUpdate, now);
@@ -1694,4 +1725,33 @@
   }
 
 
+  bool ServerIndex::GetMetadata(Json::Value& target,
+                                const std::string& publicId)
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+
+    target = Json::objectValue;
+
+    ResourceType type;
+    int64_t id;
+    if (!db_->LookupResource(publicId, id, type))
+    {
+      return false;
+    }
+
+    std::list<MetadataType> metadata;
+    db_->ListAvailableMetadata(metadata, id);
+
+    for (std::list<MetadataType>::const_iterator
+           it = metadata.begin(); it != metadata.end(); it++)
+    {
+      std::string key = EnumerationToString(*it);
+      std::string value = db_->GetMetadata(id, *it);
+      target[key] = value;
+    }
+
+    return true;
+  }
+
+
 }