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

anonymization refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jul 2014 16:31:14 +0200
parents 2f76b92addd4
children 84b6d7bca6db
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Jul 04 15:31:42 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Jul 04 16:31:14 2014 +0200
@@ -252,47 +252,53 @@
 
 
       /**
-       * Compute the resulting DICOM instance and store it into the Orthanc store.
+       * Compute the resulting DICOM instance.
        **/
 
       std::auto_ptr<ParsedDicomFile> modified(original.Clone());
       modification.Apply(*modified);
 
+
+      /**
+       * Prepare the metadata information to associate with the
+       * resulting DICOM instance (AnonymizedFrom/ModifiedFrom).
+       **/
+
+      DicomInstanceHasher modifiedHasher = modified->GetHasher();
+      ServerIndex::MetadataMap metadata;
+
+      if (originalHasher.HashSeries() != modifiedHasher.HashSeries())
+      {
+        metadata[std::make_pair(ResourceType_Series, metadataType)] = originalHasher.HashSeries();
+      }
+
+      if (originalHasher.HashStudy() != modifiedHasher.HashStudy())
+      {
+        metadata[std::make_pair(ResourceType_Study, metadataType)] = originalHasher.HashStudy();
+      }
+
+      if (originalHasher.HashPatient() != modifiedHasher.HashPatient())
+      {
+        metadata[std::make_pair(ResourceType_Patient, metadataType)] = originalHasher.HashPatient();
+      }
+
+      assert(*it == originalHasher.HashInstance());
+      metadata[std::make_pair(ResourceType_Instance, metadataType)] = *it;
+
+
+      /**
+       * Store the resulting DICOM instance into the Orthanc store.
+       **/
+
       std::string modifiedInstance;
-      if (context.Store(modifiedInstance, *modified) != StoreStatus_Success)
+      if (context.Store(modifiedInstance, *modified, metadata) != StoreStatus_Success)
       {
         LOG(ERROR) << "Error while storing a modified instance " << *it;
         return;
       }
 
-
-      /**
-       * Record metadata information (AnonymizedFrom/ModifiedFrom).
-       **/
-
-      DicomInstanceHasher modifiedHasher = modified->GetHasher();
-
-      if (originalHasher.HashSeries() != modifiedHasher.HashSeries())
-      {
-        context.GetIndex().SetMetadata(modifiedHasher.HashSeries(), 
-                                       metadataType, originalHasher.HashSeries());
-      }
-
-      if (originalHasher.HashStudy() != modifiedHasher.HashStudy())
-      {
-        context.GetIndex().SetMetadata(modifiedHasher.HashStudy(), 
-                                       metadataType, originalHasher.HashStudy());
-      }
-
-      if (originalHasher.HashPatient() != modifiedHasher.HashPatient())
-      {
-        context.GetIndex().SetMetadata(modifiedHasher.HashPatient(), 
-                                       metadataType, originalHasher.HashPatient());
-      }
-
-      assert(*it == originalHasher.HashInstance());
+      // Sanity checks in debug mode
       assert(modifiedInstance == modifiedHasher.HashInstance());
-      context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it);
 
 
       /**