Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
544:a482948c1fd6 | 605:b82292ba2083 |
---|---|
1131 | 1131 |
1132 // Some more removals (from the experience of DICOM files at the CHU of Liege) | 1132 // Some more removals (from the experience of DICOM files at the CHU of Liege) |
1133 removals.insert(DicomTag(0x0010, 0x1040)); // Patient's Address | 1133 removals.insert(DicomTag(0x0010, 0x1040)); // Patient's Address |
1134 removals.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician | 1134 removals.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician |
1135 removals.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers | 1135 removals.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers |
1136 removals.insert(DicomTag(0x0010, 0x2000)); // Medical Alerts | |
1136 | 1137 |
1137 // Set the DeidentificationMethod tag | 1138 // Set the DeidentificationMethod tag |
1138 replacements.insert(std::make_pair(DicomTag(0x0012, 0x0063), "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1")); | 1139 replacements.insert(std::make_pair(DicomTag(0x0012, 0x0063), "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1")); |
1139 | 1140 |
1140 // Set the PatientIdentityRemoved tag | 1141 // Set the PatientIdentityRemoved tag |
1183 | 1184 |
1184 | 1185 |
1185 static bool ParseAnonymizationRequest(Removals& removals, | 1186 static bool ParseAnonymizationRequest(Removals& removals, |
1186 Replacements& replacements, | 1187 Replacements& replacements, |
1187 bool& removePrivateTags, | 1188 bool& removePrivateTags, |
1189 bool& keepPatientId, | |
1188 RestApi::PostCall& call) | 1190 RestApi::PostCall& call) |
1189 { | 1191 { |
1190 RETRIEVE_CONTEXT(call); | 1192 RETRIEVE_CONTEXT(call); |
1191 | 1193 |
1192 removePrivateTags = true; | 1194 removePrivateTags = true; |
1195 keepPatientId = false; | |
1193 | 1196 |
1194 Json::Value request; | 1197 Json::Value request; |
1195 if (call.ParseJsonRequest(request) && | 1198 if (call.ParseJsonRequest(request) && |
1196 request.isObject()) | 1199 request.isObject()) |
1197 { | 1200 { |
1219 | 1222 |
1220 SetupAnonymization(removals, replacements); | 1223 SetupAnonymization(removals, replacements); |
1221 | 1224 |
1222 for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++) | 1225 for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++) |
1223 { | 1226 { |
1227 if (*it == DICOM_TAG_PATIENT_ID) | |
1228 { | |
1229 keepPatientId = true; | |
1230 } | |
1231 | |
1224 removals.erase(*it); | 1232 removals.erase(*it); |
1225 } | 1233 } |
1226 | 1234 |
1227 Removals additionalRemovals; | 1235 Removals additionalRemovals; |
1228 ParseRemovals(additionalRemovals, removalsPart); | 1236 ParseRemovals(additionalRemovals, removalsPart); |
1234 } | 1242 } |
1235 | 1243 |
1236 ParseReplacements(replacements, replacementsPart); | 1244 ParseReplacements(replacements, replacementsPart); |
1237 | 1245 |
1238 // Generate random Patient's Name if none is specified | 1246 // Generate random Patient's Name if none is specified |
1239 if (replacements.find(DicomTag(0x0010, 0x0010)) == replacements.end()) | 1247 if (toKeep.find(DICOM_TAG_PATIENT_NAME) == toKeep.end() && |
1240 { | 1248 replacements.find(DICOM_TAG_PATIENT_NAME) == replacements.end()) |
1241 replacements.insert(std::make_pair(DicomTag(0x0010, 0x0010), GeneratePatientName(context))); | 1249 { |
1250 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_NAME, GeneratePatientName(context))); | |
1242 } | 1251 } |
1243 | 1252 |
1244 return true; | 1253 return true; |
1245 } | 1254 } |
1246 else | 1255 else |
1317 replacements[*tag] = mapped; | 1326 replacements[*tag] = mapped; |
1318 return isNew; | 1327 return isNew; |
1319 } | 1328 } |
1320 | 1329 |
1321 | 1330 |
1322 static void AnonymizeOrModifyResource(bool isAnonymization, | 1331 static void AnonymizeOrModifyResource(Removals& removals, |
1323 Removals& removals, | |
1324 Replacements& replacements, | 1332 Replacements& replacements, |
1325 bool removePrivateTags, | 1333 bool removePrivateTags, |
1334 bool keepPatientId, | |
1326 MetadataType metadataType, | 1335 MetadataType metadataType, |
1327 ChangeType changeType, | 1336 ChangeType changeType, |
1328 ResourceType resourceType, | 1337 ResourceType resourceType, |
1329 RestApi::PostCall& call) | 1338 RestApi::PostCall& call) |
1330 { | 1339 { |
1357 LOG(INFO) << "Modifying instance " << *it; | 1366 LOG(INFO) << "Modifying instance " << *it; |
1358 ParsedDicomFile& original = context.GetDicomFile(*it); | 1367 ParsedDicomFile& original = context.GetDicomFile(*it); |
1359 | 1368 |
1360 DicomInstanceHasher originalHasher = original.GetHasher(); | 1369 DicomInstanceHasher originalHasher = original.GetHasher(); |
1361 | 1370 |
1362 if (isFirst && !isAnonymization) | 1371 if (isFirst && keepPatientId) |
1363 { | 1372 { |
1364 // If modifying a study or a series, keep the original patient ID. | |
1365 std::string patientId = originalHasher.GetPatientId(); | 1373 std::string patientId = originalHasher.GetPatientId(); |
1366 uidMap[std::make_pair(DicomRootLevel_Patient, patientId)] = patientId; | 1374 uidMap[std::make_pair(DicomRootLevel_Patient, patientId)] = patientId; |
1367 } | 1375 } |
1368 | 1376 |
1369 bool isNewSeries = RetrieveMappedUid(original, DicomRootLevel_Series, replacements, uidMap); | 1377 bool isNewSeries = RetrieveMappedUid(original, DicomRootLevel_Series, replacements, uidMap); |
1469 | 1477 |
1470 static void AnonymizeInstance(RestApi::PostCall& call) | 1478 static void AnonymizeInstance(RestApi::PostCall& call) |
1471 { | 1479 { |
1472 Removals removals; | 1480 Removals removals; |
1473 Replacements replacements; | 1481 Replacements replacements; |
1474 bool removePrivateTags; | 1482 bool removePrivateTags, keepPatientId; |
1475 | 1483 |
1476 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) | 1484 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) |
1477 { | 1485 { |
1486 // TODO Handle "keepPatientId" | |
1487 | |
1478 // Generate random patient ID if not specified | 1488 // Generate random patient ID if not specified |
1479 if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end()) | 1489 if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end()) |
1480 { | 1490 { |
1481 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID, | 1491 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID, |
1482 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient))); | 1492 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient))); |
1507 Replacements replacements; | 1517 Replacements replacements; |
1508 bool removePrivateTags; | 1518 bool removePrivateTags; |
1509 | 1519 |
1510 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) | 1520 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) |
1511 { | 1521 { |
1512 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, | 1522 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/, |
1513 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries, | 1523 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries, |
1514 ResourceType_Series, call); | 1524 ResourceType_Series, call); |
1515 } | 1525 } |
1516 } | 1526 } |
1517 | 1527 |
1518 | 1528 |
1519 static void AnonymizeSeriesInplace(RestApi::PostCall& call) | 1529 static void AnonymizeSeriesInplace(RestApi::PostCall& call) |
1530 { | |
1531 Removals removals; | |
1532 Replacements replacements; | |
1533 bool removePrivateTags, keepPatientId; | |
1534 | |
1535 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) | |
1536 { | |
1537 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId, | |
1538 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries, | |
1539 ResourceType_Series, call); | |
1540 } | |
1541 } | |
1542 | |
1543 | |
1544 static void ModifyStudyInplace(RestApi::PostCall& call) | |
1520 { | 1545 { |
1521 Removals removals; | 1546 Removals removals; |
1522 Replacements replacements; | 1547 Replacements replacements; |
1523 bool removePrivateTags; | 1548 bool removePrivateTags; |
1524 | 1549 |
1525 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) | 1550 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) |
1526 { | 1551 { |
1527 AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, | 1552 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/, |
1528 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries, | 1553 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy, |
1529 ResourceType_Series, call); | 1554 ResourceType_Study, call); |
1530 } | 1555 } |
1531 } | 1556 } |
1532 | 1557 |
1533 | 1558 |
1534 static void ModifyStudyInplace(RestApi::PostCall& call) | 1559 static void AnonymizeStudyInplace(RestApi::PostCall& call) |
1560 { | |
1561 Removals removals; | |
1562 Replacements replacements; | |
1563 bool removePrivateTags, keepPatientId; | |
1564 | |
1565 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) | |
1566 { | |
1567 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId, | |
1568 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy, | |
1569 ResourceType_Study, call); | |
1570 } | |
1571 } | |
1572 | |
1573 | |
1574 /*static void ModifyPatientInplace(RestApi::PostCall& call) | |
1535 { | 1575 { |
1536 Removals removals; | 1576 Removals removals; |
1537 Replacements replacements; | 1577 Replacements replacements; |
1538 bool removePrivateTags; | 1578 bool removePrivateTags; |
1539 | 1579 |
1540 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) | 1580 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) |
1541 { | 1581 { |
1542 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, | 1582 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, |
1543 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy, | 1583 MetadataType_ModifiedFrom, ChangeType_ModifiedPatient, |
1544 ResourceType_Study, call); | 1584 ResourceType_Patient, call); |
1545 } | 1585 } |
1546 } | 1586 }*/ |
1547 | 1587 |
1548 | 1588 |
1549 static void AnonymizeStudyInplace(RestApi::PostCall& call) | 1589 static void AnonymizePatientInplace(RestApi::PostCall& call) |
1550 { | 1590 { |
1551 Removals removals; | 1591 Removals removals; |
1552 Replacements replacements; | 1592 Replacements replacements; |
1553 bool removePrivateTags; | 1593 bool removePrivateTags, keepPatientId; |
1554 | 1594 |
1555 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) | 1595 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) |
1556 { | 1596 { |
1557 AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, | 1597 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId, |
1558 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy, | |
1559 ResourceType_Study, call); | |
1560 } | |
1561 } | |
1562 | |
1563 | |
1564 /*static void ModifyPatientInplace(RestApi::PostCall& call) | |
1565 { | |
1566 Removals removals; | |
1567 Replacements replacements; | |
1568 bool removePrivateTags; | |
1569 | |
1570 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) | |
1571 { | |
1572 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, | |
1573 MetadataType_ModifiedFrom, ChangeType_ModifiedPatient, | |
1574 ResourceType_Patient, call); | |
1575 } | |
1576 }*/ | |
1577 | |
1578 | |
1579 static void AnonymizePatientInplace(RestApi::PostCall& call) | |
1580 { | |
1581 Removals removals; | |
1582 Replacements replacements; | |
1583 bool removePrivateTags; | |
1584 | |
1585 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) | |
1586 { | |
1587 AnonymizeOrModifyResource(true, removals, replacements, removePrivateTags, | |
1588 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient, | 1598 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient, |
1589 ResourceType_Patient, call); | 1599 ResourceType_Patient, call); |
1590 } | 1600 } |
1591 } | 1601 } |
1592 | 1602 |