comparison OrthancFramework/Sources/DicomParsing/DicomModification.cpp @ 5122:8638522eeda1

revert changeset df4a90a65af9 that removes features used elsewhere, and protect by Force the change of UIDs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Dec 2022 15:46:33 +0100
parents df4a90a65af9
children f2dcdbe05884
comparison
equal deleted inserted replaced
5121:77e20ce39d6f 5122:8638522eeda1
520 520
521 521
522 DicomModification::DicomModification() : 522 DicomModification::DicomModification() :
523 removePrivateTags_(false), 523 removePrivateTags_(false),
524 level_(ResourceType_Instance), 524 level_(ResourceType_Instance),
525 allowManualIdentifiers_(true),
525 keepStudyInstanceUid_(false), 526 keepStudyInstanceUid_(false),
526 keepSeriesInstanceUid_(false), 527 keepSeriesInstanceUid_(false),
527 keepSopInstanceUid_(false), 528 keepSopInstanceUid_(false),
528 updateReferencedRelationships_(true), 529 updateReferencedRelationships_(true),
529 isAnonymization_(false), 530 isAnonymization_(false),
919 { 920 {
920 throw OrthancException(ErrorCode_BadRequest); 921 throw OrthancException(ErrorCode_BadRequest);
921 } 922 }
922 923
923 924
925 // Sanity checks at the patient level
926 if (!allowManualIdentifiers_)
927 {
928 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
929 {
930 throw OrthancException(ErrorCode_BadRequest,
931 "When modifying a patient, the StudyInstanceUID cannot be manually modified");
932 }
933
934 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
935 {
936 throw OrthancException(ErrorCode_BadRequest,
937 "When modifying a patient, the SeriesInstanceUID cannot be manually modified");
938 }
939
940 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
941 {
942 throw OrthancException(ErrorCode_BadRequest,
943 "When modifying a patient, the SopInstanceUID cannot be manually modified");
944 }
945 }
946
947
948 // Sanity checks at the study level
949 if (!allowManualIdentifiers_)
950 {
951 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
952 {
953 throw OrthancException(ErrorCode_BadRequest,
954 "When modifying a study, the SeriesInstanceUID cannot be manually modified");
955 }
956
957 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
958 {
959 throw OrthancException(ErrorCode_BadRequest,
960 "When modifying a study, the SopInstanceUID cannot be manually modified");
961 }
962 }
963
964
965 // Sanity checks at the series level
966 if (!allowManualIdentifiers_)
967 {
968 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
969 {
970 throw OrthancException(ErrorCode_BadRequest,
971 "When modifying a series, the SopInstanceUID cannot be manually modified");
972 }
973 }
974
924 975
925 // (0) Create a summary of the source file, if a custom generator 976 // (0) Create a summary of the source file, if a custom generator
926 // is provided 977 // is provided
927 if (identifierGenerator_ != NULL) 978 if (identifierGenerator_ != NULL)
928 { 979 {
1058 assert((*it)->GetPath().GetPrefixLength() > 0); 1109 assert((*it)->GetPath().GetPrefixLength() > 0);
1059 toModify.ReplacePath((*it)->GetPath(), (*it)->GetValue(), true /* decode data URI scheme */, 1110 toModify.ReplacePath((*it)->GetPath(), (*it)->GetValue(), true /* decode data URI scheme */,
1060 DicomReplaceMode_InsertIfAbsent, privateCreator_); 1111 DicomReplaceMode_InsertIfAbsent, privateCreator_);
1061 } 1112 }
1062 } 1113 }
1114
1115 void DicomModification::SetAllowManualIdentifiers(bool check)
1116 {
1117 allowManualIdentifiers_ = check;
1118 }
1119
1120 bool DicomModification::AreAllowManualIdentifiers() const
1121 {
1122 return allowManualIdentifiers_;
1123 }
1124
1063 1125
1064 static bool IsDatabaseKey(const DicomTag& tag) 1126 static bool IsDatabaseKey(const DicomTag& tag)
1065 { 1127 {
1066 return (tag == DICOM_TAG_PATIENT_ID || 1128 return (tag == DICOM_TAG_PATIENT_ID ||
1067 tag == DICOM_TAG_STUDY_INSTANCE_UID || 1129 tag == DICOM_TAG_STUDY_INSTANCE_UID ||
1211 // New in Orthanc 1.6.0 1273 // New in Orthanc 1.6.0
1212 if (request.isMember("PrivateCreator")) 1274 if (request.isMember("PrivateCreator"))
1213 { 1275 {
1214 privateCreator_ = SerializationToolbox::ReadString(request, "PrivateCreator"); 1276 privateCreator_ = SerializationToolbox::ReadString(request, "PrivateCreator");
1215 } 1277 }
1278
1279 if (!force)
1280 {
1281 /**
1282 * Sanity checks about the manual replacement of DICOM
1283 * identifiers. Those checks were part of
1284 * "DicomModification::Apply()" in Orthanc <= 1.11.2, and
1285 * couldn't be disabled even if using the "Force" flag. Check
1286 * out:
1287 * https://groups.google.com/g/orthanc-users/c/xMUUZAnBa5g/m/WCEu-U2NBQAJ
1288 **/
1289 bool isReplacedPatientId = (IsReplaced(DICOM_TAG_PATIENT_ID) ||
1290 uids_.find(DICOM_TAG_PATIENT_ID) != uids_.end());
1291
1292 if (level_ == ResourceType_Patient && !isReplacedPatientId)
1293 {
1294 throw OrthancException(ErrorCode_BadRequest,
1295 "When modifying a patient, her PatientID is required to be modified.");
1296 }
1297
1298 if (level_ == ResourceType_Study && isReplacedPatientId)
1299 {
1300 throw OrthancException(ErrorCode_BadRequest,
1301 "When modifying a study, the parent PatientID cannot be manually modified");
1302 }
1303
1304 if (level_ == ResourceType_Series && isReplacedPatientId)
1305 {
1306 throw OrthancException(ErrorCode_BadRequest,
1307 "When modifying a series, the parent PatientID cannot be manually modified");
1308 }
1309
1310 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
1311 {
1312 throw OrthancException(ErrorCode_BadRequest,
1313 "When modifying a series, the parent StudyInstanceUID cannot be manually modified");
1314 }
1315
1316 if (level_ == ResourceType_Instance && isReplacedPatientId)
1317 {
1318 throw OrthancException(ErrorCode_BadRequest,
1319 "When modifying an instance, the parent PatientID cannot be manually modified");
1320 }
1321
1322 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
1323 {
1324 throw OrthancException(ErrorCode_BadRequest,
1325 "When modifying an instance, the parent StudyInstanceUID cannot be manually modified");
1326 }
1327
1328 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
1329 {
1330 throw OrthancException(ErrorCode_BadRequest,
1331 "When modifying an instance, the parent SeriesInstanceUID cannot be manually modified");
1332 }
1333 }
1216 } 1334 }
1217 1335
1218 1336
1219 void DicomModification::ParseAnonymizationRequest(bool& patientNameOverridden, 1337 void DicomModification::ParseAnonymizationRequest(bool& patientNameOverridden,
1220 const Json::Value& request) 1338 const Json::Value& request)
1280 1398
1281 1399
1282 1400
1283 static const char* REMOVE_PRIVATE_TAGS = "RemovePrivateTags"; 1401 static const char* REMOVE_PRIVATE_TAGS = "RemovePrivateTags";
1284 static const char* LEVEL = "Level"; 1402 static const char* LEVEL = "Level";
1403 static const char* ALLOW_MANUAL_IDENTIFIERS = "AllowManualIdentifiers";
1285 static const char* KEEP_STUDY_INSTANCE_UID = "KeepStudyInstanceUID"; 1404 static const char* KEEP_STUDY_INSTANCE_UID = "KeepStudyInstanceUID";
1286 static const char* KEEP_SERIES_INSTANCE_UID = "KeepSeriesInstanceUID"; 1405 static const char* KEEP_SERIES_INSTANCE_UID = "KeepSeriesInstanceUID";
1287 static const char* KEEP_SOP_INSTANCE_UID = "KeepSOPInstanceUID"; 1406 static const char* KEEP_SOP_INSTANCE_UID = "KeepSOPInstanceUID";
1288 static const char* UPDATE_REFERENCED_RELATIONSHIPS = "UpdateReferencedRelationships"; 1407 static const char* UPDATE_REFERENCED_RELATIONSHIPS = "UpdateReferencedRelationships";
1289 static const char* IS_ANONYMIZATION = "IsAnonymization"; 1408 static const char* IS_ANONYMIZATION = "IsAnonymization";
1311 } 1430 }
1312 1431
1313 value = Json::objectValue; 1432 value = Json::objectValue;
1314 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_; 1433 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_;
1315 value[LEVEL] = EnumerationToString(level_); 1434 value[LEVEL] = EnumerationToString(level_);
1435 value[ALLOW_MANUAL_IDENTIFIERS] = allowManualIdentifiers_;
1316 value[KEEP_STUDY_INSTANCE_UID] = keepStudyInstanceUid_; 1436 value[KEEP_STUDY_INSTANCE_UID] = keepStudyInstanceUid_;
1317 value[KEEP_SERIES_INSTANCE_UID] = keepSeriesInstanceUid_; 1437 value[KEEP_SERIES_INSTANCE_UID] = keepSeriesInstanceUid_;
1318 value[KEEP_SOP_INSTANCE_UID] = keepSopInstanceUid_; 1438 value[KEEP_SOP_INSTANCE_UID] = keepSopInstanceUid_;
1319 value[UPDATE_REFERENCED_RELATIONSHIPS] = updateReferencedRelationships_; 1439 value[UPDATE_REFERENCED_RELATIONSHIPS] = updateReferencedRelationships_;
1320 value[IS_ANONYMIZATION] = isAnonymization_; 1440 value[IS_ANONYMIZATION] = isAnonymization_;
1455 DicomModification::DicomModification(const Json::Value& serialized) : 1575 DicomModification::DicomModification(const Json::Value& serialized) :
1456 identifierGenerator_(NULL) 1576 identifierGenerator_(NULL)
1457 { 1577 {
1458 removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS); 1578 removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS);
1459 level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str()); 1579 level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str());
1580 allowManualIdentifiers_ = SerializationToolbox::ReadBoolean(serialized, ALLOW_MANUAL_IDENTIFIERS);
1460 keepStudyInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_STUDY_INSTANCE_UID); 1581 keepStudyInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_STUDY_INSTANCE_UID);
1461 keepSeriesInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SERIES_INSTANCE_UID); 1582 keepSeriesInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SERIES_INSTANCE_UID);
1462 updateReferencedRelationships_ = SerializationToolbox::ReadBoolean 1583 updateReferencedRelationships_ = SerializationToolbox::ReadBoolean
1463 (serialized, UPDATE_REFERENCED_RELATIONSHIPS); 1584 (serialized, UPDATE_REFERENCED_RELATIONSHIPS);
1464 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); 1585 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION);