# HG changeset patch # User Sebastien Jodogne # Date 1381759071 -7200 # Node ID d5043ff68d582959b41974773a9796074e078076 # Parent 84011417321d2c18b3c72343102d046e00c9cb68 Possibility to keep the PatientID during an anonymization diff -r 84011417321d -r d5043ff68d58 NEWS --- 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) ========================== diff -r 84011417321d -r d5043ff68d58 OrthancServer/OrthancRestApi.cpp --- 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); }