diff OrthancServer/Sources/ServerToolbox.cpp @ 4988:8fba26292a9f

Housekeeper plugin: finalizing + integration tests ok
author Alain Mazy <am@osimis.io>
date Sat, 30 Apr 2022 19:39:40 +0200
parents 94a7b681b340
children b1fe3b44ce1d
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerToolbox.cpp	Tue Apr 26 16:14:49 2022 +0200
+++ b/OrthancServer/Sources/ServerToolbox.cpp	Sat Apr 30 19:39:40 2022 +0200
@@ -254,7 +254,8 @@
 
     
     void ReconstructResource(ServerContext& context,
-                             const std::string& resource)
+                             const std::string& resource,
+                             bool reconstructFiles)
     {
       LOG(WARNING) << "Reconstructing resource " << resource;
       
@@ -271,7 +272,30 @@
                                             -1 /* dummy revision */, "" /* dummy MD5 */);
         
         context.GetIndex().ReconstructInstance(locker.GetDicom());
+
+        if (reconstructFiles)
+        {
+          // preserve metadata from old resource
+          typedef std::map<MetadataType, std::string>  InstanceMetadata;
+          InstanceMetadata  instanceMetadata;
+
+          std::string resultPublicId;  // ignored
+          std::unique_ptr<DicomInstanceToStore> dicomInstancetoStore(DicomInstanceToStore::CreateFromParsedDicomFile(locker.GetDicom()));
+
+          context.GetIndex().GetAllMetadata(instanceMetadata, *it, ResourceType_Instance);
+          
+          for (InstanceMetadata::const_iterator itm = instanceMetadata.begin();
+              itm != instanceMetadata.end(); ++itm)
+          {
+            dicomInstancetoStore->AddMetadata(ResourceType_Instance, itm->first, itm->second);
+          }
+
+          context.TranscodeAndStore(resultPublicId, dicomInstancetoStore.get(), StoreInstanceMode_OverwriteDuplicate, true);
+        }
       }
     }
   }
 }
+
+
+todo: add a status route for the plugin !!!
\ No newline at end of file