diff OrthancServer/OrthancRestApi.cpp @ 605:b82292ba2083 dicom-rt

integration mainline -> dicom-rt
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2013 14:21:50 +0200
parents e318e9d49815 d5043ff68d58
children
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi.cpp	Wed Sep 04 14:19:14 2013 +0200
+++ b/OrthancServer/OrthancRestApi.cpp	Thu Oct 17 14:21:50 2013 +0200
@@ -1133,6 +1133,7 @@
     removals.insert(DicomTag(0x0010, 0x1040));  // Patient's Address
     removals.insert(DicomTag(0x0032, 0x1032));  // Requesting Physician
     removals.insert(DicomTag(0x0010, 0x2154));  // PatientTelephoneNumbers
+    removals.insert(DicomTag(0x0010, 0x2000));  // Medical Alerts
 
     // Set the DeidentificationMethod tag
     replacements.insert(std::make_pair(DicomTag(0x0012, 0x0063), "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1"));
@@ -1185,11 +1186,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) &&
@@ -1221,6 +1224,11 @@
 
       for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++)
       {
+        if (*it == DICOM_TAG_PATIENT_ID)
+        {
+          keepPatientId = true;
+        }
+
         removals.erase(*it);
       }
 
@@ -1236,9 +1244,10 @@
       ParseReplacements(replacements, replacementsPart);
 
       // Generate random Patient's Name if none is specified
-      if (replacements.find(DicomTag(0x0010, 0x0010)) == replacements.end())
+      if (toKeep.find(DICOM_TAG_PATIENT_NAME) == toKeep.end() &&
+          replacements.find(DICOM_TAG_PATIENT_NAME) == replacements.end())
       {
-        replacements.insert(std::make_pair(DicomTag(0x0010, 0x0010), GeneratePatientName(context)));
+        replacements.insert(std::make_pair(DICOM_TAG_PATIENT_NAME, GeneratePatientName(context)));
       }
 
       return true;
@@ -1319,10 +1328,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,
@@ -1359,9 +1368,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;
       }
@@ -1471,10 +1479,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())
       {
@@ -1509,7 +1519,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);
     }
@@ -1520,11 +1530,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);
     }
@@ -1539,7 +1549,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);
     }
@@ -1550,11 +1560,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);
     }
@@ -1580,11 +1590,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);
     }