Mercurial > hg > orthanc
annotate OrthancServer/DicomModification.cpp @ 1648:a0a4fa28624c
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Sep 2015 11:33:55 +0200 |
parents | f967bdf8534e |
children | 18c02c6987d5 |
rev | line source |
---|---|
786 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
786 | 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 | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
36 #include "../Core/Logging.h" |
786 | 37 #include "../Core/OrthancException.h" |
790 | 38 #include "FromDcmtkBridge.h" |
786 | 39 |
795 | 40 #include <memory> // For std::auto_ptr |
41 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
42 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
43 static const std::string ORTHANC_DEIDENTIFICATION_METHOD = "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
44 |
786 | 45 namespace Orthanc |
46 { | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
47 void DicomModification::MarkNotOrthancAnonymization() |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
48 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
49 Replacements::iterator it = replacements_.find(DICOM_TAG_DEIDENTIFICATION_METHOD); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
50 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
51 if (it != replacements_.end() && |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
52 it->second == ORTHANC_DEIDENTIFICATION_METHOD) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
53 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
54 replacements_.erase(it); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
55 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
56 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
57 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
58 |
786 | 59 void DicomModification::MapDicomIdentifier(ParsedDicomFile& dicom, |
788 | 60 ResourceType level) |
786 | 61 { |
62 std::auto_ptr<DicomTag> tag; | |
63 | |
64 switch (level) | |
65 { | |
788 | 66 case ResourceType_Study: |
786 | 67 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); |
68 break; | |
69 | |
788 | 70 case ResourceType_Series: |
786 | 71 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); |
72 break; | |
73 | |
788 | 74 case ResourceType_Instance: |
786 | 75 tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID)); |
76 break; | |
77 | |
78 default: | |
79 throw OrthancException(ErrorCode_InternalError); | |
80 } | |
81 | |
82 std::string original; | |
83 if (!dicom.GetTagValue(original, *tag)) | |
84 { | |
85 original = ""; | |
86 } | |
87 | |
88 std::string mapped; | |
89 | |
90 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, original)); | |
91 if (previous == uidMap_.end()) | |
92 { | |
93 mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level); | |
94 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped)); | |
95 } | |
96 else | |
97 { | |
98 mapped = previous->second; | |
99 } | |
100 | |
101 dicom.Replace(*tag, mapped); | |
102 } | |
103 | |
104 DicomModification::DicomModification() | |
105 { | |
106 removePrivateTags_ = false; | |
788 | 107 level_ = ResourceType_Instance; |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
108 allowManualIdentifiers_ = true; |
786 | 109 } |
110 | |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
111 void DicomModification::Keep(const DicomTag& tag) |
786 | 112 { |
113 removals_.erase(tag); | |
114 replacements_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
115 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
116 if (FromDcmtkBridge::IsPrivateTag(tag)) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
117 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
118 privateTagsToKeep_.insert(tag); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
119 } |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
120 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
121 MarkNotOrthancAnonymization(); |
786 | 122 } |
123 | |
124 void DicomModification::Remove(const DicomTag& tag) | |
125 { | |
126 removals_.insert(tag); | |
127 replacements_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
128 privateTagsToKeep_.erase(tag); |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
129 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
130 MarkNotOrthancAnonymization(); |
786 | 131 } |
132 | |
133 bool DicomModification::IsRemoved(const DicomTag& tag) const | |
134 { | |
135 return removals_.find(tag) != removals_.end(); | |
136 } | |
137 | |
138 void DicomModification::Replace(const DicomTag& tag, | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
139 const std::string& value, |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
140 bool safeForAnonymization) |
786 | 141 { |
142 removals_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
143 privateTagsToKeep_.erase(tag); |
786 | 144 replacements_[tag] = value; |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
145 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
146 if (!safeForAnonymization) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
147 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
148 MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
149 } |
786 | 150 } |
151 | |
152 bool DicomModification::IsReplaced(const DicomTag& tag) const | |
153 { | |
154 return replacements_.find(tag) != replacements_.end(); | |
155 } | |
156 | |
157 const std::string& DicomModification::GetReplacement(const DicomTag& tag) const | |
158 { | |
159 Replacements::const_iterator it = replacements_.find(tag); | |
160 | |
161 if (it == replacements_.end()) | |
162 { | |
163 throw OrthancException(ErrorCode_InexistentItem); | |
164 } | |
165 else | |
166 { | |
167 return it->second; | |
168 } | |
169 } | |
170 | |
171 void DicomModification::SetRemovePrivateTags(bool removed) | |
172 { | |
173 removePrivateTags_ = removed; | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
174 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
175 if (!removed) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
176 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
177 MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
178 } |
786 | 179 } |
180 | |
788 | 181 void DicomModification::SetLevel(ResourceType level) |
786 | 182 { |
183 uidMap_.clear(); | |
184 level_ = level; | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
185 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
186 if (level != ResourceType_Patient) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
187 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
188 MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
189 } |
786 | 190 } |
191 | |
192 void DicomModification::SetupAnonymization() | |
193 { | |
194 removals_.clear(); | |
195 replacements_.clear(); | |
196 removePrivateTags_ = true; | |
788 | 197 level_ = ResourceType_Patient; |
786 | 198 uidMap_.clear(); |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
199 privateTagsToKeep_.clear(); |
786 | 200 |
201 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles | |
202 removals_.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID | |
203 //removals_.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set in Apply() | |
204 removals_.insert(DicomTag(0x0008, 0x0050)); // Accession Number | |
205 removals_.insert(DicomTag(0x0008, 0x0080)); // Institution Name | |
206 removals_.insert(DicomTag(0x0008, 0x0081)); // Institution Address | |
207 removals_.insert(DicomTag(0x0008, 0x0090)); // Referring Physician's Name | |
208 removals_.insert(DicomTag(0x0008, 0x0092)); // Referring Physician's Address | |
209 removals_.insert(DicomTag(0x0008, 0x0094)); // Referring Physician's Telephone Numbers | |
210 removals_.insert(DicomTag(0x0008, 0x1010)); // Station Name | |
211 removals_.insert(DicomTag(0x0008, 0x1030)); // Study Description | |
212 removals_.insert(DicomTag(0x0008, 0x103e)); // Series Description | |
213 removals_.insert(DicomTag(0x0008, 0x1040)); // Institutional Department Name | |
214 removals_.insert(DicomTag(0x0008, 0x1048)); // Physician(s) of Record | |
215 removals_.insert(DicomTag(0x0008, 0x1050)); // Performing Physicians' Name | |
216 removals_.insert(DicomTag(0x0008, 0x1060)); // Name of Physician(s) Reading Study | |
217 removals_.insert(DicomTag(0x0008, 0x1070)); // Operators' Name | |
218 removals_.insert(DicomTag(0x0008, 0x1080)); // Admitting Diagnoses Description | |
219 removals_.insert(DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID | |
220 removals_.insert(DicomTag(0x0008, 0x2111)); // Derivation Description | |
221 //removals_.insert(DicomTag(0x0010, 0x0010)); // Patient's Name => cf. below (*) | |
222 //removals_.insert(DicomTag(0x0010, 0x0020)); // Patient ID => cf. below (*) | |
223 removals_.insert(DicomTag(0x0010, 0x0030)); // Patient's Birth Date | |
224 removals_.insert(DicomTag(0x0010, 0x0032)); // Patient's Birth Time | |
225 removals_.insert(DicomTag(0x0010, 0x0040)); // Patient's Sex | |
226 removals_.insert(DicomTag(0x0010, 0x1000)); // Other Patient Ids | |
227 removals_.insert(DicomTag(0x0010, 0x1001)); // Other Patient Names | |
228 removals_.insert(DicomTag(0x0010, 0x1010)); // Patient's Age | |
229 removals_.insert(DicomTag(0x0010, 0x1020)); // Patient's Size | |
230 removals_.insert(DicomTag(0x0010, 0x1030)); // Patient's Weight | |
231 removals_.insert(DicomTag(0x0010, 0x1090)); // Medical Record Locator | |
232 removals_.insert(DicomTag(0x0010, 0x2160)); // Ethnic Group | |
233 removals_.insert(DicomTag(0x0010, 0x2180)); // Occupation | |
234 removals_.insert(DicomTag(0x0010, 0x21b0)); // Additional Patient's History | |
235 removals_.insert(DicomTag(0x0010, 0x4000)); // Patient Comments | |
236 removals_.insert(DicomTag(0x0018, 0x1000)); // Device Serial Number | |
237 removals_.insert(DicomTag(0x0018, 0x1030)); // Protocol Name | |
238 //removals_.insert(DicomTag(0x0020, 0x000d)); // Study Instance UID => set in Apply() | |
239 //removals_.insert(DicomTag(0x0020, 0x000e)); // Series Instance UID => set in Apply() | |
240 removals_.insert(DicomTag(0x0020, 0x0010)); // Study ID | |
241 removals_.insert(DicomTag(0x0020, 0x0052)); // Frame of Reference UID | |
242 removals_.insert(DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID | |
243 removals_.insert(DicomTag(0x0020, 0x4000)); // Image Comments | |
244 removals_.insert(DicomTag(0x0040, 0x0275)); // Request Attributes Sequence | |
245 removals_.insert(DicomTag(0x0040, 0xa124)); // UID | |
246 removals_.insert(DicomTag(0x0040, 0xa730)); // Content Sequence | |
247 removals_.insert(DicomTag(0x0088, 0x0140)); // Storage Media File-set UID | |
248 removals_.insert(DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID | |
249 removals_.insert(DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID | |
250 | |
251 // Some more removals (from the experience of DICOM files at the CHU of Liege) | |
252 removals_.insert(DicomTag(0x0010, 0x1040)); // Patient's Address | |
253 removals_.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician | |
254 removals_.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers | |
255 removals_.insert(DicomTag(0x0010, 0x2000)); // Medical Alerts | |
256 | |
257 // Set the DeidentificationMethod tag | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
258 replacements_.insert(std::make_pair(DICOM_TAG_DEIDENTIFICATION_METHOD, ORTHANC_DEIDENTIFICATION_METHOD)); |
786 | 259 |
260 // Set the PatientIdentityRemoved tag | |
261 replacements_.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES")); | |
262 | |
263 // (*) Choose a random patient name and ID | |
788 | 264 std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient); |
786 | 265 replacements_[DICOM_TAG_PATIENT_ID] = patientId; |
266 replacements_[DICOM_TAG_PATIENT_NAME] = patientId; | |
267 } | |
268 | |
269 void DicomModification::Apply(ParsedDicomFile& toModify) | |
270 { | |
271 // Check the request | |
788 | 272 assert(ResourceType_Patient + 1 == ResourceType_Study && |
273 ResourceType_Study + 1 == ResourceType_Series && | |
274 ResourceType_Series + 1 == ResourceType_Instance); | |
786 | 275 |
276 if (IsRemoved(DICOM_TAG_PATIENT_ID) || | |
277 IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) || | |
278 IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) || | |
279 IsRemoved(DICOM_TAG_SOP_INSTANCE_UID)) | |
280 { | |
281 throw OrthancException(ErrorCode_BadRequest); | |
282 } | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
283 |
786 | 284 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
285 // Sanity checks at the patient level |
788 | 286 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) |
786 | 287 { |
916
b4b46e3e6017
more explicit error message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
288 LOG(ERROR) << "When modifying a patient, her PatientID is required to be modified"; |
786 | 289 throw OrthancException(ErrorCode_BadRequest); |
290 } | |
291 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
292 if (!allowManualIdentifiers_) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
293 { |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
294 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
295 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
296 LOG(ERROR) << "When modifying a patient, the StudyInstanceUID cannot be manually modified"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
297 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
298 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
299 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
300 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
301 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
302 LOG(ERROR) << "When modifying a patient, the SeriesInstanceUID cannot be manually modified"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
303 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
304 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
305 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
306 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
307 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
308 LOG(ERROR) << "When modifying a patient, the SopInstanceUID cannot be manually modified"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
309 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
310 } |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
311 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
312 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
313 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
314 // Sanity checks at the study level |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
315 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
316 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
317 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
|
318 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
319 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
320 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
321 if (!allowManualIdentifiers_) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
322 { |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
323 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
324 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
325 LOG(ERROR) << "When modifying a study, the SeriesInstanceUID cannot be manually modified"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
326 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
327 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
328 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
329 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
330 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
331 LOG(ERROR) << "When modifying a study, the SopInstanceUID cannot be manually modified"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
332 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
333 } |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
334 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
335 |
786 | 336 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
337 // Sanity checks at the series level |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
338 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
339 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
340 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
|
341 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
342 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
343 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
344 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
786 | 345 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
346 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
|
347 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
348 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
349 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
350 if (!allowManualIdentifiers_) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
351 { |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
352 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
353 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
354 LOG(ERROR) << "When modifying a series, the SopInstanceUID cannot be manually modified"; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
355 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
356 } |
786 | 357 } |
358 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
359 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
360 // Sanity checks at the instance level |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
361 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID)) |
786 | 362 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
363 LOG(ERROR) << "When modifying an instance, the parent PatientID cannot be manually modified"; |
786 | 364 throw OrthancException(ErrorCode_BadRequest); |
365 } | |
366 | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
367 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
|
368 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
369 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
|
370 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
371 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
372 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
373 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
|
374 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
375 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
|
376 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
377 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
378 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
379 |
786 | 380 // (1) Remove the private tags, if need be |
381 if (removePrivateTags_) | |
382 { | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
383 toModify.RemovePrivateTags(privateTagsToKeep_); |
786 | 384 } |
385 | |
386 // (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
|
387 for (SetOfTags::const_iterator it = removals_.begin(); |
786 | 388 it != removals_.end(); ++it) |
389 { | |
390 toModify.Remove(*it); | |
391 } | |
392 | |
393 // (3) Replace the tags | |
394 for (Replacements::const_iterator it = replacements_.begin(); | |
395 it != replacements_.end(); ++it) | |
396 { | |
789 | 397 toModify.Replace(it->first, it->second, DicomReplaceMode_InsertIfAbsent); |
786 | 398 } |
399 | |
400 // (4) Update the DICOM identifiers | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
401 if (level_ <= ResourceType_Study && |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
402 !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
786 | 403 { |
788 | 404 MapDicomIdentifier(toModify, ResourceType_Study); |
786 | 405 } |
406 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
407 if (level_ <= ResourceType_Series && |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
408 !IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
786 | 409 { |
788 | 410 MapDicomIdentifier(toModify, ResourceType_Series); |
786 | 411 } |
412 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
413 if (level_ <= ResourceType_Instance && // Always true |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
414 !IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
786 | 415 { |
788 | 416 MapDicomIdentifier(toModify, ResourceType_Instance); |
786 | 417 } |
418 } | |
419 } |