Mercurial > hg > orthanc
comparison OrthancServer/DicomModification.cpp @ 788:7ebe4bf87196
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 May 2014 18:39:36 +0200 |
parents | ac18946afa74 |
children | 55dae8c5a6ab |
comparison
equal
deleted
inserted
replaced
787:ac18946afa74 | 788:7ebe4bf87196 |
---|---|
35 #include "../Core/OrthancException.h" | 35 #include "../Core/OrthancException.h" |
36 | 36 |
37 namespace Orthanc | 37 namespace Orthanc |
38 { | 38 { |
39 void DicomModification::MapDicomIdentifier(ParsedDicomFile& dicom, | 39 void DicomModification::MapDicomIdentifier(ParsedDicomFile& dicom, |
40 DicomRootLevel level) | 40 ResourceType level) |
41 { | 41 { |
42 std::auto_ptr<DicomTag> tag; | 42 std::auto_ptr<DicomTag> tag; |
43 | 43 |
44 switch (level) | 44 switch (level) |
45 { | 45 { |
46 case DicomRootLevel_Study: | 46 case ResourceType_Study: |
47 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); | 47 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); |
48 break; | 48 break; |
49 | 49 |
50 case DicomRootLevel_Series: | 50 case ResourceType_Series: |
51 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); | 51 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); |
52 break; | 52 break; |
53 | 53 |
54 case DicomRootLevel_Instance: | 54 case ResourceType_Instance: |
55 tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID)); | 55 tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID)); |
56 break; | 56 break; |
57 | 57 |
58 default: | 58 default: |
59 throw OrthancException(ErrorCode_InternalError); | 59 throw OrthancException(ErrorCode_InternalError); |
82 } | 82 } |
83 | 83 |
84 DicomModification::DicomModification() | 84 DicomModification::DicomModification() |
85 { | 85 { |
86 removePrivateTags_ = false; | 86 removePrivateTags_ = false; |
87 level_ = DicomRootLevel_Instance; | 87 level_ = ResourceType_Instance; |
88 } | 88 } |
89 | 89 |
90 void DicomModification::Keep(const DicomTag& tag) | 90 void DicomModification::Keep(const DicomTag& tag) |
91 { | 91 { |
92 removals_.erase(tag); | 92 removals_.erase(tag); |
133 void DicomModification::SetRemovePrivateTags(bool removed) | 133 void DicomModification::SetRemovePrivateTags(bool removed) |
134 { | 134 { |
135 removePrivateTags_ = removed; | 135 removePrivateTags_ = removed; |
136 } | 136 } |
137 | 137 |
138 void DicomModification::SetLevel(DicomRootLevel level) | 138 void DicomModification::SetLevel(ResourceType level) |
139 { | 139 { |
140 uidMap_.clear(); | 140 uidMap_.clear(); |
141 level_ = level; | 141 level_ = level; |
142 } | 142 } |
143 | 143 |
144 void DicomModification::SetupAnonymization() | 144 void DicomModification::SetupAnonymization() |
145 { | 145 { |
146 removals_.clear(); | 146 removals_.clear(); |
147 replacements_.clear(); | 147 replacements_.clear(); |
148 removePrivateTags_ = true; | 148 removePrivateTags_ = true; |
149 level_ = DicomRootLevel_Patient; | 149 level_ = ResourceType_Patient; |
150 uidMap_.clear(); | 150 uidMap_.clear(); |
151 | 151 |
152 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles | 152 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles |
153 removals_.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID | 153 removals_.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID |
154 //removals_.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set in Apply() | 154 //removals_.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set in Apply() |
210 | 210 |
211 // Set the PatientIdentityRemoved tag | 211 // Set the PatientIdentityRemoved tag |
212 replacements_.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES")); | 212 replacements_.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES")); |
213 | 213 |
214 // (*) Choose a random patient name and ID | 214 // (*) Choose a random patient name and ID |
215 std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient); | 215 std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient); |
216 replacements_[DICOM_TAG_PATIENT_ID] = patientId; | 216 replacements_[DICOM_TAG_PATIENT_ID] = patientId; |
217 replacements_[DICOM_TAG_PATIENT_NAME] = patientId; | 217 replacements_[DICOM_TAG_PATIENT_NAME] = patientId; |
218 } | 218 } |
219 | 219 |
220 void DicomModification::Apply(ParsedDicomFile& toModify) | 220 void DicomModification::Apply(ParsedDicomFile& toModify) |
221 { | 221 { |
222 // Check the request | 222 // Check the request |
223 assert(DicomRootLevel_Patient + 1 == DicomRootLevel_Study && | 223 assert(ResourceType_Patient + 1 == ResourceType_Study && |
224 DicomRootLevel_Study + 1 == DicomRootLevel_Series && | 224 ResourceType_Study + 1 == ResourceType_Series && |
225 DicomRootLevel_Series + 1 == DicomRootLevel_Instance); | 225 ResourceType_Series + 1 == ResourceType_Instance); |
226 | 226 |
227 if (IsRemoved(DICOM_TAG_PATIENT_ID) || | 227 if (IsRemoved(DICOM_TAG_PATIENT_ID) || |
228 IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) || | 228 IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) || |
229 IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) || | 229 IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) || |
230 IsRemoved(DICOM_TAG_SOP_INSTANCE_UID)) | 230 IsRemoved(DICOM_TAG_SOP_INSTANCE_UID)) |
231 { | 231 { |
232 throw OrthancException(ErrorCode_BadRequest); | 232 throw OrthancException(ErrorCode_BadRequest); |
233 } | 233 } |
234 | 234 |
235 if (level_ == DicomRootLevel_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) | 235 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) |
236 { | 236 { |
237 throw OrthancException(ErrorCode_BadRequest); | 237 throw OrthancException(ErrorCode_BadRequest); |
238 } | 238 } |
239 | 239 |
240 if (level_ > DicomRootLevel_Patient && IsReplaced(DICOM_TAG_PATIENT_ID)) | 240 if (level_ > ResourceType_Patient && IsReplaced(DICOM_TAG_PATIENT_ID)) |
241 { | 241 { |
242 throw OrthancException(ErrorCode_BadRequest); | 242 throw OrthancException(ErrorCode_BadRequest); |
243 } | 243 } |
244 | 244 |
245 if (level_ > DicomRootLevel_Study && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) | 245 if (level_ > ResourceType_Study && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
246 { | 246 { |
247 throw OrthancException(ErrorCode_BadRequest); | 247 throw OrthancException(ErrorCode_BadRequest); |
248 } | 248 } |
249 | 249 |
250 if (level_ > DicomRootLevel_Series && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) | 250 if (level_ > ResourceType_Series && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
251 { | 251 { |
252 throw OrthancException(ErrorCode_BadRequest); | 252 throw OrthancException(ErrorCode_BadRequest); |
253 } | 253 } |
254 | 254 |
255 // (1) Remove the private tags, if need be | 255 // (1) Remove the private tags, if need be |
267 | 267 |
268 // (3) Replace the tags | 268 // (3) Replace the tags |
269 for (Replacements::const_iterator it = replacements_.begin(); | 269 for (Replacements::const_iterator it = replacements_.begin(); |
270 it != replacements_.end(); ++it) | 270 it != replacements_.end(); ++it) |
271 { | 271 { |
272 toModify.Replace(it->first, it->second, DicomReplaceMode_InsertIfAbsent); | 272 toModify.Replace(it->first, it->second, FromDcmtkBridge::ReplaceMode_InsertIfAbsent); |
273 } | 273 } |
274 | 274 |
275 // (4) Update the DICOM identifiers | 275 // (4) Update the DICOM identifiers |
276 if (level_ <= DicomRootLevel_Study) | 276 if (level_ <= ResourceType_Study) |
277 { | 277 { |
278 MapDicomIdentifier(toModify, DicomRootLevel_Study); | 278 MapDicomIdentifier(toModify, ResourceType_Study); |
279 } | 279 } |
280 | 280 |
281 if (level_ <= DicomRootLevel_Series) | 281 if (level_ <= ResourceType_Series) |
282 { | 282 { |
283 MapDicomIdentifier(toModify, DicomRootLevel_Series); | 283 MapDicomIdentifier(toModify, ResourceType_Series); |
284 } | 284 } |
285 | 285 |
286 if (level_ <= DicomRootLevel_Instance) // Always true | 286 if (level_ <= ResourceType_Instance) // Always true |
287 { | 287 { |
288 MapDicomIdentifier(toModify, DicomRootLevel_Instance); | 288 MapDicomIdentifier(toModify, ResourceType_Instance); |
289 } | 289 } |
290 } | 290 } |
291 } | 291 } |