Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 2309:4dc313b9a20a issue-46-anonymization
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2017 13:40:02 +0200 |
parents | b5c8c0590f7f |
children | b7fba68747f6 |
comparison
equal
deleted
inserted
replaced
2308:1bdc4cc68171 | 2309:4dc313b9a20a |
---|---|
176 static bool ParseAnonymizationRequest(DicomModification& target, | 176 static bool ParseAnonymizationRequest(DicomModification& target, |
177 RestApiPostCall& call) | 177 RestApiPostCall& call) |
178 { | 178 { |
179 // curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{"Replace":{"PatientName":"hello","0010-0020":"world"},"Keep":["StudyDescription", "SeriesDescription"],"KeepPrivateTags": null,"Remove":["Modality"]}' > Anonymized.dcm | 179 // curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{"Replace":{"PatientName":"hello","0010-0020":"world"},"Keep":["StudyDescription", "SeriesDescription"],"KeepPrivateTags": null,"Remove":["Modality"]}' > Anonymized.dcm |
180 | 180 |
181 target.SetupAnonymization(); | 181 Json::Value request; |
182 if (!call.ParseJsonRequest(request) || | |
183 !request.isObject()) | |
184 { | |
185 return false; | |
186 } | |
187 | |
188 DicomVersion version = DicomVersion_2008; // TODO Switch to 2017c | |
189 if (request.isMember("DicomVersion")) | |
190 { | |
191 if (request["DicomVersion"].type() != Json::stringValue) | |
192 { | |
193 throw OrthancException(ErrorCode_BadFileFormat); | |
194 } | |
195 else | |
196 { | |
197 version = StringToDicomVersion(request["DicomVersion"].asString()); | |
198 } | |
199 } | |
200 | |
201 target.SetupAnonymization(version); | |
182 std::string patientName = target.GetReplacementAsString(DICOM_TAG_PATIENT_NAME); | 202 std::string patientName = target.GetReplacementAsString(DICOM_TAG_PATIENT_NAME); |
183 | 203 |
184 Json::Value request; | 204 if (request.isMember("KeepPrivateTags")) |
185 if (call.ParseJsonRequest(request) && request.isObject()) | 205 { |
186 { | 206 target.SetRemovePrivateTags(false); |
187 if (request.isMember("KeepPrivateTags")) | 207 } |
188 { | 208 |
189 target.SetRemovePrivateTags(false); | 209 if (request.isMember("Remove")) |
190 } | 210 { |
191 | 211 ParseListOfTags(target, request["Remove"], TagOperation_Remove); |
192 if (request.isMember("Remove")) | 212 } |
193 { | 213 |
194 ParseListOfTags(target, request["Remove"], TagOperation_Remove); | 214 if (request.isMember("Replace")) |
195 } | 215 { |
196 | 216 ParseReplacements(target, request["Replace"]); |
197 if (request.isMember("Replace")) | 217 } |
198 { | 218 |
199 ParseReplacements(target, request["Replace"]); | 219 if (request.isMember("Keep")) |
200 } | 220 { |
201 | 221 ParseListOfTags(target, request["Keep"], TagOperation_Keep); |
202 if (request.isMember("Keep")) | 222 } |
203 { | 223 |
204 ParseListOfTags(target, request["Keep"], TagOperation_Keep); | 224 if (target.IsReplaced(DICOM_TAG_PATIENT_NAME) && |
205 } | 225 target.GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName) |
206 | 226 { |
207 if (target.IsReplaced(DICOM_TAG_PATIENT_NAME) && | 227 // Overwrite the random Patient's Name by one that is more |
208 target.GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName) | 228 // user-friendly (provided none was specified by the user) |
209 { | 229 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true); |
210 // Overwrite the random Patient's Name by one that is more | 230 } |
211 // user-friendly (provided none was specified by the user) | 231 |
212 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true); | 232 return true; |
213 } | |
214 | |
215 return true; | |
216 } | |
217 else | |
218 { | |
219 return false; | |
220 } | |
221 } | 233 } |
222 | 234 |
223 | 235 |
224 static void AnonymizeOrModifyInstance(DicomModification& modification, | 236 static void AnonymizeOrModifyInstance(DicomModification& modification, |
225 RestApiPostCall& call) | 237 RestApiPostCall& call) |