comparison OrthancServer/main.cpp @ 613:60d90e48e809 find-move-scp

query/retrieve
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Oct 2013 17:27:26 +0200
parents c931ac02db82
children f27923072afd
comparison
equal deleted inserted replaced
612:fdd5f7f9c4d7 613:60d90e48e809
39 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" 39 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h"
40 #include "../Core/HttpServer/FilesystemHttpHandler.h" 40 #include "../Core/HttpServer/FilesystemHttpHandler.h"
41 #include "../Core/Lua/LuaFunctionCall.h" 41 #include "../Core/Lua/LuaFunctionCall.h"
42 #include "../Core/DicomFormat/DicomArray.h" 42 #include "../Core/DicomFormat/DicomArray.h"
43 #include "DicomProtocol/DicomServer.h" 43 #include "DicomProtocol/DicomServer.h"
44 #include "DicomProtocol/DicomUserConnection.h"
44 #include "OrthancInitialization.h" 45 #include "OrthancInitialization.h"
45 #include "ServerContext.h" 46 #include "ServerContext.h"
46 #include "OrthancFindRequestHandler.h" 47 #include "OrthancFindRequestHandler.h"
47 48
48 using namespace Orthanc; 49 using namespace Orthanc;
49 50
50 51
51 52
52 class MyStoreRequestHandler : public IStoreRequestHandler 53 class OrthancStoreRequestHandler : public IStoreRequestHandler
53 { 54 {
54 private: 55 private:
55 ServerContext& server_; 56 ServerContext& server_;
56 57
57 public: 58 public:
58 MyStoreRequestHandler(ServerContext& context) : 59 OrthancStoreRequestHandler(ServerContext& context) :
59 server_(context) 60 server_(context)
60 { 61 {
61 } 62 }
62 63
63 virtual void Handle(const std::string& dicomFile, 64 virtual void Handle(const std::string& dicomFile,
71 } 72 }
72 } 73 }
73 }; 74 };
74 75
75 76
76 class MyMoveRequestHandler : public IMoveRequestHandler 77
78 class OrthancMoveRequestIterator : public IMoveRequestIterator
77 { 79 {
78 private: 80 private:
79 ServerContext& context_; 81 ServerContext& context_;
82 std::vector<std::string> instances_;
83 DicomUserConnection connection_;
84 size_t position_;
80 85
81 public: 86 public:
82 MyMoveRequestHandler(ServerContext& context) : 87 OrthancMoveRequestIterator(ServerContext& context,
88 const std::string& target,
89 const std::string& publicId) :
90 context_(context),
91 position_(0)
92 {
93 LOG(INFO) << "Sending resource " << publicId << " to modality \"" << target << "\"";
94
95 std::list<std::string> tmp;
96 context_.GetIndex().GetChildInstances(tmp, publicId);
97
98 instances_.reserve(tmp.size());
99 for (std::list<std::string>::iterator it = tmp.begin(); it != tmp.end(); it++)
100 {
101 instances_.push_back(*it);
102 }
103
104 ConnectToModalityUsingAETitle(connection_, target);
105 }
106
107 virtual unsigned int GetSubOperationCount() const
108 {
109 return instances_.size();
110 }
111
112 virtual Status DoNext()
113 {
114 if (position_ >= instances_.size())
115 {
116 return Status_Failure;
117 }
118
119 const std::string& id = instances_[position_++];
120
121 std::string dicom;
122 context_.ReadFile(dicom, id, FileContentType_Dicom);
123 connection_.Store(dicom);
124
125 return Status_Success;
126 }
127 };
128
129
130
131 class OrthancMoveRequestHandler : public IMoveRequestHandler
132 {
133 private:
134 ServerContext& context_;
135
136 bool LookupResource(std::string& publicId,
137 DicomTag tag,
138 const DicomMap& input)
139 {
140 if (!input.HasTag(tag))
141 {
142 return false;
143 }
144
145 std::string value = input.GetValue(tag).AsString();
146
147 std::list<std::string> ids;
148 context_.GetIndex().LookupTagValue(ids, tag, value);
149
150 if (ids.size() != 1)
151 {
152 return false;
153 }
154 else
155 {
156 publicId = ids.front();
157 return true;
158 }
159 }
160
161 public:
162 OrthancMoveRequestHandler(ServerContext& context) :
83 context_(context) 163 context_(context)
84 { 164 {
85 } 165 }
86 166
87 public: 167 public:
88 virtual IMoveRequestIterator* Handle(const std::string& target, 168 virtual IMoveRequestIterator* Handle(const std::string& target,
89 const DicomMap& input) 169 const DicomMap& input)
90 { 170 {
91 LOG(WARNING) << "Move-SCU request received"; 171 LOG(WARNING) << "Move-SCU request received for AET \"" << target << "\"";
92 return NULL; 172
173
174 /**
175 * Retrieve the query level.
176 **/
177
178 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL);
179 if (levelTmp == NULL)
180 {
181 throw OrthancException(ErrorCode_BadRequest);
182 }
183
184 ResourceType level = StringToResourceType(levelTmp->AsString().c_str());
185
186
187 /**
188 * Lookup for the resource to be sent.
189 **/
190
191 bool ok;
192 std::string publicId;
193
194 switch (level)
195 {
196 case ResourceType_Patient:
197 ok = LookupResource(publicId, DICOM_TAG_PATIENT_ID, input);
198 break;
199
200 case ResourceType_Study:
201 ok = LookupResource(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input);
202 break;
203
204 case ResourceType_Series:
205 ok = LookupResource(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input);
206 break;
207
208 case ResourceType_Instance:
209 ok = LookupResource(publicId, DICOM_TAG_SOP_INSTANCE_UID, input);
210 break;
211
212 default:
213 ok = false;
214 }
215
216 if (!ok)
217 {
218 throw OrthancException(ErrorCode_BadRequest);
219 }
220
221 return new OrthancMoveRequestIterator(context_, target, publicId);
93 } 222 }
94 }; 223 };
95 224
96 225
97 class MyDicomServerFactory : 226 class MyDicomServerFactory :
107 { 236 {
108 } 237 }
109 238
110 virtual IStoreRequestHandler* ConstructStoreRequestHandler() 239 virtual IStoreRequestHandler* ConstructStoreRequestHandler()
111 { 240 {
112 return new MyStoreRequestHandler(context_); 241 return new OrthancStoreRequestHandler(context_);
113 } 242 }
114 243
115 virtual IFindRequestHandler* ConstructFindRequestHandler() 244 virtual IFindRequestHandler* ConstructFindRequestHandler()
116 { 245 {
117 return new OrthancFindRequestHandler(context_); 246 return new OrthancFindRequestHandler(context_);
118 } 247 }
119 248
120 virtual IMoveRequestHandler* ConstructMoveRequestHandler() 249 virtual IMoveRequestHandler* ConstructMoveRequestHandler()
121 { 250 {
122 return new MyMoveRequestHandler(context_); 251 return new OrthancMoveRequestHandler(context_);
123 } 252 }
124 253
125 void Done() 254 void Done()
126 { 255 {
127 } 256 }