Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi.cpp @ 62:a70bb32802ae orthanc-renaming
renaming Server
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:33:19 +0200 |
parents | 6da7fc87efaa |
children | b8dfde8d64e8 |
comparison
equal
deleted
inserted
replaced
61:d1c511efd6b1 | 62:a70bb32802ae |
---|---|
1 /** | 1 /** |
2 * Palanthir - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 6 * This program is free software: you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License as | 7 * modify it under the terms of the GNU General Public License as |
16 * You should have received a copy of the GNU General Public License | 16 * You should have received a copy of the GNU General Public License |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 **/ | 18 **/ |
19 | 19 |
20 | 20 |
21 #include "PalanthirRestApi.h" | 21 #include "OrthancRestApi.h" |
22 | 22 |
23 #include "PalanthirInitialization.h" | 23 #include "OrthancInitialization.h" |
24 #include "FromDcmtkBridge.h" | 24 #include "FromDcmtkBridge.h" |
25 #include "../Core/Uuid.h" | 25 #include "../Core/Uuid.h" |
26 | 26 |
27 #include <dcmtk/dcmdata/dcistrmb.h> | 27 #include <dcmtk/dcmdata/dcistrmb.h> |
28 #include <dcmtk/dcmdata/dcfilefo.h> | 28 #include <dcmtk/dcmdata/dcfilefo.h> |
29 #include <boost/lexical_cast.hpp> | 29 #include <boost/lexical_cast.hpp> |
30 | 30 |
31 namespace Palanthir | 31 namespace Orthanc |
32 { | 32 { |
33 static void SendJson(HttpOutput& output, | 33 static void SendJson(HttpOutput& output, |
34 const Json::Value& value) | 34 const Json::Value& value) |
35 { | 35 { |
36 Json::StyledWriter writer; | 36 Json::StyledWriter writer; |
94 | 94 |
95 Json::Value source; | 95 Json::Value source; |
96 Json::Reader reader; | 96 Json::Reader reader; |
97 if (!reader.parse(s, source)) | 97 if (!reader.parse(s, source)) |
98 { | 98 { |
99 throw PalanthirException("Corrupted JSON file"); | 99 throw OrthancException("Corrupted JSON file"); |
100 } | 100 } |
101 | 101 |
102 SimplifyTagsRecursion(target, source); | 102 SimplifyTagsRecursion(target, source); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 bool PalanthirRestApi::Store(Json::Value& result, | 106 bool OrthancRestApi::Store(Json::Value& result, |
107 const std::string& postData) | 107 const std::string& postData) |
108 { | 108 { |
109 // Prepare an input stream for the memory buffer | 109 // Prepare an input stream for the memory buffer |
110 DcmInputBufferStream is; | 110 DcmInputBufferStream is; |
111 if (postData.size() > 0) | 111 if (postData.size() > 0) |
154 } | 154 } |
155 | 155 |
156 return false; | 156 return false; |
157 } | 157 } |
158 | 158 |
159 void PalanthirRestApi::ConnectToModality(DicomUserConnection& c, | 159 void OrthancRestApi::ConnectToModality(DicomUserConnection& c, |
160 const std::string& name) | 160 const std::string& name) |
161 { | 161 { |
162 std::string aet, address; | 162 std::string aet, address; |
163 int port; | 163 int port; |
164 GetDicomModality(name, aet, address, port); | 164 GetDicomModality(name, aet, address, port); |
165 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "PALANTHIR")); | 165 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
166 c.SetDistantApplicationEntityTitle(aet); | 166 c.SetDistantApplicationEntityTitle(aet); |
167 c.SetDistantHost(address); | 167 c.SetDistantHost(address); |
168 c.SetDistantPort(port); | 168 c.SetDistantPort(port); |
169 c.Open(); | 169 c.Open(); |
170 } | 170 } |
171 | 171 |
172 bool PalanthirRestApi::MergeQueryAndTemplate(DicomMap& result, | 172 bool OrthancRestApi::MergeQueryAndTemplate(DicomMap& result, |
173 const std::string& postData) | 173 const std::string& postData) |
174 { | 174 { |
175 Json::Value query; | 175 Json::Value query; |
176 Json::Reader reader; | 176 Json::Reader reader; |
177 | 177 |
189 } | 189 } |
190 | 190 |
191 return true; | 191 return true; |
192 } | 192 } |
193 | 193 |
194 bool PalanthirRestApi::DicomFindPatient(Json::Value& result, | 194 bool OrthancRestApi::DicomFindPatient(Json::Value& result, |
195 DicomUserConnection& c, | 195 DicomUserConnection& c, |
196 const std::string& postData) | 196 const std::string& postData) |
197 { | 197 { |
198 DicomMap m; | 198 DicomMap m; |
199 DicomMap::SetupFindPatientTemplate(m); | 199 DicomMap::SetupFindPatientTemplate(m); |
206 c.FindPatient(answers, m); | 206 c.FindPatient(answers, m); |
207 answers.ToJson(result); | 207 answers.ToJson(result); |
208 return true; | 208 return true; |
209 } | 209 } |
210 | 210 |
211 bool PalanthirRestApi::DicomFindStudy(Json::Value& result, | 211 bool OrthancRestApi::DicomFindStudy(Json::Value& result, |
212 DicomUserConnection& c, | 212 DicomUserConnection& c, |
213 const std::string& postData) | 213 const std::string& postData) |
214 { | 214 { |
215 DicomMap m; | 215 DicomMap m; |
216 DicomMap::SetupFindStudyTemplate(m); | 216 DicomMap::SetupFindStudyTemplate(m); |
229 c.FindStudy(answers, m); | 229 c.FindStudy(answers, m); |
230 answers.ToJson(result); | 230 answers.ToJson(result); |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 bool PalanthirRestApi::DicomFindSeries(Json::Value& result, | 234 bool OrthancRestApi::DicomFindSeries(Json::Value& result, |
235 DicomUserConnection& c, | 235 DicomUserConnection& c, |
236 const std::string& postData) | 236 const std::string& postData) |
237 { | 237 { |
238 DicomMap m; | 238 DicomMap m; |
239 DicomMap::SetupFindSeriesTemplate(m); | 239 DicomMap::SetupFindSeriesTemplate(m); |
253 c.FindSeries(answers, m); | 253 c.FindSeries(answers, m); |
254 answers.ToJson(result); | 254 answers.ToJson(result); |
255 return true; | 255 return true; |
256 } | 256 } |
257 | 257 |
258 bool PalanthirRestApi::DicomFind(Json::Value& result, | 258 bool OrthancRestApi::DicomFind(Json::Value& result, |
259 DicomUserConnection& c, | 259 DicomUserConnection& c, |
260 const std::string& postData) | 260 const std::string& postData) |
261 { | 261 { |
262 DicomMap m; | 262 DicomMap m; |
263 DicomMap::SetupFindPatientTemplate(m); | 263 DicomMap::SetupFindPatientTemplate(m); |
323 return true; | 323 return true; |
324 } | 324 } |
325 | 325 |
326 | 326 |
327 | 327 |
328 bool PalanthirRestApi::DicomStore(Json::Value& result, | 328 bool OrthancRestApi::DicomStore(Json::Value& result, |
329 DicomUserConnection& c, | 329 DicomUserConnection& c, |
330 const std::string& postData) | 330 const std::string& postData) |
331 { | 331 { |
332 Json::Value found(Json::objectValue); | 332 Json::Value found(Json::objectValue); |
333 | 333 |
369 | 369 |
370 return true; | 370 return true; |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 PalanthirRestApi::PalanthirRestApi(ServerIndex& index, | 374 OrthancRestApi::OrthancRestApi(ServerIndex& index, |
375 const std::string& path) : | 375 const std::string& path) : |
376 index_(index), | 376 index_(index), |
377 storage_(path) | 377 storage_(path) |
378 { | 378 { |
379 GetListOfDicomModalities(modalities_); | 379 GetListOfDicomModalities(modalities_); |
380 } | 380 } |
381 | 381 |
382 | 382 |
383 void PalanthirRestApi::Handle( | 383 void OrthancRestApi::Handle( |
384 HttpOutput& output, | 384 HttpOutput& output, |
385 const std::string& method, | 385 const std::string& method, |
386 const UriComponents& uri, | 386 const UriComponents& uri, |
387 const Arguments& headers, | 387 const Arguments& headers, |
388 const Arguments& arguments, | 388 const Arguments& arguments, |
424 SendJson(output, result); | 424 SendJson(output, result); |
425 return; | 425 return; |
426 } | 426 } |
427 else | 427 else |
428 { | 428 { |
429 output.SendHeader(Palanthir_HttpStatus_415_UnsupportedMediaType); | 429 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType); |
430 return; | 430 return; |
431 } | 431 } |
432 } | 432 } |
433 else | 433 else |
434 { | 434 { |
645 { | 645 { |
646 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16); | 646 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16); |
647 } | 647 } |
648 else | 648 else |
649 { | 649 { |
650 throw PalanthirException(ErrorCode_InternalError); | 650 throw OrthancException(ErrorCode_InternalError); |
651 } | 651 } |
652 | 652 |
653 output.AnswerBufferWithContentType(png, "image/png"); | 653 output.AnswerBufferWithContentType(png, "image/png"); |
654 return; | 654 return; |
655 } | 655 } |
656 catch (PalanthirException&) | 656 catch (OrthancException&) |
657 { | 657 { |
658 output.Redirect("/app/images/Unsupported.png"); | 658 output.Redirect("/app/images/Unsupported.png"); |
659 return; | 659 return; |
660 } | 660 } |
661 } | 661 } |
679 since = boost::lexical_cast<int64_t>(GetArgument(arguments, "since", "0")); | 679 since = boost::lexical_cast<int64_t>(GetArgument(arguments, "since", "0")); |
680 limit = boost::lexical_cast<unsigned int>(GetArgument(arguments, "limit", "0")); | 680 limit = boost::lexical_cast<unsigned int>(GetArgument(arguments, "limit", "0")); |
681 } | 681 } |
682 catch (boost::bad_lexical_cast) | 682 catch (boost::bad_lexical_cast) |
683 { | 683 { |
684 output.SendHeader(Palanthir_HttpStatus_400_BadRequest); | 684 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
685 return; | 685 return; |
686 } | 686 } |
687 | 687 |
688 if (limit == 0 || limit > MAX_RESULTS) | 688 if (limit == 0 || limit > MAX_RESULTS) |
689 { | 689 { |
690 limit = MAX_RESULTS; | 690 limit = MAX_RESULTS; |
691 } | 691 } |
692 | 692 |
693 if (!index_.GetChanges(result, since, filter, limit)) | 693 if (!index_.GetChanges(result, since, filter, limit)) |
694 { | 694 { |
695 output.SendHeader(Palanthir_HttpStatus_400_BadRequest); | 695 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
696 return; | 696 return; |
697 } | 697 } |
698 | 698 |
699 existingResource = true; | 699 existingResource = true; |
700 } | 700 } |
780 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) || | 780 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) || |
781 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) || | 781 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) || |
782 (uri[2] == "find" && !DicomFind(result, connection, postData)) || | 782 (uri[2] == "find" && !DicomFind(result, connection, postData)) || |
783 (uri[2] == "store" && !DicomStore(result, connection, postData))) | 783 (uri[2] == "store" && !DicomStore(result, connection, postData))) |
784 { | 784 { |
785 output.SendHeader(Palanthir_HttpStatus_400_BadRequest); | 785 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
786 return; | 786 return; |
787 } | 787 } |
788 } | 788 } |
789 } | 789 } |
790 } | 790 } |
794 { | 794 { |
795 SendJson(output, result); | 795 SendJson(output, result); |
796 } | 796 } |
797 else | 797 else |
798 { | 798 { |
799 output.SendHeader(Palanthir_HttpStatus_404_NotFound); | 799 output.SendHeader(Orthanc_HttpStatus_404_NotFound); |
800 } | 800 } |
801 } | 801 } |
802 } | 802 } |