changeset 314:4f17834a50b6

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Dec 2012 13:53:24 +0100
parents 60429bb2551e
children fc856d175d18
files OrthancServer/OrthancRestApi.cpp
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi.cpp	Fri Dec 21 13:44:38 2012 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Fri Dec 21 13:53:24 2012 +0100
@@ -1093,22 +1093,31 @@
   }
 
 
-  static void ModifyInstance(RestApi::PostCall& call)
+  static void AnonymizeOrModifyInstance(Removals removals,
+                                        Replacements replacements,
+                                        bool removePrivateTags,
+                                        RestApi::PostCall& call)
   {
     RETRIEVE_CONTEXT(call);
     
     std::string id = call.GetUriComponent("id", "");
     ParsedDicomFile& dicom = context.GetDicomFile(id);
     
+    std::auto_ptr<ParsedDicomFile> modified(dicom.Clone());
+    ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags);
+    modified->Answer(call.GetOutput());
+  }
+
+
+  static void ModifyInstance(RestApi::PostCall& call)
+  {
     Removals removals;
     Replacements replacements;
     bool removePrivateTags;
 
     if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
     {
-      std::auto_ptr<ParsedDicomFile> modified(dicom.Clone());
-      ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags);
-      modified->Answer(call.GetOutput());
+      AnonymizeOrModifyInstance(removals, replacements, removePrivateTags, call);
     }
   }
 
@@ -1117,9 +1126,6 @@
   {
     RETRIEVE_CONTEXT(call);
     
-    std::string id = call.GetUriComponent("id", "");
-    ParsedDicomFile& dicom = context.GetDicomFile(id);
-    
     Removals removals;
     Replacements replacements;
     bool removePrivateTags;
@@ -1139,9 +1145,7 @@
                                            FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient)));
       }
 
-      std::auto_ptr<ParsedDicomFile> anonymized(dicom.Clone());
-      ReplaceInstanceInternal(*anonymized, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags);
-      anonymized->Answer(call.GetOutput());
+      AnonymizeOrModifyInstance(removals, replacements, removePrivateTags, call);
     }
   }