comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 2639:75a404e40323 jobs

simplification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 May 2018 14:39:22 +0200
parents 6db878376018
children c691fcf66071
comparison
equal deleted inserted replaced
2638:25ae209dcea9 2639:75a404e40323
108 modification.Apply(*modified); 108 modification.Apply(*modified);
109 modified->Answer(call.GetOutput()); 109 modified->Answer(call.GetOutput());
110 } 110 }
111 111
112 112
113 static void AnonymizeOrModifyResource(DicomModification& modification, 113 static void AnonymizeOrModifyResource(DicomModification* modificationRaw, // Takes ownership
114 MetadataType metadataType, 114 MetadataType metadataType,
115 ChangeType changeType,
116 ResourceType resourceType, 115 ResourceType resourceType,
117 RestApiPostCall& call) 116 RestApiPostCall& call)
118 { 117 {
118 if (modificationRaw == NULL)
119 {
120 throw OrthancException(ErrorCode_NullPointer);
121 }
122
123 std::auto_ptr<DicomModification> modification(modificationRaw);
124
119 bool isFirst = true; 125 bool isFirst = true;
120 Json::Value result(Json::objectValue); 126 Json::Value result(Json::objectValue);
121 127
122 ServerContext& context = OrthancRestApi::GetContext(call); 128 ServerContext& context = OrthancRestApi::GetContext(call);
123 129
161 /** 167 /**
162 * Compute the resulting DICOM instance. 168 * Compute the resulting DICOM instance.
163 **/ 169 **/
164 170
165 std::auto_ptr<ParsedDicomFile> modified(original.Clone(true)); 171 std::auto_ptr<ParsedDicomFile> modified(original.Clone(true));
166 modification.Apply(*modified); 172 modification->Apply(*modified);
167 173
168 DicomInstanceToStore toStore; 174 DicomInstanceToStore toStore;
169 toStore.SetRestOrigin(call); 175 toStore.SetRestOrigin(call);
170 toStore.SetParsedDicomFile(*modified); 176 toStore.SetParsedDicomFile(*modified);
171 177
287 293
288 AnonymizeOrModifyInstance(modification, call); 294 AnonymizeOrModifyInstance(modification, call);
289 } 295 }
290 296
291 297
292 template <enum ChangeType changeType, 298 template <enum ResourceType resourceType>
293 enum ResourceType resourceType>
294 static void ModifyResource(RestApiPostCall& call) 299 static void ModifyResource(RestApiPostCall& call)
295 { 300 {
296 DicomModification modification; 301 std::auto_ptr<DicomModification> modification(new DicomModification);
297 302 ParseModifyRequest(*modification, call);
298 ParseModifyRequest(modification, call); 303
299 304 modification->SetLevel(resourceType);
300 modification.SetLevel(resourceType); 305 AnonymizeOrModifyResource(modification.release(), MetadataType_ModifiedFrom, resourceType, call);
301 AnonymizeOrModifyResource(modification, MetadataType_ModifiedFrom, 306 }
302 changeType, resourceType, call); 307
303 } 308
304 309 template <enum ResourceType resourceType>
305
306 template <enum ChangeType changeType,
307 enum ResourceType resourceType>
308 static void AnonymizeResource(RestApiPostCall& call) 310 static void AnonymizeResource(RestApiPostCall& call)
309 { 311 {
310 DicomModification modification; 312 std::auto_ptr<DicomModification> modification(new DicomModification);
311 313 ParseAnonymizationRequest(*modification, call);
312 ParseAnonymizationRequest(modification, call); 314
313 315 AnonymizeOrModifyResource(modification.release(), MetadataType_AnonymizedFrom, resourceType, call);
314 AnonymizeOrModifyResource(modification, MetadataType_AnonymizedFrom,
315 changeType, resourceType, call);
316 } 316 }
317 317
318 318
319 static void StoreCreatedInstance(std::string& id /* out */, 319 static void StoreCreatedInstance(std::string& id /* out */,
320 RestApiPostCall& call, 320 RestApiPostCall& call,
727 727
728 728
729 void OrthancRestApi::RegisterAnonymizeModify() 729 void OrthancRestApi::RegisterAnonymizeModify()
730 { 730 {
731 Register("/instances/{id}/modify", ModifyInstance); 731 Register("/instances/{id}/modify", ModifyInstance);
732 Register("/series/{id}/modify", ModifyResource<ChangeType_ModifiedSeries, ResourceType_Series>); 732 Register("/series/{id}/modify", ModifyResource<ResourceType_Series>);
733 Register("/studies/{id}/modify", ModifyResource<ChangeType_ModifiedStudy, ResourceType_Study>); 733 Register("/studies/{id}/modify", ModifyResource<ResourceType_Study>);
734 Register("/patients/{id}/modify", ModifyResource<ChangeType_ModifiedPatient, ResourceType_Patient>); 734 Register("/patients/{id}/modify", ModifyResource<ResourceType_Patient>);
735 735
736 Register("/instances/{id}/anonymize", AnonymizeInstance); 736 Register("/instances/{id}/anonymize", AnonymizeInstance);
737 Register("/series/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedSeries, ResourceType_Series>); 737 Register("/series/{id}/anonymize", AnonymizeResource<ResourceType_Series>);
738 Register("/studies/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedStudy, ResourceType_Study>); 738 Register("/studies/{id}/anonymize", AnonymizeResource<ResourceType_Study>);
739 Register("/patients/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedPatient, ResourceType_Patient>); 739 Register("/patients/{id}/anonymize", AnonymizeResource<ResourceType_Patient>);
740 740
741 Register("/tools/create-dicom", CreateDicom); 741 Register("/tools/create-dicom", CreateDicom);
742 } 742 }
743 } 743 }