Mercurial > hg > orthanc
annotate OrthancServer/DicomModification.cpp @ 2222:21713ce8717b
Fix handling of Move Originator AET and ID in C-MOVE SCP
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Dec 2016 14:34:33 +0100 |
parents | e3fd5bc429a2 |
children | a3a65de1840f |
rev | line source |
---|---|
786 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
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 { | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
47 void DicomModification::RemoveInternal(const DicomTag& tag) |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
48 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
49 Replacements::iterator it = replacements_.find(tag); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
50 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
51 if (it != replacements_.end()) |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
52 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
53 delete it->second; |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
54 replacements_.erase(it); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
55 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
56 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
57 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
58 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
59 void DicomModification::ReplaceInternal(const DicomTag& tag, |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
60 const Json::Value& value) |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
61 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
62 Replacements::iterator it = replacements_.find(tag); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
63 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
64 if (it != replacements_.end()) |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
65 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
66 delete it->second; |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
67 it->second = NULL; // In the case of an exception during the clone |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
68 it->second = new Json::Value(value); // Clone |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
69 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
70 else |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
71 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
72 replacements_[tag] = new Json::Value(value); // Clone |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
73 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
74 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
75 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
76 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
77 void DicomModification::ClearReplacements() |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
78 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
79 for (Replacements::iterator it = replacements_.begin(); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
80 it != replacements_.end(); ++it) |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
81 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
82 delete it->second; |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
83 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
84 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
85 replacements_.clear(); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
86 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
87 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
88 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
89 void DicomModification::MarkNotOrthancAnonymization() |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
90 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
91 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
|
92 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
93 if (it != replacements_.end() && |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
94 it->second->asString() == ORTHANC_DEIDENTIFICATION_METHOD) |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
95 { |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
96 delete it->second; |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
97 replacements_.erase(it); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
98 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
99 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
100 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
101 |
786 | 102 void DicomModification::MapDicomIdentifier(ParsedDicomFile& dicom, |
788 | 103 ResourceType level) |
786 | 104 { |
105 std::auto_ptr<DicomTag> tag; | |
106 | |
107 switch (level) | |
108 { | |
788 | 109 case ResourceType_Study: |
786 | 110 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); |
111 break; | |
112 | |
788 | 113 case ResourceType_Series: |
786 | 114 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); |
115 break; | |
116 | |
788 | 117 case ResourceType_Instance: |
786 | 118 tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID)); |
119 break; | |
120 | |
121 default: | |
122 throw OrthancException(ErrorCode_InternalError); | |
123 } | |
124 | |
125 std::string original; | |
126 if (!dicom.GetTagValue(original, *tag)) | |
127 { | |
128 original = ""; | |
129 } | |
130 | |
131 std::string mapped; | |
132 | |
133 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, original)); | |
134 if (previous == uidMap_.end()) | |
135 { | |
136 mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level); | |
137 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped)); | |
138 } | |
139 else | |
140 { | |
141 mapped = previous->second; | |
142 } | |
143 | |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
144 dicom.Replace(*tag, mapped, false /* don't try and decode data URI scheme for UIDs */, DicomReplaceMode_InsertIfAbsent); |
786 | 145 } |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
146 |
2194
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
147 DicomModification::DicomModification() : |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
148 removePrivateTags_(false), |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
149 level_(ResourceType_Instance), |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
150 allowManualIdentifiers_(true), |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
151 keepStudyInstanceUid_(false), |
2209
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2194
diff
changeset
|
152 keepSeriesInstanceUid_(false) |
786 | 153 { |
154 } | |
155 | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
156 DicomModification::~DicomModification() |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
157 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
158 ClearReplacements(); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
159 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
160 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
161 void DicomModification::Keep(const DicomTag& tag) |
786 | 162 { |
163 removals_.erase(tag); | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
164 RemoveInternal(tag); |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
165 |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1698
diff
changeset
|
166 if (tag.IsPrivate()) |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
167 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
168 privateTagsToKeep_.insert(tag); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
169 } |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
170 |
2194
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
171 if (tag == DICOM_TAG_STUDY_INSTANCE_UID) |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
172 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
173 keepStudyInstanceUid_ = true; |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
174 } |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
175 |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
176 if (tag == DICOM_TAG_SERIES_INSTANCE_UID) |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
177 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
178 keepSeriesInstanceUid_ = true; |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
179 } |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
180 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
181 MarkNotOrthancAnonymization(); |
786 | 182 } |
183 | |
184 void DicomModification::Remove(const DicomTag& tag) | |
185 { | |
186 removals_.insert(tag); | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
187 RemoveInternal(tag); |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
188 privateTagsToKeep_.erase(tag); |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
189 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
190 MarkNotOrthancAnonymization(); |
786 | 191 } |
192 | |
193 bool DicomModification::IsRemoved(const DicomTag& tag) const | |
194 { | |
195 return removals_.find(tag) != removals_.end(); | |
196 } | |
197 | |
198 void DicomModification::Replace(const DicomTag& tag, | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
199 const Json::Value& value, |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
200 bool safeForAnonymization) |
786 | 201 { |
202 removals_.erase(tag); | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
203 privateTagsToKeep_.erase(tag); |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
204 ReplaceInternal(tag, value); |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
205 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
206 if (!safeForAnonymization) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
207 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
208 MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
209 } |
786 | 210 } |
211 | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
212 |
786 | 213 bool DicomModification::IsReplaced(const DicomTag& tag) const |
214 { | |
215 return replacements_.find(tag) != replacements_.end(); | |
216 } | |
217 | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
218 const Json::Value& DicomModification::GetReplacement(const DicomTag& tag) const |
786 | 219 { |
220 Replacements::const_iterator it = replacements_.find(tag); | |
221 | |
222 if (it == replacements_.end()) | |
223 { | |
224 throw OrthancException(ErrorCode_InexistentItem); | |
225 } | |
226 else | |
227 { | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
228 return *it->second; |
786 | 229 } |
230 } | |
231 | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
232 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
233 std::string DicomModification::GetReplacementAsString(const DicomTag& tag) const |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
234 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
235 const Json::Value& json = GetReplacement(tag); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
236 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
237 if (json.type() != Json::stringValue) |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
238 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
239 throw OrthancException(ErrorCode_BadParameterType); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
240 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
241 else |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
242 { |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
243 return json.asString(); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
244 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
245 } |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
246 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
247 |
786 | 248 void DicomModification::SetRemovePrivateTags(bool removed) |
249 { | |
250 removePrivateTags_ = removed; | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
251 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
252 if (!removed) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
253 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
254 MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
255 } |
786 | 256 } |
257 | |
788 | 258 void DicomModification::SetLevel(ResourceType level) |
786 | 259 { |
260 uidMap_.clear(); | |
261 level_ = level; | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
262 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
263 if (level != ResourceType_Patient) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
264 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
265 MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
266 } |
786 | 267 } |
268 | |
269 void DicomModification::SetupAnonymization() | |
270 { | |
271 removals_.clear(); | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
272 ClearReplacements(); |
786 | 273 removePrivateTags_ = true; |
788 | 274 level_ = ResourceType_Patient; |
786 | 275 uidMap_.clear(); |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
276 privateTagsToKeep_.clear(); |
786 | 277 |
278 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles | |
279 removals_.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID | |
280 //removals_.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set in Apply() | |
281 removals_.insert(DicomTag(0x0008, 0x0050)); // Accession Number | |
282 removals_.insert(DicomTag(0x0008, 0x0080)); // Institution Name | |
283 removals_.insert(DicomTag(0x0008, 0x0081)); // Institution Address | |
284 removals_.insert(DicomTag(0x0008, 0x0090)); // Referring Physician's Name | |
285 removals_.insert(DicomTag(0x0008, 0x0092)); // Referring Physician's Address | |
286 removals_.insert(DicomTag(0x0008, 0x0094)); // Referring Physician's Telephone Numbers | |
287 removals_.insert(DicomTag(0x0008, 0x1010)); // Station Name | |
288 removals_.insert(DicomTag(0x0008, 0x1030)); // Study Description | |
289 removals_.insert(DicomTag(0x0008, 0x103e)); // Series Description | |
290 removals_.insert(DicomTag(0x0008, 0x1040)); // Institutional Department Name | |
291 removals_.insert(DicomTag(0x0008, 0x1048)); // Physician(s) of Record | |
292 removals_.insert(DicomTag(0x0008, 0x1050)); // Performing Physicians' Name | |
293 removals_.insert(DicomTag(0x0008, 0x1060)); // Name of Physician(s) Reading Study | |
294 removals_.insert(DicomTag(0x0008, 0x1070)); // Operators' Name | |
295 removals_.insert(DicomTag(0x0008, 0x1080)); // Admitting Diagnoses Description | |
296 removals_.insert(DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID | |
297 removals_.insert(DicomTag(0x0008, 0x2111)); // Derivation Description | |
298 //removals_.insert(DicomTag(0x0010, 0x0010)); // Patient's Name => cf. below (*) | |
299 //removals_.insert(DicomTag(0x0010, 0x0020)); // Patient ID => cf. below (*) | |
300 removals_.insert(DicomTag(0x0010, 0x0030)); // Patient's Birth Date | |
301 removals_.insert(DicomTag(0x0010, 0x0032)); // Patient's Birth Time | |
302 removals_.insert(DicomTag(0x0010, 0x0040)); // Patient's Sex | |
303 removals_.insert(DicomTag(0x0010, 0x1000)); // Other Patient Ids | |
304 removals_.insert(DicomTag(0x0010, 0x1001)); // Other Patient Names | |
305 removals_.insert(DicomTag(0x0010, 0x1010)); // Patient's Age | |
306 removals_.insert(DicomTag(0x0010, 0x1020)); // Patient's Size | |
307 removals_.insert(DicomTag(0x0010, 0x1030)); // Patient's Weight | |
308 removals_.insert(DicomTag(0x0010, 0x1090)); // Medical Record Locator | |
309 removals_.insert(DicomTag(0x0010, 0x2160)); // Ethnic Group | |
310 removals_.insert(DicomTag(0x0010, 0x2180)); // Occupation | |
311 removals_.insert(DicomTag(0x0010, 0x21b0)); // Additional Patient's History | |
312 removals_.insert(DicomTag(0x0010, 0x4000)); // Patient Comments | |
313 removals_.insert(DicomTag(0x0018, 0x1000)); // Device Serial Number | |
314 removals_.insert(DicomTag(0x0018, 0x1030)); // Protocol Name | |
315 //removals_.insert(DicomTag(0x0020, 0x000d)); // Study Instance UID => set in Apply() | |
316 //removals_.insert(DicomTag(0x0020, 0x000e)); // Series Instance UID => set in Apply() | |
317 removals_.insert(DicomTag(0x0020, 0x0010)); // Study ID | |
318 removals_.insert(DicomTag(0x0020, 0x0052)); // Frame of Reference UID | |
319 removals_.insert(DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID | |
320 removals_.insert(DicomTag(0x0020, 0x4000)); // Image Comments | |
321 removals_.insert(DicomTag(0x0040, 0x0275)); // Request Attributes Sequence | |
322 removals_.insert(DicomTag(0x0040, 0xa124)); // UID | |
323 removals_.insert(DicomTag(0x0040, 0xa730)); // Content Sequence | |
324 removals_.insert(DicomTag(0x0088, 0x0140)); // Storage Media File-set UID | |
325 removals_.insert(DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID | |
326 removals_.insert(DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID | |
327 | |
328 // Some more removals (from the experience of DICOM files at the CHU of Liege) | |
329 removals_.insert(DicomTag(0x0010, 0x1040)); // Patient's Address | |
330 removals_.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician | |
331 removals_.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers | |
332 removals_.insert(DicomTag(0x0010, 0x2000)); // Medical Alerts | |
333 | |
334 // Set the DeidentificationMethod tag | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
335 ReplaceInternal(DICOM_TAG_DEIDENTIFICATION_METHOD, ORTHANC_DEIDENTIFICATION_METHOD); |
786 | 336 |
337 // Set the PatientIdentityRemoved tag | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
338 ReplaceInternal(DicomTag(0x0012, 0x0062), "YES"); |
786 | 339 |
340 // (*) Choose a random patient name and ID | |
788 | 341 std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient); |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
342 ReplaceInternal(DICOM_TAG_PATIENT_ID, patientId); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
343 ReplaceInternal(DICOM_TAG_PATIENT_NAME, patientId); |
786 | 344 } |
345 | |
346 void DicomModification::Apply(ParsedDicomFile& toModify) | |
347 { | |
348 // Check the request | |
788 | 349 assert(ResourceType_Patient + 1 == ResourceType_Study && |
350 ResourceType_Study + 1 == ResourceType_Series && | |
351 ResourceType_Series + 1 == ResourceType_Instance); | |
786 | 352 |
353 if (IsRemoved(DICOM_TAG_PATIENT_ID) || | |
354 IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) || | |
355 IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) || | |
356 IsRemoved(DICOM_TAG_SOP_INSTANCE_UID)) | |
357 { | |
358 throw OrthancException(ErrorCode_BadRequest); | |
359 } | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
360 |
786 | 361 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
362 // Sanity checks at the patient level |
788 | 363 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID)) |
786 | 364 { |
916
b4b46e3e6017
more explicit error message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
365 LOG(ERROR) << "When modifying a patient, her PatientID is required to be modified"; |
786 | 366 throw OrthancException(ErrorCode_BadRequest); |
367 } | |
368 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
369 if (!allowManualIdentifiers_) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
370 { |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
371 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
|
372 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
373 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
|
374 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
375 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
376 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
377 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
|
378 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
379 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
|
380 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
381 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
382 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
383 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
|
384 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
385 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
|
386 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
387 } |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
388 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
389 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
390 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
391 // Sanity checks at the study level |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
392 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
393 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
394 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
|
395 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
396 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
397 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
398 if (!allowManualIdentifiers_) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
399 { |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
400 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
|
401 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
402 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
|
403 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
404 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
405 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
406 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
|
407 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
408 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
|
409 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
410 } |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
411 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
412 |
786 | 413 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
414 // Sanity checks at the series level |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
415 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID)) |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
416 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
417 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
|
418 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
419 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
420 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
421 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
786 | 422 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
423 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
|
424 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
425 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
426 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
427 if (!allowManualIdentifiers_) |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
428 { |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
429 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
|
430 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
431 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
|
432 throw OrthancException(ErrorCode_BadRequest); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
433 } |
786 | 434 } |
435 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
436 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
437 // Sanity checks at the instance level |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
438 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID)) |
786 | 439 { |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
440 LOG(ERROR) << "When modifying an instance, the parent PatientID cannot be manually modified"; |
786 | 441 throw OrthancException(ErrorCode_BadRequest); |
442 } | |
443 | |
1160
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
444 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
|
445 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
446 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
|
447 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
448 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
449 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
450 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
|
451 { |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
452 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
|
453 throw OrthancException(ErrorCode_BadRequest); |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
454 } |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
455 |
80671157d051
generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
456 |
786 | 457 // (1) Remove the private tags, if need be |
458 if (removePrivateTags_) | |
459 { | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
916
diff
changeset
|
460 toModify.RemovePrivateTags(privateTagsToKeep_); |
786 | 461 } |
462 | |
463 // (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
|
464 for (SetOfTags::const_iterator it = removals_.begin(); |
786 | 465 it != removals_.end(); ++it) |
466 { | |
467 toModify.Remove(*it); | |
468 } | |
469 | |
470 // (3) Replace the tags | |
471 for (Replacements::const_iterator it = replacements_.begin(); | |
472 it != replacements_.end(); ++it) | |
473 { | |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
474 toModify.Replace(it->first, *it->second, true /* decode data URI scheme */, DicomReplaceMode_InsertIfAbsent); |
786 | 475 } |
476 | |
477 // (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
|
478 if (level_ <= ResourceType_Study && |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
479 !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
786 | 480 { |
2194
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
481 if (keepStudyInstanceUid_) |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
482 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
483 LOG(WARNING) << "Modifying a study while keeping its original StudyInstanceUID: This should be avoided!"; |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
484 } |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
485 else |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
486 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
487 MapDicomIdentifier(toModify, ResourceType_Study); |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
488 } |
786 | 489 } |
490 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
491 if (level_ <= ResourceType_Series && |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
492 !IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
786 | 493 { |
2194
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
494 if (keepSeriesInstanceUid_) |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
495 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
496 LOG(WARNING) << "Modifying a series while keeping its original SeriesInstanceUID: This should be avoided!"; |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
497 } |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
498 else |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
499 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
500 MapDicomIdentifier(toModify, ResourceType_Series); |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
501 } |
786 | 502 } |
503 | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
504 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
|
505 !IsReplaced(DICOM_TAG_SOP_INSTANCE_UID)) |
786 | 506 { |
2209
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2194
diff
changeset
|
507 MapDicomIdentifier(toModify, ResourceType_Instance); |
786 | 508 } |
509 } | |
510 } |