Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
537:2890721b0f57 | 540:eaca3d38b2aa |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "OrthancConnection.h" | 33 #include "OrthancConnection.h" |
34 | 34 |
35 #include "../Core/Toolbox.h" | |
36 | |
35 namespace OrthancClient | 37 namespace OrthancClient |
36 { | 38 { |
37 void OrthancConnection::ReadPatients() | 39 void OrthancConnection::ReadPatients() |
38 { | 40 { |
41 client_.SetMethod(Orthanc::HttpMethod_Get); | |
39 client_.SetUrl(orthancUrl_ + "/patients"); | 42 client_.SetUrl(orthancUrl_ + "/patients"); |
43 | |
40 Json::Value v; | 44 Json::Value v; |
41 if (!client_.Apply(content_)) | 45 if (!client_.Apply(content_)) |
42 { | 46 { |
43 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol); | 47 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol); |
44 } | 48 } |
68 orthancUrl_(orthancUrl), patients_(*this) | 72 orthancUrl_(orthancUrl), patients_(*this) |
69 { | 73 { |
70 client_.SetCredentials(username, password); | 74 client_.SetCredentials(username, password); |
71 ReadPatients(); | 75 ReadPatients(); |
72 } | 76 } |
77 | |
78 | |
79 void OrthancConnection::Store(const void* dicom, uint64_t size) | |
80 { | |
81 if (size == 0) | |
82 { | |
83 return; | |
84 } | |
85 | |
86 client_.SetMethod(Orthanc::HttpMethod_Post); | |
87 client_.SetUrl(orthancUrl_ + "/instances"); | |
88 | |
89 // Copy the DICOM file in the POST body. TODO - Avoid memory copy | |
90 client_.AccessPostData().resize(size); | |
91 memcpy(&client_.AccessPostData()[0], dicom, size); | |
92 | |
93 Json::Value v; | |
94 if (!client_.Apply(v)) | |
95 { | |
96 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol); | |
97 } | |
98 | |
99 Refresh(); | |
100 } | |
101 | |
102 | |
103 void OrthancConnection::StoreFile(const char* filename) | |
104 { | |
105 std::string content; | |
106 Orthanc::Toolbox::ReadFile(content, filename); | |
107 | |
108 if (content.size() != 0) | |
109 { | |
110 Store(&content[0], content.size()); | |
111 } | |
112 } | |
113 | |
73 } | 114 } |