comparison OrthancFramework/Sources/DicomParsing/DicomModification.cpp @ 5087:df4a90a65af9

DicomModification::SetAllowManualIdentifiers() has been removed since it was always true -> code cleanup
author Alain Mazy <am@osimis.io>
date Mon, 26 Sep 2022 18:56:40 +0200
parents 0b27bbd19b1f
children 8638522eeda1
comparison
equal deleted inserted replaced
5086:0b27bbd19b1f 5087:df4a90a65af9
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),
526 keepStudyInstanceUid_(false), 525 keepStudyInstanceUid_(false),
527 keepSeriesInstanceUid_(false), 526 keepSeriesInstanceUid_(false),
528 keepSopInstanceUid_(false), 527 keepSopInstanceUid_(false),
529 updateReferencedRelationships_(true), 528 updateReferencedRelationships_(true),
530 isAnonymization_(false), 529 isAnonymization_(false),
920 { 919 {
921 throw OrthancException(ErrorCode_BadRequest); 920 throw OrthancException(ErrorCode_BadRequest);
922 } 921 }
923 922
924 923
925 // Sanity checks at the patient level
926 bool isReplacedPatientId = (IsReplaced(DICOM_TAG_PATIENT_ID) ||
927 uids_.find(DICOM_TAG_PATIENT_ID) != uids_.end());
928
929 if (!allowManualIdentifiers_)
930 {
931 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
932 {
933 throw OrthancException(ErrorCode_BadRequest,
934 "When modifying a patient, the StudyInstanceUID cannot be manually modified");
935 }
936
937 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
938 {
939 throw OrthancException(ErrorCode_BadRequest,
940 "When modifying a patient, the SeriesInstanceUID cannot be manually modified");
941 }
942
943 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
944 {
945 throw OrthancException(ErrorCode_BadRequest,
946 "When modifying a patient, the SopInstanceUID cannot be manually modified");
947 }
948 }
949
950
951 // Sanity checks at the study level
952 if (!allowManualIdentifiers_)
953 {
954 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
955 {
956 throw OrthancException(ErrorCode_BadRequest,
957 "When modifying a study, the SeriesInstanceUID cannot be manually modified");
958 }
959
960 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
961 {
962 throw OrthancException(ErrorCode_BadRequest,
963 "When modifying a study, the SopInstanceUID cannot be manually modified");
964 }
965 }
966
967
968 // Sanity checks at the series level
969 if (!allowManualIdentifiers_)
970 {
971 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
972 {
973 throw OrthancException(ErrorCode_BadRequest,
974 "When modifying a series, the SopInstanceUID cannot be manually modified");
975 }
976 }
977 924
978 // (0) Create a summary of the source file, if a custom generator 925 // (0) Create a summary of the source file, if a custom generator
979 // is provided 926 // is provided
980 if (identifierGenerator_ != NULL) 927 if (identifierGenerator_ != NULL)
981 { 928 {
1111 assert((*it)->GetPath().GetPrefixLength() > 0); 1058 assert((*it)->GetPath().GetPrefixLength() > 0);
1112 toModify.ReplacePath((*it)->GetPath(), (*it)->GetValue(), true /* decode data URI scheme */, 1059 toModify.ReplacePath((*it)->GetPath(), (*it)->GetValue(), true /* decode data URI scheme */,
1113 DicomReplaceMode_InsertIfAbsent, privateCreator_); 1060 DicomReplaceMode_InsertIfAbsent, privateCreator_);
1114 } 1061 }
1115 } 1062 }
1116
1117 void DicomModification::SetAllowManualIdentifiers(bool check)
1118 {
1119 allowManualIdentifiers_ = check;
1120 }
1121
1122 bool DicomModification::AreAllowManualIdentifiers() const
1123 {
1124 return allowManualIdentifiers_;
1125 }
1126
1127 1063
1128 static bool IsDatabaseKey(const DicomTag& tag) 1064 static bool IsDatabaseKey(const DicomTag& tag)
1129 { 1065 {
1130 return (tag == DICOM_TAG_PATIENT_ID || 1066 return (tag == DICOM_TAG_PATIENT_ID ||
1131 tag == DICOM_TAG_STUDY_INSTANCE_UID || 1067 tag == DICOM_TAG_STUDY_INSTANCE_UID ||
1344 1280
1345 1281
1346 1282
1347 static const char* REMOVE_PRIVATE_TAGS = "RemovePrivateTags"; 1283 static const char* REMOVE_PRIVATE_TAGS = "RemovePrivateTags";
1348 static const char* LEVEL = "Level"; 1284 static const char* LEVEL = "Level";
1349 static const char* ALLOW_MANUAL_IDENTIFIERS = "AllowManualIdentifiers";
1350 static const char* KEEP_STUDY_INSTANCE_UID = "KeepStudyInstanceUID"; 1285 static const char* KEEP_STUDY_INSTANCE_UID = "KeepStudyInstanceUID";
1351 static const char* KEEP_SERIES_INSTANCE_UID = "KeepSeriesInstanceUID"; 1286 static const char* KEEP_SERIES_INSTANCE_UID = "KeepSeriesInstanceUID";
1352 static const char* KEEP_SOP_INSTANCE_UID = "KeepSOPInstanceUID"; 1287 static const char* KEEP_SOP_INSTANCE_UID = "KeepSOPInstanceUID";
1353 static const char* UPDATE_REFERENCED_RELATIONSHIPS = "UpdateReferencedRelationships"; 1288 static const char* UPDATE_REFERENCED_RELATIONSHIPS = "UpdateReferencedRelationships";
1354 static const char* IS_ANONYMIZATION = "IsAnonymization"; 1289 static const char* IS_ANONYMIZATION = "IsAnonymization";
1376 } 1311 }
1377 1312
1378 value = Json::objectValue; 1313 value = Json::objectValue;
1379 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_; 1314 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_;
1380 value[LEVEL] = EnumerationToString(level_); 1315 value[LEVEL] = EnumerationToString(level_);
1381 value[ALLOW_MANUAL_IDENTIFIERS] = allowManualIdentifiers_;
1382 value[KEEP_STUDY_INSTANCE_UID] = keepStudyInstanceUid_; 1316 value[KEEP_STUDY_INSTANCE_UID] = keepStudyInstanceUid_;
1383 value[KEEP_SERIES_INSTANCE_UID] = keepSeriesInstanceUid_; 1317 value[KEEP_SERIES_INSTANCE_UID] = keepSeriesInstanceUid_;
1384 value[KEEP_SOP_INSTANCE_UID] = keepSopInstanceUid_; 1318 value[KEEP_SOP_INSTANCE_UID] = keepSopInstanceUid_;
1385 value[UPDATE_REFERENCED_RELATIONSHIPS] = updateReferencedRelationships_; 1319 value[UPDATE_REFERENCED_RELATIONSHIPS] = updateReferencedRelationships_;
1386 value[IS_ANONYMIZATION] = isAnonymization_; 1320 value[IS_ANONYMIZATION] = isAnonymization_;
1521 DicomModification::DicomModification(const Json::Value& serialized) : 1455 DicomModification::DicomModification(const Json::Value& serialized) :
1522 identifierGenerator_(NULL) 1456 identifierGenerator_(NULL)
1523 { 1457 {
1524 removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS); 1458 removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS);
1525 level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str()); 1459 level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str());
1526 allowManualIdentifiers_ = SerializationToolbox::ReadBoolean(serialized, ALLOW_MANUAL_IDENTIFIERS);
1527 keepStudyInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_STUDY_INSTANCE_UID); 1460 keepStudyInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_STUDY_INSTANCE_UID);
1528 keepSeriesInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SERIES_INSTANCE_UID); 1461 keepSeriesInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SERIES_INSTANCE_UID);
1529 updateReferencedRelationships_ = SerializationToolbox::ReadBoolean 1462 updateReferencedRelationships_ = SerializationToolbox::ReadBoolean
1530 (serialized, UPDATE_REFERENCED_RELATIONSHIPS); 1463 (serialized, UPDATE_REFERENCED_RELATIONSHIPS);
1531 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); 1464 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION);