diff OrthancCppClient/OrthancConnection.cpp @ 540:eaca3d38b2aa laaw

many fixes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Sep 2013 12:55:07 +0200
parents 6e4bd06c17c5
children b2357f1f026f
line wrap: on
line diff
--- a/OrthancCppClient/OrthancConnection.cpp	Mon Aug 12 10:56:35 2013 +0200
+++ b/OrthancCppClient/OrthancConnection.cpp	Thu Sep 12 12:55:07 2013 +0200
@@ -32,11 +32,15 @@
 
 #include "OrthancConnection.h"
 
+#include "../Core/Toolbox.h"
+
 namespace OrthancClient
 {
   void OrthancConnection::ReadPatients()
   {
+    client_.SetMethod(Orthanc::HttpMethod_Get);
     client_.SetUrl(orthancUrl_ + "/patients");
+
     Json::Value v;
     if (!client_.Apply(content_))
     {
@@ -70,4 +74,41 @@
     client_.SetCredentials(username, password);
     ReadPatients();
   }
+
+
+  void OrthancConnection::Store(const void* dicom, uint64_t size)
+  {
+    if (size == 0)
+    {
+      return;
+    }
+
+    client_.SetMethod(Orthanc::HttpMethod_Post);
+    client_.SetUrl(orthancUrl_ + "/instances");
+
+    // Copy the DICOM file in the POST body. TODO - Avoid memory copy
+    client_.AccessPostData().resize(size);
+    memcpy(&client_.AccessPostData()[0], dicom, size);
+
+    Json::Value v;
+    if (!client_.Apply(v))
+    {
+      throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
+    }
+    
+    Refresh();
+  }
+
+
+  void  OrthancConnection::StoreFile(const char* filename)
+  {
+    std::string content;
+    Orthanc::Toolbox::ReadFile(content, filename);
+
+    if (content.size() != 0)
+    {
+      Store(&content[0], content.size());
+    }
+  }
+
 }