Mercurial > hg > orthanc
annotate OrthancServer/DicomModification.cpp @ 2760:ab35523fced1 Orthanc-0.8.5
close old branch
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 09:41:40 +0200 |
parents | 80671157d051 |
children | 7f3a65e84d4b |
rev | line source |
---|---|
786 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
786 | 34 #include "DicomModification.h" |
35 | |
36 #include "../Core/OrthancException.h" | |
790 | 37 #include "FromDcmtkBridge.h" |
786 | 38 |
795 | 39 #include <memory> // For std::auto_ptr |
916
b4b46e3e6017
more explicit error message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
40 #include <glog/logging.h> |
795 | 41 |
786 | 42 namespace Orthanc |
43 { | |
44 void DicomModification::MapDicomIdentifier(ParsedDicomFile& dicom, | |
788 | 45 ResourceType level) |
786 | 46 { |
47 std::auto_ptr<DicomTag> tag; | |
48 | |
49 switch (level) | |
50 { | |
788 | 51 case ResourceType_Study: |
786 | 52 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); |
53 break; | |
54 | |
788 | 55 case ResourceType_Series: |
786 | 56 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); |
57 break; | |
58 | |
788 | 59 case ResourceType_Instance: |
786 | 60 tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID)); |
61 break; | |
62 | |
63 default: | |
64 throw OrthancException(ErrorCode_InternalError); | |
65 } | |
66 | |
67 std::string original; | |
68 if (!dicom.GetTagValue(original, *tag)) | |
69 { | |
70 original = ""; | |
71 } | |
72 | |
73 std::string mapped; | |
74 | |
75 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, original)); | |
76 if (previous == uidMap_.end()) | |
77 { | |
78 mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level); | |
79 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped)); | |
80 } | |
81 else | |
82 { | |
83 mapped = previous->second; | |
84 } | |
85 | |
86 dicom.Replace(*tag, mapped); | |
87 } | |
88 | |
89 DicomModification::DicomModification() | |
90 { | |
91 removePrivateTags_ = false; | |
788 | 92 level_ = ResourceType_Instance; |
786 | 93 } |
94 | |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
95 void DicomModification::Keep(const DicomTag& tag) |
786 | 96 { |
97 removals_.erase(tag); | |
98 replacements_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
99 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
100 if (FromDcmtkBridge::IsPrivateTag(tag)) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
101 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
102 privateTagsToKeep_.insert(tag); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
103 } |
786 | 104 } |
105 | |
106 void DicomModification::Remove(const DicomTag& tag) | |
107 { | |
108 removals_.insert(tag); | |
109 replacements_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
110 privateTagsToKeep_.erase(tag); |
786 | 111 } |
112 | |
113 bool DicomModification::IsRemoved(const DicomTag& tag) const | |
114 { | |
115 return removals_.find(tag) != removals_.end(); | |
116 } | |
117 | |
118 void DicomModification::Replace(const DicomTag& tag, | |
119 const std::string& value) | |
120 { | |
121 removals_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
122 privateTagsToKeep_.erase(tag); |
786 | 123 replacements_[tag] = value; |
124 } | |
125 | |
126 bool DicomModification::IsReplaced(const DicomTag& tag) const | |
127 { | |
128 return replacements_.find(tag) != replacements_.end(); | |
129 } | |
130 | |
131 const std::string& DicomModification::GetReplacement(const DicomTag& tag) const | |
132 { | |
133 Replacements::const_iterator it = replacements_.find(tag); | |
134 | |
135 if (it == replacements_.end()) | |
136 { | |
137 throw OrthancException(ErrorCode_InexistentItem); | |
138 } | |
139 else | |
140 { | |
141 return it->second; | |
142 } | |
143 } | |
144 | |
145 void DicomModification::SetRemovePrivateTags(bool removed) | |
146 { | |
147 removePrivateTags_ = removed; | |
148 } | |
149 | |
788 | 150 void DicomModification::SetLevel(ResourceType level) |
786 | 151 { |
152 uidMap_.clear(); | |
153 level_ = level; | |
154 } | |
155 | |
156 void DicomModification::SetupAnonymization() | |
157 { | |
158 removals_.clear(); | |
159 replacements_.clear(); | |
160 removePrivateTags_ = true; | |
788 | 161 level_ = ResourceType_Patient; |
786 | 162 uidMap_.clear(); |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
163 privateTagsToKeep_.clear(); |
786 | 164 |
165 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles | |
166 removals_.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID | |
167 //removals_.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set in Apply() | |
168 removals_.insert(DicomTag(0x0008, 0x0050)); // Accession Number | |
169 removals_.insert(DicomTag(0x0008, 0x0080)); // Institution Name | |
170 removals_.insert(DicomTag(0x0008, 0x0081)); // Institution Address | |
171 removals_.insert(DicomTag(0x0008, 0x0090)); // Referring Physician's Name | |
172 removals_.insert(DicomTag(0x0008, 0x0092)); // Referring Physician's Address | |
173 removals_.insert(DicomTag(0x0008, 0x0094)); // Referring Physician's Telephone Numbers | |
174 removals_.insert(DicomTag(0x0008, 0x1010)); // Station Name | |
175 removals_.insert(DicomTag(0x0008, 0x1030)); // Study Description | |
176 removals_.insert(DicomTag(0x0008, 0x103e)); // Series Description | |
177 removals_.insert(DicomTag(0x0008, 0x1040)); // Institutional Department Name | |
178 removals_.insert(DicomTag(0x0008, 0x1048)); // Physician(s) of Record | |
179 removals_.insert(DicomTag(0x0008, 0x1050)); // Performing Physicians' Name | |
180 removals_.insert(DicomTag(0x0008, 0x1060)); // Name of Physician(s) Reading Study | |
181 removals_.insert(DicomTag(0x0008, 0x1070)); // Operators' Name | |
182 removals_.insert(DicomTag(0x0008, 0x1080)); // Admitting Diagnoses Description | |
183 removals_.insert(DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID | |
184 removals_.insert(DicomTag(0x0008, 0x2111)); // Derivation Description | |
185 //removals_.insert(DicomTag(0x0010, 0x0010)); // Patient's Name => cf. below (*) | |
186 //removals_.insert(DicomTag(0x0010, 0x0020)); // Patient ID => cf. below (*) | |
187 removals_.insert(DicomTag(0x0010, 0x0030)); // Patient's Birth Date | |
188 removals_.insert(DicomTag(0x0010, 0x0032)); // Patient's Birth Time | |
189 removals_.insert(DicomTag(0x0010, 0x0040)); // Patient's Sex | |
190 removals_.insert(DicomTag(0x0010, 0x1000)); // Other Patient Ids | |
191 removals_.insert(DicomTag(0x0010, 0x1001)); // Other Patient Names | |
192 removals_.insert(DicomTag(0x0010, 0x1010)); // Patient's Age | |
193 removals_.insert(DicomTag(0x0010, 0x1020)); // Patient's Size | |
194 removals_.insert(DicomTag(0x0010, 0x1030)); // Patient's Weight | |
195 removals_.insert(DicomTag(0x0010, 0x1090)); // Medical Record Locator | |
196 removals_.insert(DicomTag(0x0010, 0x2160)); // Ethnic Group | |
197 removals_.insert(DicomTag(0x0010, 0x2180)); // Occupation | |
198 removals_.insert(DicomTag(0x0010, 0x21b0)); // Additional Patient's History | |
199 removals_.insert(DicomTag(0x0010, 0x4000)); // Patient Comments | |
200 removals_.insert(DicomTag(0x0018, 0x1000)); // Device Serial Number | |
201 removals_.insert(DicomTag(0x0018, 0x1030)); // Protocol Name | |
202 //removals_.insert(DicomTag(0x0020, 0x000d)); // Study Instance UID => set in Apply() | |
203 //removals_.insert(DicomTag(0x0020, 0x000e)); // Series Instance UID => set in Apply() | |
204 removals_.insert(DicomTag(0x0020, 0x0010)); // Study ID | |
205 removals_.insert(DicomTag(0x0020, 0x0052)); // Frame of Reference UID | |
206 removals_.insert(DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID | |
207 removals_.insert(DicomTag(0x0020, 0x4000)); // Image Comments | |
208 removals_.insert(DicomTag(0x0040, 0x0275)); // Request Attributes Sequence | |
209 removals_.insert(DicomTag(0x0040, 0xa124)); // UID | |
210 removals_.insert(DicomTag(0x0040, 0xa730)); // Content Sequence | |
211 removals_.insert(DicomTag(0x0088, 0x0140)); // Storage Media File-set UID | |
212 removals_.insert(DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID | |
213 removals_.insert(DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID | |
214 | |
215 // Some more removals (from the experience of DICOM files at the CHU of Liege) | |
216 removals_.insert(DicomTag(0x0010, 0x1040)); // Patient's Address | |
217 removals_.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician | |
218 removals_.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers | |
219 removals_.insert(DicomTag(0x0010, 0x2000)); // Medical Alerts | |
220 | |
221 // Set the DeidentificationMethod tag | |
222 replacements_.insert(std::make_pair(DicomTag(0x0012, 0x0063), "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1")); | |
223 | |
224 // Set the PatientIdentityRemoved tag | |
225 replacements_.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES")); | |
226 | |
227 // (*) Choose a random patient name and ID | |
788 | 228 std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient); |
786 | 229 replacements_[DICOM_TAG_PATIENT_ID] = patientId; |
230 replacements_[DICOM_TAG_PATIENT_NAME] = patientId; | |
231 } | |
232 | |
233 void DicomModification::Apply(ParsedDicomFile& toModify) | |
234 { | |
235 // Check the request | |
788 | 236 assert(ResourceType_Patient + 1 == ResourceType_Study && |
237 ResourceType_Study + 1 == ResourceType_Series && | |
238 ResourceType_Series + 1 == ResourceType_Instance); | |
786 | 239 |
240 if (IsRemoved(DICOM_TAG_PATIENT_ID) || | |
241 IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) || | |
242 IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) || | |
243 IsRemoved(DICOM_TAG_SOP_INSTANCE_UID)) | |
244 { | |
245 throw OrthancException(ErrorCode_BadRequest); | |
246 } | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
247 |
786 | 248 |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
249 // Sanity checks |
788 | 250 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) |
786 | 251 { |
916
b4b46e3e6017
more explicit error message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
252 LOG(ERROR) << "When modifying a patient, her PatientID is required to be modified"; |
786 | 253 throw OrthancException(ErrorCode_BadRequest); |
254 } | |
255 | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
256 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
257 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
258 LOG(ERROR) << "When modifying a patient, the StudyInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
259 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
260 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
261 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
262 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
263 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
264 LOG(ERROR) << "When modifying a patient, the SeriesInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
265 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
266 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
267 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
268 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
786 | 269 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
270 LOG(ERROR) << "When modifying a patient, the SopInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
271 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
272 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
273 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
274 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
275 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
276 LOG(ERROR) << "When modifying a study, the parent PatientID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
277 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
278 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
279 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
280 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
281 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
282 LOG(ERROR) << "When modifying a study, the SeriesInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
283 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
284 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
285 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
286 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
287 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
288 LOG(ERROR) << "When modifying a study, the SopInstanceUID cannot be manually modified"; |
786 | 289 throw OrthancException(ErrorCode_BadRequest); |
290 } | |
291 | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
292 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
293 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
294 LOG(ERROR) << "When modifying a series, the parent PatientID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
295 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
296 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
297 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
298 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
786 | 299 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
300 LOG(ERROR) << "When modifying a series, the parent StudyInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
301 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
302 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
303 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
304 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
305 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
306 LOG(ERROR) << "When modifying a series, the SopInstanceUID cannot be manually modified"; |
786 | 307 throw OrthancException(ErrorCode_BadRequest); |
308 } | |
309 | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
310 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID)) |
786 | 311 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
312 LOG(ERROR) << "When modifying an instance, the parent PatientID cannot be manually modified"; |
786 | 313 throw OrthancException(ErrorCode_BadRequest); |
314 } | |
315 | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
316 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
317 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
318 LOG(ERROR) << "When modifying an instance, the parent StudyInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
319 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
320 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
321 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
322 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
323 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
324 LOG(ERROR) << "When modifying an instance, the parent SeriesInstanceUID cannot be manually modified"; |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
325 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
326 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
327 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
328 |
786 | 329 // (1) Remove the private tags, if need be |
330 if (removePrivateTags_) | |
331 { | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
332 toModify.RemovePrivateTags(privateTagsToKeep_); |
786 | 333 } |
334 | |
335 // (2) Remove the tags specified by the user | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
336 for (SetOfTags::const_iterator it = removals_.begin(); |
786 | 337 it != removals_.end(); ++it) |
338 { | |
339 toModify.Remove(*it); | |
340 } | |
341 | |
342 // (3) Replace the tags | |
343 for (Replacements::const_iterator it = replacements_.begin(); | |
344 it != replacements_.end(); ++it) | |
345 { | |
789 | 346 toModify.Replace(it->first, it->second, DicomReplaceMode_InsertIfAbsent); |
786 | 347 } |
348 | |
349 // (4) Update the DICOM identifiers | |
788 | 350 if (level_ <= ResourceType_Study) |
786 | 351 { |
788 | 352 MapDicomIdentifier(toModify, ResourceType_Study); |
786 | 353 } |
354 | |
788 | 355 if (level_ <= ResourceType_Series) |
786 | 356 { |
788 | 357 MapDicomIdentifier(toModify, ResourceType_Series); |
786 | 358 } |
359 | |
788 | 360 if (level_ <= ResourceType_Instance) // Always true |
786 | 361 { |
788 | 362 MapDicomIdentifier(toModify, ResourceType_Instance); |
786 | 363 } |
364 } | |
365 } |