changeset 602:d5043ff68d58

Possibility to keep the PatientID during an anonymization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 14 Oct 2013 15:57:51 +0200
parents 84011417321d
children 49945044b06d
files NEWS OrthancServer/OrthancRestApi.cpp
diffstat 2 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Oct 11 12:06:55 2013 +0200
+++ b/NEWS	Mon Oct 14 15:57:51 2013 +0200
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Possibility to keep the PatientID during an anonymization
+
 
 Version 0.6.2 (2013/10/04)
 ==========================
--- a/OrthancServer/OrthancRestApi.cpp	Fri Oct 11 12:06:55 2013 +0200
+++ b/OrthancServer/OrthancRestApi.cpp	Mon Oct 14 15:57:51 2013 +0200
@@ -1191,11 +1191,13 @@
   static bool ParseAnonymizationRequest(Removals& removals,
                                         Replacements& replacements,
                                         bool& removePrivateTags,
+                                        bool& keepPatientId,
                                         RestApi::PostCall& call)
   {
     RETRIEVE_CONTEXT(call);
 
     removePrivateTags = true;
+    keepPatientId = false;
 
     Json::Value request;
     if (call.ParseJsonRequest(request) &&
@@ -1227,6 +1229,11 @@
 
       for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++)
       {
+        if (*it == DICOM_TAG_PATIENT_ID)
+        {
+          keepPatientId = true;
+        }
+
         removals.erase(*it);
       }
 
@@ -1326,10 +1333,10 @@
   }
 
 
-  static void AnonymizeOrModifyResource(bool isAnonymization,
-                                        Removals& removals,
+  static void AnonymizeOrModifyResource(Removals& removals,
                                         Replacements& replacements,
                                         bool removePrivateTags,
+                                        bool keepPatientId,
                                         MetadataType metadataType,
                                         ChangeType changeType,
                                         ResourceType resourceType,
@@ -1366,9 +1373,8 @@
 
       DicomInstanceHasher originalHasher = original.GetHasher();
 
-      if (isFirst && !isAnonymization)
+      if (isFirst && keepPatientId)
       {
-        // If modifying a study or a series, keep the original patient ID.
         std::string patientId = originalHasher.GetPatientId();
         uidMap[std::make_pair(DicomRootLevel_Patient, patientId)] = patientId;
       }
@@ -1478,10 +1484,12 @@
   {
     Removals removals;
     Replacements replacements;
-    bool removePrivateTags;
+    bool removePrivateTags, keepPatientId;
 
-    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
+    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
     {
+      // TODO Handle "keepPatientId"
+
       // Generate random patient ID if not specified
       if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end())
       {
@@ -1516,7 +1524,7 @@
 
     if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
     {
-      AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, 
+      AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/,
                                 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries, 
                                 ResourceType_Series, call);
     }
@@ -1527,11 +1535,11 @@
   {
     Removals removals;
     Replacements replacements;
-    bool removePrivateTags;
+    bool removePrivateTags, keepPatientId;
 
-    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
+    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
     {
-      AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, 
+      AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId,
                                 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries, 
                                 ResourceType_Series, call);
     }
@@ -1546,7 +1554,7 @@
 
     if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
     {
-      AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, 
+      AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/,
                                 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy, 
                                 ResourceType_Study, call);
     }
@@ -1557,11 +1565,11 @@
   {
     Removals removals;
     Replacements replacements;
-    bool removePrivateTags;
+    bool removePrivateTags, keepPatientId;
 
-    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
+    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
     {
-      AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, 
+      AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId,
                                 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy, 
                                 ResourceType_Study, call);
     }
@@ -1587,11 +1595,11 @@
   {
     Removals removals;
     Replacements replacements;
-    bool removePrivateTags;
+    bool removePrivateTags, keepPatientId;
 
-    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
+    if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
     {
-      AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, 
+      AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId,
                                 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient, 
                                 ResourceType_Patient, call);
     }