Mercurial > hg > orthanc
comparison Core/DicomParsing/DicomModification.cpp @ 2954:d924f9bb61cc
taking advantage of details in OrthancException
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Dec 2018 14:35:34 +0100 |
parents | 99863d6245b2 |
children | 4e43e67f8ecf |
comparison
equal
deleted
inserted
replaced
2953:210d5afd8f2b | 2954:d924f9bb61cc |
---|---|
254 } | 254 } |
255 else | 255 else |
256 { | 256 { |
257 if (!identifierGenerator_->Apply(mapped, original, level, currentSource_)) | 257 if (!identifierGenerator_->Apply(mapped, original, level, currentSource_)) |
258 { | 258 { |
259 LOG(ERROR) << "Unable to generate an anonymized ID"; | 259 throw OrthancException(ErrorCode_InternalError, |
260 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 260 "Unable to generate an anonymized ID"); |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped)); | 264 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped)); |
265 } | 265 } |
871 | 871 |
872 | 872 |
873 // Sanity checks at the patient level | 873 // Sanity checks at the patient level |
874 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) | 874 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) |
875 { | 875 { |
876 LOG(ERROR) << "When modifying a patient, her PatientID is required to be modified"; | 876 throw OrthancException(ErrorCode_BadRequest, |
877 throw OrthancException(ErrorCode_BadRequest); | 877 "When modifying a patient, her PatientID is required to be modified"); |
878 } | 878 } |
879 | 879 |
880 if (!allowManualIdentifiers_) | 880 if (!allowManualIdentifiers_) |
881 { | 881 { |
882 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) | 882 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
883 { | 883 { |
884 LOG(ERROR) << "When modifying a patient, the StudyInstanceUID cannot be manually modified"; | 884 throw OrthancException(ErrorCode_BadRequest, |
885 throw OrthancException(ErrorCode_BadRequest); | 885 "When modifying a patient, the StudyInstanceUID cannot be manually modified"); |
886 } | 886 } |
887 | 887 |
888 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) | 888 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
889 { | 889 { |
890 LOG(ERROR) << "When modifying a patient, the SeriesInstanceUID cannot be manually modified"; | 890 throw OrthancException(ErrorCode_BadRequest, |
891 throw OrthancException(ErrorCode_BadRequest); | 891 "When modifying a patient, the SeriesInstanceUID cannot be manually modified"); |
892 } | 892 } |
893 | 893 |
894 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) | 894 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
895 { | 895 { |
896 LOG(ERROR) << "When modifying a patient, the SopInstanceUID cannot be manually modified"; | 896 throw OrthancException(ErrorCode_BadRequest, |
897 throw OrthancException(ErrorCode_BadRequest); | 897 "When modifying a patient, the SopInstanceUID cannot be manually modified"); |
898 } | 898 } |
899 } | 899 } |
900 | 900 |
901 | 901 |
902 // Sanity checks at the study level | 902 // Sanity checks at the study level |
903 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID)) | 903 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID)) |
904 { | 904 { |
905 LOG(ERROR) << "When modifying a study, the parent PatientID cannot be manually modified"; | 905 throw OrthancException(ErrorCode_BadRequest, |
906 throw OrthancException(ErrorCode_BadRequest); | 906 "When modifying a study, the parent PatientID cannot be manually modified"); |
907 } | 907 } |
908 | 908 |
909 if (!allowManualIdentifiers_) | 909 if (!allowManualIdentifiers_) |
910 { | 910 { |
911 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) | 911 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
912 { | 912 { |
913 LOG(ERROR) << "When modifying a study, the SeriesInstanceUID cannot be manually modified"; | 913 throw OrthancException(ErrorCode_BadRequest, |
914 throw OrthancException(ErrorCode_BadRequest); | 914 "When modifying a study, the SeriesInstanceUID cannot be manually modified"); |
915 } | 915 } |
916 | 916 |
917 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) | 917 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
918 { | 918 { |
919 LOG(ERROR) << "When modifying a study, the SopInstanceUID cannot be manually modified"; | 919 throw OrthancException(ErrorCode_BadRequest, |
920 throw OrthancException(ErrorCode_BadRequest); | 920 "When modifying a study, the SopInstanceUID cannot be manually modified"); |
921 } | 921 } |
922 } | 922 } |
923 | 923 |
924 | 924 |
925 // Sanity checks at the series level | 925 // Sanity checks at the series level |
926 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID)) | 926 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID)) |
927 { | 927 { |
928 LOG(ERROR) << "When modifying a series, the parent PatientID cannot be manually modified"; | 928 throw OrthancException(ErrorCode_BadRequest, |
929 throw OrthancException(ErrorCode_BadRequest); | 929 "When modifying a series, the parent PatientID cannot be manually modified"); |
930 } | 930 } |
931 | 931 |
932 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) | 932 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
933 { | 933 { |
934 LOG(ERROR) << "When modifying a series, the parent StudyInstanceUID cannot be manually modified"; | 934 throw OrthancException(ErrorCode_BadRequest, |
935 throw OrthancException(ErrorCode_BadRequest); | 935 "When modifying a series, the parent StudyInstanceUID cannot be manually modified"); |
936 } | 936 } |
937 | 937 |
938 if (!allowManualIdentifiers_) | 938 if (!allowManualIdentifiers_) |
939 { | 939 { |
940 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) | 940 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
941 { | 941 { |
942 LOG(ERROR) << "When modifying a series, the SopInstanceUID cannot be manually modified"; | 942 throw OrthancException(ErrorCode_BadRequest, |
943 throw OrthancException(ErrorCode_BadRequest); | 943 "When modifying a series, the SopInstanceUID cannot be manually modified"); |
944 } | 944 } |
945 } | 945 } |
946 | 946 |
947 | 947 |
948 // Sanity checks at the instance level | 948 // Sanity checks at the instance level |
949 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID)) | 949 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID)) |
950 { | 950 { |
951 LOG(ERROR) << "When modifying an instance, the parent PatientID cannot be manually modified"; | 951 throw OrthancException(ErrorCode_BadRequest, |
952 throw OrthancException(ErrorCode_BadRequest); | 952 "When modifying an instance, the parent PatientID cannot be manually modified"); |
953 } | 953 } |
954 | 954 |
955 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) | 955 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
956 { | 956 { |
957 LOG(ERROR) << "When modifying an instance, the parent StudyInstanceUID cannot be manually modified"; | 957 throw OrthancException(ErrorCode_BadRequest, |
958 throw OrthancException(ErrorCode_BadRequest); | 958 "When modifying an instance, the parent StudyInstanceUID cannot be manually modified"); |
959 } | 959 } |
960 | 960 |
961 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) | 961 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
962 { | 962 { |
963 LOG(ERROR) << "When modifying an instance, the parent SeriesInstanceUID cannot be manually modified"; | 963 throw OrthancException(ErrorCode_BadRequest, |
964 throw OrthancException(ErrorCode_BadRequest); | 964 "When modifying an instance, the parent SeriesInstanceUID cannot be manually modified"); |
965 } | 965 } |
966 | 966 |
967 | 967 |
968 // (0) Create a summary of the source file, if a custom generator | 968 // (0) Create a summary of the source file, if a custom generator |
969 // is provided | 969 // is provided |
1080 | 1080 |
1081 DicomTag tag = FromDcmtkBridge::ParseTag(name); | 1081 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
1082 | 1082 |
1083 if (!force && IsDatabaseKey(tag)) | 1083 if (!force && IsDatabaseKey(tag)) |
1084 { | 1084 { |
1085 LOG(ERROR) << "Marking tag \"" << name << "\" as to be " | 1085 throw OrthancException(ErrorCode_BadRequest, |
1086 << (operation == DicomModification::TagOperation_Keep ? "kept" : "removed") | 1086 "Marking tag \"" + name + "\" as to be " + |
1087 << " requires the \"Force\" option to be set to true"; | 1087 (operation == DicomModification::TagOperation_Keep ? "kept" : "removed") + |
1088 throw OrthancException(ErrorCode_BadRequest); | 1088 " requires the \"Force\" option to be set to true"); |
1089 } | 1089 } |
1090 | 1090 |
1091 switch (operation) | 1091 switch (operation) |
1092 { | 1092 { |
1093 case DicomModification::TagOperation_Keep: | 1093 case DicomModification::TagOperation_Keep: |
1124 | 1124 |
1125 DicomTag tag = FromDcmtkBridge::ParseTag(name); | 1125 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
1126 | 1126 |
1127 if (!force && IsDatabaseKey(tag)) | 1127 if (!force && IsDatabaseKey(tag)) |
1128 { | 1128 { |
1129 LOG(ERROR) << "Marking tag \"" << name << "\" as to be replaced " | 1129 throw OrthancException(ErrorCode_BadRequest, |
1130 << "requires the \"Force\" option to be set to true"; | 1130 "Marking tag \"" + name + "\" as to be replaced " + |
1131 throw OrthancException(ErrorCode_BadRequest); | 1131 "requires the \"Force\" option to be set to true"); |
1132 } | 1132 } |
1133 | 1133 |
1134 target.Replace(tag, value, false); | 1134 target.Replace(tag, value, false); |
1135 | 1135 |
1136 VLOG(1) << "Replace: " << name << " " << tag | 1136 VLOG(1) << "Replace: " << name << " " << tag |
1151 { | 1151 { |
1152 return json[member].asBool(); | 1152 return json[member].asBool(); |
1153 } | 1153 } |
1154 else | 1154 else |
1155 { | 1155 { |
1156 LOG(ERROR) << "Member \"" << member << "\" should be a Boolean value"; | 1156 throw OrthancException(ErrorCode_BadFileFormat, |
1157 throw OrthancException(ErrorCode_BadFileFormat); | 1157 "Member \"" + member + "\" should be a Boolean value"); |
1158 } | 1158 } |
1159 } | 1159 } |
1160 | 1160 |
1161 | 1161 |
1162 void DicomModification::ParseModifyRequest(const Json::Value& request) | 1162 void DicomModification::ParseModifyRequest(const Json::Value& request) |
1269 | 1269 |
1270 void DicomModification::Serialize(Json::Value& value) const | 1270 void DicomModification::Serialize(Json::Value& value) const |
1271 { | 1271 { |
1272 if (identifierGenerator_ != NULL) | 1272 if (identifierGenerator_ != NULL) |
1273 { | 1273 { |
1274 LOG(ERROR) << "Cannot serialize a DicomModification with a custom identifier generator"; | 1274 throw OrthancException(ErrorCode_InternalError, |
1275 throw OrthancException(ErrorCode_InternalError); | 1275 "Cannot serialize a DicomModification with a custom identifier generator"); |
1276 } | 1276 } |
1277 | 1277 |
1278 value = Json::objectValue; | 1278 value = Json::objectValue; |
1279 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_; | 1279 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_; |
1280 value[LEVEL] = EnumerationToString(level_); | 1280 value[LEVEL] = EnumerationToString(level_); |