changeset 2194:3b40ca7470cc

"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Dec 2016 16:58:35 +0100
parents 6ac6193a7935
children c5c77ceb38c0 fd82e9e6251e af60b784d2b8
files NEWS OrthancServer/DicomModification.cpp OrthancServer/DicomModification.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp
diffstat 4 files changed, 60 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Dec 02 16:04:00 2016 +0100
+++ b/NEWS	Fri Dec 02 16:58:35 2016 +0100
@@ -17,6 +17,7 @@
 * "Asynchronous" flag for URIs "/modalities/{...}/store" and "/peers/{...}/store"
   to avoid waiting for the completion of image transfers
 * Possibility to DELETE "dicom-as-json" attachments to reconstruct the JSON summaries
+* "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
 
 Plugins
 -------
--- a/OrthancServer/DicomModification.cpp	Fri Dec 02 16:04:00 2016 +0100
+++ b/OrthancServer/DicomModification.cpp	Fri Dec 02 16:58:35 2016 +0100
@@ -144,11 +144,14 @@
     dicom.Replace(*tag, mapped, false /* don't try and decode data URI scheme for UIDs */, DicomReplaceMode_InsertIfAbsent);
   }
   
-  DicomModification::DicomModification()
+  DicomModification::DicomModification() :
+    removePrivateTags_(false),
+    level_(ResourceType_Instance),
+    allowManualIdentifiers_(true),
+    keepStudyInstanceUid_(false),
+    keepSeriesInstanceUid_(false),
+    keepSopInstanceUid_(false)
   {
-    removePrivateTags_ = false;
-    level_ = ResourceType_Instance;
-    allowManualIdentifiers_ = true;
   }
 
   DicomModification::~DicomModification()
@@ -166,6 +169,21 @@
       privateTagsToKeep_.insert(tag);
     }
 
+    if (tag == DICOM_TAG_STUDY_INSTANCE_UID)
+    {
+      keepStudyInstanceUid_ = true;
+    }
+
+    if (tag == DICOM_TAG_SERIES_INSTANCE_UID)
+    {
+      keepSeriesInstanceUid_ = true;
+    }
+
+    if (tag == DICOM_TAG_SOP_INSTANCE_UID)
+    {
+      keepSopInstanceUid_ = true;
+    }
+
     MarkNotOrthancAnonymization();
   }
 
@@ -466,19 +484,40 @@
     if (level_ <= ResourceType_Study &&
         !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
     {
-      MapDicomIdentifier(toModify, ResourceType_Study);
+      if (keepStudyInstanceUid_)
+      {
+        LOG(WARNING) << "Modifying a study while keeping its original StudyInstanceUID: This should be avoided!";
+      }
+      else
+      {
+        MapDicomIdentifier(toModify, ResourceType_Study);
+      }
     }
 
     if (level_ <= ResourceType_Series &&
         !IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
     {
-      MapDicomIdentifier(toModify, ResourceType_Series);
+      if (keepSeriesInstanceUid_)
+      {
+        LOG(WARNING) << "Modifying a series while keeping its original SeriesInstanceUID: This should be avoided!";
+      }
+      else
+      {
+        MapDicomIdentifier(toModify, ResourceType_Series);
+      }
     }
 
     if (level_ <= ResourceType_Instance &&  // Always true
         !IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
     {
-      MapDicomIdentifier(toModify, ResourceType_Instance);
+      if (keepSopInstanceUid_)
+      {
+        LOG(WARNING) << "Modifying an instance while keeping its original SOPInstanceUID: This should be avoided!";
+      }
+      else
+      {
+        MapDicomIdentifier(toModify, ResourceType_Instance);
+      }
     }
   }
 }
--- a/OrthancServer/DicomModification.h	Fri Dec 02 16:04:00 2016 +0100
+++ b/OrthancServer/DicomModification.h	Fri Dec 02 16:58:35 2016 +0100
@@ -57,6 +57,9 @@
     UidMap uidMap_;
     SetOfTags privateTagsToKeep_;
     bool allowManualIdentifiers_;
+    bool keepStudyInstanceUid_;
+    bool keepSeriesInstanceUid_;
+    bool keepSopInstanceUid_;
 
     void MapDicomIdentifier(ParsedDicomFile& dicom,
                             ResourceType level);
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Dec 02 16:04:00 2016 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Dec 02 16:58:35 2016 +0100
@@ -136,6 +136,16 @@
         ParseReplacements(target, request["Replace"]);
       }
 
+      // The "Keep" operation only makes sense for the tags
+      // StudyInstanceUID, SeriesInstanceUID and SOPInstanceUID. Avoid
+      // this feature as much as possible, as this breaks the DICOM
+      // model of the real world, except if you know exactly what
+      // you're doing!
+      if (request.isMember("Keep"))
+      {
+        ParseListOfTags(target, request["Keep"], TagOperation_Keep);
+      }
+
       return true;
     }
     else