diff OrthancServer/ParsedDicomFile.cpp @ 991:2f76b92addd4

keep private tags during anonymization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Jul 2014 11:56:08 +0200
parents 2fd5a163776d
children af014624dac1 a226e0959d8b
line wrap: on
line diff
--- a/OrthancServer/ParsedDicomFile.cpp	Tue Jul 01 17:17:45 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed Jul 02 11:56:08 2014 +0200
@@ -756,24 +756,42 @@
 
 
 
-  void ParsedDicomFile::RemovePrivateTags()
+  void ParsedDicomFile::RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep)
   {
+    DcmDataset& dataset = *pimpl_->file_->getDataset();
+
+    // Loop over the dataset to detect its private tags
     typedef std::list<DcmElement*> Tags;
-
     Tags privateTags;
 
-    DcmDataset& dataset = *pimpl_->file_->getDataset();
     for (unsigned long i = 0; i < dataset.card(); i++)
     {
       DcmElement* element = dataset.getElement(i);
       DcmTag tag(element->getTag());
-      if (!strcmp("PrivateCreator", tag.getTagName()) ||  // TODO - This may change with future versions of DCMTK
-          tag.getPrivateCreator() != NULL)
+
+      // Is this a private tag?
+      if (FromDcmtkBridge::IsPrivateTag(tag))
       {
-        privateTags.push_back(element);
+        bool remove = true;
+
+        // Check whether this private tag is to be kept
+        if (toKeep != NULL)
+        {
+          DicomTag tmp = FromDcmtkBridge::Convert(tag);
+          if (toKeep->find(tmp) != toKeep->end())
+          {
+            remove = false;  // Keep it
+          }
+        }
+            
+        if (remove)
+        {
+          privateTags.push_back(element);
+        }
       }
     }
 
+    // Loop over the detected private tags to remove them
     for (Tags::iterator it = privateTags.begin(); 
          it != privateTags.end(); ++it)
     {