Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi2.cpp @ 226:8a26a8e85edf
refactoring to read files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 09:45:29 +0100 |
parents | 03aa59ecf6d8 |
children | 209ca3f6db62 |
comparison
equal
deleted
inserted
replaced
225:03aa59ecf6d8 | 226:8a26a8e85edf |
---|---|
43 #include <boost/lexical_cast.hpp> | 43 #include <boost/lexical_cast.hpp> |
44 #include <glog/logging.h> | 44 #include <glog/logging.h> |
45 | 45 |
46 | 46 |
47 #define RETRIEVE_CONTEXT(call) \ | 47 #define RETRIEVE_CONTEXT(call) \ |
48 OrthancRestApi2& contextApi = dynamic_cast<OrthancRestApi2&>(call.GetContext()); \ | 48 OrthancRestApi2& contextApi = \ |
49 dynamic_cast<OrthancRestApi2&>(call.GetContext()); \ | |
49 ServerContext& context = contextApi.GetContext() | 50 ServerContext& context = contextApi.GetContext() |
50 | 51 |
51 | 52 |
52 namespace Orthanc | 53 namespace Orthanc |
53 { | 54 { |
148 | 149 |
149 static void GetInstanceFile(RestApi::GetCall& call) | 150 static void GetInstanceFile(RestApi::GetCall& call) |
150 { | 151 { |
151 RETRIEVE_CONTEXT(call); | 152 RETRIEVE_CONTEXT(call); |
152 | 153 |
153 CompressionType compressionType; | |
154 std::string fileUuid; | |
155 std::string publicId = call.GetUriComponent("id", ""); | 154 std::string publicId = call.GetUriComponent("id", ""); |
156 | 155 context.AnswerFile(call.GetOutput(), publicId, AttachedFileType_Dicom); |
157 if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Dicom)) | |
158 { | |
159 assert(compressionType == CompressionType_None); | |
160 | |
161 FilesystemHttpSender sender(context.GetFileStorage(), fileUuid); | |
162 sender.SetDownloadFilename(fileUuid + ".dcm"); | |
163 sender.SetContentType("application/dicom"); | |
164 call.GetOutput().AnswerFile(sender); | |
165 } | |
166 } | 156 } |
167 | 157 |
168 | 158 |
169 template <bool simplify> | 159 template <bool simplify> |
170 static void GetInstanceTags(RestApi::GetCall& call) | 160 static void GetInstanceTags(RestApi::GetCall& call) |
171 { | 161 { |
172 RETRIEVE_CONTEXT(call); | 162 RETRIEVE_CONTEXT(call); |
173 | 163 |
174 CompressionType compressionType; | |
175 std::string fileUuid; | |
176 std::string publicId = call.GetUriComponent("id", ""); | 164 std::string publicId = call.GetUriComponent("id", ""); |
177 | 165 |
178 if (context.GetIndex().GetFile(fileUuid, compressionType, publicId, AttachedFileType_Json)) | 166 Json::Value full; |
179 { | 167 context.ReadJson(full, publicId); |
180 assert(compressionType == CompressionType_None); | 168 |
181 | 169 if (simplify) |
182 Json::Value full; | 170 { |
183 ReadJson(full, context.GetFileStorage(), fileUuid); | 171 Json::Value simplified; |
184 | 172 SimplifyTags(simplified, full); |
185 if (simplify) | 173 call.GetOutput().AnswerJson(simplified); |
186 { | 174 } |
187 Json::Value simplified; | 175 else |
188 SimplifyTags(simplified, full); | 176 { |
189 call.GetOutput().AnswerJson(simplified); | 177 call.GetOutput().AnswerJson(full); |
190 } | |
191 else | |
192 { | |
193 call.GetOutput().AnswerJson(full); | |
194 } | |
195 } | 178 } |
196 } | 179 } |
197 | 180 |
198 | 181 |
199 static void ListFrames(RestApi::GetCall& call) | 182 static void ListFrames(RestApi::GetCall& call) |
257 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, mode); | 240 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, mode); |
258 call.GetOutput().AnswerBuffer(png, "image/png"); | 241 call.GetOutput().AnswerBuffer(png, "image/png"); |
259 } | 242 } |
260 catch (OrthancException& e) | 243 catch (OrthancException& e) |
261 { | 244 { |
262 //if (e.GetErrorCode() == ErrorCode_NotImplemented) | 245 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange) |
246 { | |
247 // The frame number is out of the range for this DICOM | |
248 // instance, the resource is not existent | |
249 } | |
250 else | |
263 { | 251 { |
264 std::string root = ""; | 252 std::string root = ""; |
265 for (size_t i = 1; i < call.GetFullUri().size(); i++) | 253 for (size_t i = 1; i < call.GetFullUri().size(); i++) |
266 { | 254 { |
267 root += "../"; | 255 root += "../"; |