comparison OrthancServer/OrthancRestApi.cpp @ 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 48c9f83587a8
children b82292ba2083 60d90e48e809
comparison
equal deleted inserted replaced
601:84011417321d 602:d5043ff68d58
1189 1189
1190 1190
1191 static bool ParseAnonymizationRequest(Removals& removals, 1191 static bool ParseAnonymizationRequest(Removals& removals,
1192 Replacements& replacements, 1192 Replacements& replacements,
1193 bool& removePrivateTags, 1193 bool& removePrivateTags,
1194 bool& keepPatientId,
1194 RestApi::PostCall& call) 1195 RestApi::PostCall& call)
1195 { 1196 {
1196 RETRIEVE_CONTEXT(call); 1197 RETRIEVE_CONTEXT(call);
1197 1198
1198 removePrivateTags = true; 1199 removePrivateTags = true;
1200 keepPatientId = false;
1199 1201
1200 Json::Value request; 1202 Json::Value request;
1201 if (call.ParseJsonRequest(request) && 1203 if (call.ParseJsonRequest(request) &&
1202 request.isObject()) 1204 request.isObject())
1203 { 1205 {
1225 1227
1226 SetupAnonymization(removals, replacements); 1228 SetupAnonymization(removals, replacements);
1227 1229
1228 for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++) 1230 for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++)
1229 { 1231 {
1232 if (*it == DICOM_TAG_PATIENT_ID)
1233 {
1234 keepPatientId = true;
1235 }
1236
1230 removals.erase(*it); 1237 removals.erase(*it);
1231 } 1238 }
1232 1239
1233 Removals additionalRemovals; 1240 Removals additionalRemovals;
1234 ParseRemovals(additionalRemovals, removalsPart); 1241 ParseRemovals(additionalRemovals, removalsPart);
1324 replacements[*tag] = mapped; 1331 replacements[*tag] = mapped;
1325 return isNew; 1332 return isNew;
1326 } 1333 }
1327 1334
1328 1335
1329 static void AnonymizeOrModifyResource(bool isAnonymization, 1336 static void AnonymizeOrModifyResource(Removals& removals,
1330 Removals& removals,
1331 Replacements& replacements, 1337 Replacements& replacements,
1332 bool removePrivateTags, 1338 bool removePrivateTags,
1339 bool keepPatientId,
1333 MetadataType metadataType, 1340 MetadataType metadataType,
1334 ChangeType changeType, 1341 ChangeType changeType,
1335 ResourceType resourceType, 1342 ResourceType resourceType,
1336 RestApi::PostCall& call) 1343 RestApi::PostCall& call)
1337 { 1344 {
1364 LOG(INFO) << "Modifying instance " << *it; 1371 LOG(INFO) << "Modifying instance " << *it;
1365 ParsedDicomFile& original = context.GetDicomFile(*it); 1372 ParsedDicomFile& original = context.GetDicomFile(*it);
1366 1373
1367 DicomInstanceHasher originalHasher = original.GetHasher(); 1374 DicomInstanceHasher originalHasher = original.GetHasher();
1368 1375
1369 if (isFirst && !isAnonymization) 1376 if (isFirst && keepPatientId)
1370 { 1377 {
1371 // If modifying a study or a series, keep the original patient ID.
1372 std::string patientId = originalHasher.GetPatientId(); 1378 std::string patientId = originalHasher.GetPatientId();
1373 uidMap[std::make_pair(DicomRootLevel_Patient, patientId)] = patientId; 1379 uidMap[std::make_pair(DicomRootLevel_Patient, patientId)] = patientId;
1374 } 1380 }
1375 1381
1376 bool isNewSeries = RetrieveMappedUid(original, DicomRootLevel_Series, replacements, uidMap); 1382 bool isNewSeries = RetrieveMappedUid(original, DicomRootLevel_Series, replacements, uidMap);
1476 1482
1477 static void AnonymizeInstance(RestApi::PostCall& call) 1483 static void AnonymizeInstance(RestApi::PostCall& call)
1478 { 1484 {
1479 Removals removals; 1485 Removals removals;
1480 Replacements replacements; 1486 Replacements replacements;
1481 bool removePrivateTags; 1487 bool removePrivateTags, keepPatientId;
1482 1488
1483 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) 1489 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
1484 { 1490 {
1491 // TODO Handle "keepPatientId"
1492
1485 // Generate random patient ID if not specified 1493 // Generate random patient ID if not specified
1486 if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end()) 1494 if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end())
1487 { 1495 {
1488 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID, 1496 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID,
1489 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient))); 1497 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient)));
1514 Replacements replacements; 1522 Replacements replacements;
1515 bool removePrivateTags; 1523 bool removePrivateTags;
1516 1524
1517 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) 1525 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
1518 { 1526 {
1519 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, 1527 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/,
1520 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries, 1528 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries,
1521 ResourceType_Series, call); 1529 ResourceType_Series, call);
1522 } 1530 }
1523 } 1531 }
1524 1532
1525 1533
1526 static void AnonymizeSeriesInplace(RestApi::PostCall& call) 1534 static void AnonymizeSeriesInplace(RestApi::PostCall& call)
1535 {
1536 Removals removals;
1537 Replacements replacements;
1538 bool removePrivateTags, keepPatientId;
1539
1540 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
1541 {
1542 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId,
1543 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries,
1544 ResourceType_Series, call);
1545 }
1546 }
1547
1548
1549 static void ModifyStudyInplace(RestApi::PostCall& call)
1527 { 1550 {
1528 Removals removals; 1551 Removals removals;
1529 Replacements replacements; 1552 Replacements replacements;
1530 bool removePrivateTags; 1553 bool removePrivateTags;
1531 1554
1532 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) 1555 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
1533 { 1556 {
1534 AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, 1557 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/,
1535 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries, 1558 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy,
1536 ResourceType_Series, call); 1559 ResourceType_Study, call);
1537 } 1560 }
1538 } 1561 }
1539 1562
1540 1563
1541 static void ModifyStudyInplace(RestApi::PostCall& call) 1564 static void AnonymizeStudyInplace(RestApi::PostCall& call)
1565 {
1566 Removals removals;
1567 Replacements replacements;
1568 bool removePrivateTags, keepPatientId;
1569
1570 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
1571 {
1572 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId,
1573 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy,
1574 ResourceType_Study, call);
1575 }
1576 }
1577
1578
1579 /*static void ModifyPatientInplace(RestApi::PostCall& call)
1542 { 1580 {
1543 Removals removals; 1581 Removals removals;
1544 Replacements replacements; 1582 Replacements replacements;
1545 bool removePrivateTags; 1583 bool removePrivateTags;
1546 1584
1547 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) 1585 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
1548 { 1586 {
1549 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, 1587 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags,
1550 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy, 1588 MetadataType_ModifiedFrom, ChangeType_ModifiedPatient,
1551 ResourceType_Study, call); 1589 ResourceType_Patient, call);
1552 } 1590 }
1553 } 1591 }*/
1554 1592
1555 1593
1556 static void AnonymizeStudyInplace(RestApi::PostCall& call) 1594 static void AnonymizePatientInplace(RestApi::PostCall& call)
1557 { 1595 {
1558 Removals removals; 1596 Removals removals;
1559 Replacements replacements; 1597 Replacements replacements;
1560 bool removePrivateTags; 1598 bool removePrivateTags, keepPatientId;
1561 1599
1562 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) 1600 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call))
1563 { 1601 {
1564 AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, 1602 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId,
1565 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy,
1566 ResourceType_Study, call);
1567 }
1568 }
1569
1570
1571 /*static void ModifyPatientInplace(RestApi::PostCall& call)
1572 {
1573 Removals removals;
1574 Replacements replacements;
1575 bool removePrivateTags;
1576
1577 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
1578 {
1579 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags,
1580 MetadataType_ModifiedFrom, ChangeType_ModifiedPatient,
1581 ResourceType_Patient, call);
1582 }
1583 }*/
1584
1585
1586 static void AnonymizePatientInplace(RestApi::PostCall& call)
1587 {
1588 Removals removals;
1589 Replacements replacements;
1590 bool removePrivateTags;
1591
1592 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
1593 {
1594 AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags,
1595 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient, 1603 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient,
1596 ResourceType_Patient, call); 1604 ResourceType_Patient, call);
1597 } 1605 }
1598 } 1606 }
1599 1607