changeset 999:db18c071fbd7 lua-scripting

store-scu filter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jul 2014 14:09:53 +0200
parents 4136fab6a639
children 13e230bbd882
files CMakeLists.txt OrthancServer/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/Scheduler/IServerFilter.h OrthancServer/Scheduler/ServerJob.h OrthancServer/Scheduler/ServerScheduler.cpp OrthancServer/Scheduler/ServerScheduler.h OrthancServer/Scheduler/StoreScuFilter.cpp OrthancServer/Scheduler/StoreScuFilter.h
diffstat 8 files changed, 143 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Thu Jul 03 18:30:23 2014 +0200
+++ b/CMakeLists.txt	Fri Jul 04 14:09:53 2014 +0200
@@ -157,6 +157,7 @@
   OrthancServer/Scheduler/ServerFilterInstance.cpp
   OrthancServer/Scheduler/ServerJob.cpp
   OrthancServer/Scheduler/ServerScheduler.cpp
+  OrthancServer/Scheduler/StoreScuFilter.cpp
   )
 
 
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Jul 03 18:30:23 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Fri Jul 04 14:09:53 2014 +0200
@@ -36,6 +36,8 @@
 #include "../OrthancInitialization.h"
 #include "../../Core/HttpClient.h"
 #include "../FromDcmtkBridge.h"
+#include "../Scheduler/ServerJob.h"
+#include "../Scheduler/StoreScuFilter.h"
 
 #include <glog/logging.h>
 
@@ -321,17 +323,16 @@
     }
 
     RemoteModalityParameters p = Configuration::GetModalityUsingSymbolicName(remote);
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), p);
 
+    ServerJob job;
     for (std::list<std::string>::const_iterator 
            it = instances.begin(); it != instances.end(); ++it)
     {
-      LOG(INFO) << "Sending resource " << *it << " to modality \"" << remote << "\"";
+      job.AddFilter(new StoreScuFilter(context, p)).AddInput(*it);
+    }
 
-      std::string dicom;
-      context.ReadFile(dicom, *it, FileContentType_Dicom);
-      locker.GetConnection().Store(dicom);
-    }
+    job.SetDescription("Store-SCU from HTTP to modality \"" + remote + "\"");
+    context.GetScheduler().SubmitAndWait(job);
 
     call.GetOutput().AnswerBuffer("{}", "application/json");
   }
--- a/OrthancServer/Scheduler/IServerFilter.h	Thu Jul 03 18:30:23 2014 +0200
+++ b/OrthancServer/Scheduler/IServerFilter.h	Fri Jul 04 14:09:53 2014 +0200
@@ -34,10 +34,11 @@
 
 #include <list>
 #include <string>
+#include <boost/noncopyable.hpp>
 
 namespace Orthanc
 {
-  class IServerFilter
+  class IServerFilter : public boost::noncopyable
   {
   public:
     typedef std::list<std::string>  ListOfStrings;
--- a/OrthancServer/Scheduler/ServerJob.h	Thu Jul 03 18:30:23 2014 +0200
+++ b/OrthancServer/Scheduler/ServerJob.h	Fri Jul 04 14:09:53 2014 +0200
@@ -62,7 +62,7 @@
       return jobId_;
     }
 
-    void SetDescription(const char* description)
+    void SetDescription(const std::string& description)
     {
       description_ = description;
     }
--- a/OrthancServer/Scheduler/ServerScheduler.cpp	Thu Jul 03 18:30:23 2014 +0200
+++ b/OrthancServer/Scheduler/ServerScheduler.cpp	Fri Jul 04 14:09:53 2014 +0200
@@ -271,6 +271,13 @@
   }
 
 
+  bool ServerScheduler::SubmitAndWait(ServerJob& job)
+  {
+    ListOfStrings ignoredSink;
+    return SubmitAndWait(ignoredSink, job);
+  }
+
+
   bool ServerScheduler::IsRunning(const std::string& jobId)
   {
     boost::mutex::scoped_lock lock(mutex_);
--- a/OrthancServer/Scheduler/ServerScheduler.h	Thu Jul 03 18:30:23 2014 +0200
+++ b/OrthancServer/Scheduler/ServerScheduler.h	Fri Jul 04 14:09:53 2014 +0200
@@ -91,6 +91,8 @@
     bool SubmitAndWait(ListOfStrings& outputs,
                        ServerJob& job);
 
+    bool SubmitAndWait(ServerJob& job);
+
     bool IsRunning(const std::string& jobId);
 
     void Cancel(const std::string& jobId);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Scheduler/StoreScuFilter.cpp	Fri Jul 04 14:09:53 2014 +0200
@@ -0,0 +1,65 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
+ * Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "StoreScuFilter.h"
+
+#include <glog/logging.h>
+
+namespace Orthanc
+{
+  StoreScuFilter::StoreScuFilter(ServerContext& context,
+                                 const RemoteModalityParameters& modality) : 
+    context_(context),
+    modality_(modality)
+  {
+  }
+
+  bool StoreScuFilter::Apply(ListOfStrings& outputs,
+                             const ListOfStrings& inputs)
+  {
+
+    ReusableDicomUserConnection::Locker locker(context_.GetReusableDicomUserConnection(), modality_);
+
+    for (ListOfStrings::const_iterator
+           it = inputs.begin(); it != inputs.end(); ++it)
+    {
+      LOG(INFO) << "Sending resource " << *it << " to modality \"" 
+                << modality_.GetApplicationEntityTitle() << "\"";
+
+      std::string dicom;
+      context_.ReadFile(dicom, *it, FileContentType_Dicom);
+      locker.GetConnection().Store(dicom);
+    }
+
+    return true;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Scheduler/StoreScuFilter.h	Fri Jul 04 14:09:53 2014 +0200
@@ -0,0 +1,58 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
+ * Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IServerFilter.h"
+#include "../ServerContext.h"
+
+namespace Orthanc
+{
+  class StoreScuFilter : public IServerFilter
+  {
+  private:
+    ServerContext& context_;
+    RemoteModalityParameters modality_;
+
+  public:
+    StoreScuFilter(ServerContext& context,
+                   const RemoteModalityParameters& modality);
+
+    bool Apply(ListOfStrings& outputs,
+               const ListOfStrings& inputs);
+
+    bool SendOutputsToSink() const
+    {
+      return false;
+    }
+  };
+}