diff OrthancServer/DicomModification.cpp @ 2310:b7fba68747f6 issue-46-anonymization

DicomModification::Clear()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2017 14:00:00 +0200
parents 4dc313b9a20a
children 78dcb3ddea9f
line wrap: on
line diff
--- a/OrthancServer/DicomModification.cpp	Wed Jul 12 13:40:02 2017 +0200
+++ b/OrthancServer/DicomModification.cpp	Wed Jul 12 14:00:00 2017 +0200
@@ -171,6 +171,7 @@
   void DicomModification::Keep(const DicomTag& tag)
   {
     removals_.erase(tag);
+    clearings_.erase(tag);
     RemoveInternal(tag);
 
     if (tag.IsPrivate())
@@ -194,6 +195,17 @@
   void DicomModification::Remove(const DicomTag& tag)
   {
     removals_.insert(tag);
+    clearings_.erase(tag);
+    RemoveInternal(tag);
+    privateTagsToKeep_.erase(tag);
+
+    MarkNotOrthancAnonymization();
+  }
+
+  void DicomModification::Clear(const DicomTag& tag)
+  {
+    removals_.erase(tag);
+    clearings_.insert(tag);
     RemoveInternal(tag);
     privateTagsToKeep_.erase(tag);
 
@@ -205,10 +217,16 @@
     return removals_.find(tag) != removals_.end();
   }
 
+  bool DicomModification::IsCleared(const DicomTag& tag) const
+  {
+    return clearings_.find(tag) != clearings_.end();
+  }
+
   void DicomModification::Replace(const DicomTag& tag,
                                   const Json::Value& value,
                                   bool safeForAnonymization)
   {
+    clearings_.erase(tag);
     removals_.erase(tag);
     privateTagsToKeep_.erase(tag);
     ReplaceInternal(tag, value);
@@ -606,6 +624,7 @@
   void DicomModification::SetupAnonymization(DicomVersion version)
   {
     removals_.clear();
+    clearings_.clear();
     ClearReplacements();
     removePrivateTags_ = true;
     level_ = ResourceType_Patient;
@@ -756,21 +775,28 @@
       toModify.RemovePrivateTags(privateTagsToKeep_);
     }
 
-    // (2) Remove the tags specified by the user
+    // (2) Clear the tags specified by the user
+    for (SetOfTags::const_iterator it = clearings_.begin(); 
+         it != clearings_.end(); ++it)
+    {
+      toModify.Clear(*it, true /* only clear if the tag exists in the original file */);
+    }
+
+    // (3) Remove the tags specified by the user
     for (SetOfTags::const_iterator it = removals_.begin(); 
          it != removals_.end(); ++it)
     {
       toModify.Remove(*it);
     }
 
-    // (3) Replace the tags
+    // (4) Replace the tags
     for (Replacements::const_iterator it = replacements_.begin(); 
          it != replacements_.end(); ++it)
     {
       toModify.Replace(it->first, *it->second, true /* decode data URI scheme */, DicomReplaceMode_InsertIfAbsent);
     }
 
-    // (4) Update the DICOM identifiers
+    // (5) Update the DICOM identifiers
     if (level_ <= ResourceType_Study &&
         !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
     {