annotate OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4055:9214e3a7b0a2 framework

moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 12:52:09 +0200
parents 05b8fd21089c
children d6362b2c4b61
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1281
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3601
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
34 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 #include "../../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
39 #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
40 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
41 #include "../../../OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
42 #include "../../../OrthancFramework/Sources/HttpServer/HttpContentNegociation.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
43 #include "../../../OrthancFramework/Sources/Images/Image.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
44 #include "../../../OrthancFramework/Sources/Images/ImageProcessing.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
45 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
46 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
47
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
48 #include "../OrthancConfiguration.h"
3094
61da3c9b4121 cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3085
diff changeset
49 #include "../Search/DatabaseLookup.h"
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1385
diff changeset
50 #include "../ServerContext.h"
2131
bb199bccdc45 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
51 #include "../ServerToolbox.h"
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
52 #include "../SliceOrdering.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
3085
c829758b9ca0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3061
diff changeset
54 #include "../../Plugins/Engine/OrthancPlugins.h"
c829758b9ca0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3061
diff changeset
55
3687
e6d6f8d23d02 fix linking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3686
diff changeset
56 // This "include" is mandatory for Release builds using Linux Standard Base
e6d6f8d23d02 fix linking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3686
diff changeset
57 #include <boost/math/special_functions/round.hpp>
e6d6f8d23d02 fix linking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3686
diff changeset
58
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
60 /**
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
61 * This semaphore is used to limit the number of concurrent HTTP
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
62 * requests on CPU-intensive routes of the REST API, in order to
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
63 * prevent exhaustion of resources (new in Orthanc 1.7.0).
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
64 **/
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
65 static Orthanc::Semaphore throttlingSemaphore_(4); // TODO => PARAMETER?
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
66
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
67
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
70 static void AnswerDicomAsJson(RestApiCall& call,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
71 const Json::Value& dicom,
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
72 DicomToJsonFormat mode)
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
73 {
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
74 if (mode != DicomToJsonFormat_Full)
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
75 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
76 Json::Value simplified;
4055
9214e3a7b0a2 moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
77 Toolbox::SimplifyDicomAsJson(simplified, dicom, mode);
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
78 call.GetOutput().AnswerJson(simplified);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
79 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
80 else
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
81 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
82 call.GetOutput().AnswerJson(dicom);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
83 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
84 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
85
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
86
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
87 static DicomToJsonFormat GetDicomFormat(const RestApiGetCall& call)
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
88 {
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
89 if (call.HasArgument("simplify"))
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
90 {
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
91 return DicomToJsonFormat_Human;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
92 }
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
93 else if (call.HasArgument("short"))
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
94 {
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
95 return DicomToJsonFormat_Short;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
96 }
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
97 else
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
98 {
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
99 return DicomToJsonFormat_Full;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
100 }
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
101 }
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
102
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
103
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
104 static void AnswerDicomAsJson(RestApiGetCall& call,
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
105 const Json::Value& dicom)
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
106 {
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
107 AnswerDicomAsJson(call, dicom, GetDicomFormat(call));
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
108 }
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
109
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
110
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
111 static void ParseSetOfTags(std::set<DicomTag>& target,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
112 const RestApiGetCall& call,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
113 const std::string& argument)
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
114 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
115 target.clear();
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
116
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
117 if (call.HasArgument(argument))
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
118 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
119 std::vector<std::string> tags;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
120 Toolbox::TokenizeString(tags, call.GetArgument(argument, ""), ',');
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
121
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
122 for (size_t i = 0; i < tags.size(); i++)
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
123 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
124 target.insert(FromDcmtkBridge::ParseTag(tags[i]));
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
125 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
126 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
127 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
128
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
129
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 // List all the patients, studies, series or instances ----------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
132 static void AnswerListOfResources(RestApiOutput& output,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
133 ServerIndex& index,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
134 const std::list<std::string>& resources,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
135 ResourceType level,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
136 bool expand)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
137 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
138 Json::Value answer = Json::arrayValue;
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
139
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
140 for (std::list<std::string>::const_iterator
1384
d6971e18a324 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1374
diff changeset
141 resource = resources.begin(); resource != resources.end(); ++resource)
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
142 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
143 if (expand)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
144 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
145 Json::Value item;
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
146 if (index.LookupResource(item, *resource, level))
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
147 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
148 answer.append(item);
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
149 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
150 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
151 else
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
152 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
153 answer.append(*resource);
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
154 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
155 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
156
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
157 output.AnswerJson(answer);
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
158 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
159
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
160
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
162 static void ListResources(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
1342
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
164 ServerIndex& index = OrthancRestApi::GetIndex(call);
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
165
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
166 std::list<std::string> result;
1509
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
167
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
168 if (call.HasArgument("limit") ||
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
169 call.HasArgument("since"))
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
170 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
171 if (!call.HasArgument("limit"))
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
172 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
173 throw OrthancException(ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
174 "Missing \"limit\" argument for GET request against: " +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
175 call.FlattenUri());
1509
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
176 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
177
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
178 if (!call.HasArgument("since"))
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
179 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
180 throw OrthancException(ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
181 "Missing \"since\" argument for GET request against: " +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
182 call.FlattenUri());
1509
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
183 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
184
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
185 size_t since = boost::lexical_cast<size_t>(call.GetArgument("since", ""));
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
186 size_t limit = boost::lexical_cast<size_t>(call.GetArgument("limit", ""));
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
187 index.GetAllUuids(result, resourceType, since, limit);
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
188 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
189 else
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
190 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
191 index.GetAllUuids(result, resourceType);
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
192 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
193
1342
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
194
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
195 AnswerListOfResources(call.GetOutput(), index, result, resourceType, call.HasArgument("expand"));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
199 static void GetSingleResource(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
209 static void DeleteSingleResource(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 Json::Value result;
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1140
diff changeset
212 if (OrthancRestApi::GetContext(call).DeleteResource(result, call.GetUriComponent("id", ""), resourceType))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 // Get information about a single patient -----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
221 static void IsProtectedPatient(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
225 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
229 static void SetPatientProtection(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
235 std::string body;
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
236 call.BodyToString(body);
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
237 body = Toolbox::StripSpaces(body);
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
238
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
239 if (body == "0")
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 context.GetIndex().SetProtectedPatient(publicId, false);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
242 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
244 else if (body == "1")
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 context.GetIndex().SetProtectedPatient(publicId, true);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
247 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 // Bad request
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 // Get information about a single instance ----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
258 static void GetInstanceFile(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 std::string publicId = call.GetUriComponent("id", "");
3203
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
263
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
264 IHttpHandler::Arguments::const_iterator accept = call.GetHttpHeaders().find("accept");
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
265 if (accept != call.GetHttpHeaders().end())
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
266 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
267 // New in Orthanc 1.5.4
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
268 try
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
269 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
270 MimeType mime = StringToMimeType(accept->second.c_str());
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
271
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
272 if (mime == MimeType_DicomWebJson ||
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
273 mime == MimeType_DicomWebXml)
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
274 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
275 DicomWebJsonVisitor visitor;
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
276
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
277 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
278 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
279 locker.GetDicom().Apply(visitor);
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
280 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
281
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
282 if (mime == MimeType_DicomWebJson)
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
283 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
284 std::string s = visitor.GetResult().toStyledString();
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
285 call.GetOutput().AnswerBuffer(s, MimeType_DicomWebJson);
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
286 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
287 else
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
288 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
289 std::string xml;
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
290 visitor.FormatXml(xml);
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
291 call.GetOutput().AnswerBuffer(xml, MimeType_DicomWebXml);
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
292 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
293
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
294 return;
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
295 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
296 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
297 catch (OrthancException&)
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
298 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
299 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
300 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
301
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
302 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
306 static void ExportInstanceFile(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 std::string dicom;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
313 context.ReadDicom(dicom, publicId);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
315 std::string target;
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
316 call.BodyToString(target);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
317 SystemToolbox::WriteFile(dicom, target);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
319 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
323 template <DicomToJsonFormat format>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
324 static void GetInstanceTags(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 std::string publicId = call.GetUriComponent("id", "");
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
329
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
330 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
331 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
333 if (format != DicomToJsonFormat_Full ||
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
334 !ignoreTagLength.empty())
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
336 Json::Value full;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
337 context.ReadDicomAsJson(full, publicId, ignoreTagLength);
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
338 AnswerDicomAsJson(call, full, format);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
3973
d86bddb50972 fix spelling errors according to debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3928
diff changeset
342 // This path allows one to avoid the JSON decoding if no
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
343 // simplification is asked, and if no "ignore-length" argument
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
344 // is present
2127
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
345 std::string full;
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
346 context.ReadDicomAsJson(full, publicId);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
347 call.GetOutput().AnswerBuffer(full, MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
351
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
352 static void GetInstanceTagsBis(RestApiGetCall& call)
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
353 {
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
354 switch (GetDicomFormat(call))
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
355 {
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
356 case DicomToJsonFormat_Human:
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
357 GetInstanceTags<DicomToJsonFormat_Human>(call);
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
358 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
359
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
360 case DicomToJsonFormat_Short:
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
361 GetInstanceTags<DicomToJsonFormat_Short>(call);
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
362 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
363
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
364 case DicomToJsonFormat_Full:
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
365 GetInstanceTags<DicomToJsonFormat_Full>(call);
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
366 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
367
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
368 default:
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
369 throw OrthancException(ErrorCode_InternalError);
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
370 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
371 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
372
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
374 static void ListFrames(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
376 std::string publicId = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
378 unsigned int numberOfFrames;
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
379
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
380 {
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
381 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
382 numberOfFrames = locker.GetDicom().GetFramesCount();
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
384
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
385 Json::Value result = Json::arrayValue;
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
386 for (unsigned int i = 0; i < numberOfFrames; i++)
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
387 {
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
388 result.append(i);
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
389 }
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
390
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
391 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
395 namespace
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
396 {
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
397 class ImageToEncode
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
398 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
399 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
400 std::unique_ptr<ImageAccessor>& image_;
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
401 ImageExtractionMode mode_;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
402 bool invert_;
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
403 MimeType format_;
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
404 std::string answer_;
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
405
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
406 public:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
407 ImageToEncode(std::unique_ptr<ImageAccessor>& image,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
408 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
409 bool invert) :
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
410 image_(image),
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
411 mode_(mode),
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
412 invert_(invert)
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
413 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
414 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
415
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
416 void Answer(RestApiOutput& output)
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
417 {
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
418 output.AnswerBuffer(answer_, format_);
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
419 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
420
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
421 void EncodeUsingPng()
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
422 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
423 format_ = MimeType_Png;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
424 DicomImageDecoder::ExtractPngImage(answer_, image_, mode_, invert_);
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
425 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
426
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
427 void EncodeUsingPam()
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
428 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
429 format_ = MimeType_Pam;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
430 DicomImageDecoder::ExtractPamImage(answer_, image_, mode_, invert_);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
431 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
432
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
433 void EncodeUsingJpeg(uint8_t quality)
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
434 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
435 format_ = MimeType_Jpeg;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
436 DicomImageDecoder::ExtractJpegImage(answer_, image_, mode_, invert_, quality);
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1784
diff changeset
437 }
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
438 };
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
439
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
440 class EncodePng : public HttpContentNegociation::IHandler
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
441 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
442 private:
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
443 ImageToEncode& image_;
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
444
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
445 public:
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
446 EncodePng(ImageToEncode& image) : image_(image)
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
447 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
448 }
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
449
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
450 virtual void Handle(const std::string& type,
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
451 const std::string& subtype)
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
452 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
453 assert(type == "image");
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
454 assert(subtype == "png");
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
455 image_.EncodeUsingPng();
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
456 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
457 };
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
458
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
459 class EncodePam : public HttpContentNegociation::IHandler
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
460 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
461 private:
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
462 ImageToEncode& image_;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
463
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
464 public:
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
465 EncodePam(ImageToEncode& image) : image_(image)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
466 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
467 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
468
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
469 virtual void Handle(const std::string& type,
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
470 const std::string& subtype)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
471 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
472 assert(type == "image");
2780
am@osimis.io
parents: 2726
diff changeset
473 assert(subtype == "x-portable-arbitrarymap");
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
474 image_.EncodeUsingPam();
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
475 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
476 };
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
477
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
478 class EncodeJpeg : public HttpContentNegociation::IHandler
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
479 {
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
480 private:
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
481 ImageToEncode& image_;
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
482 unsigned int quality_;
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
483
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
484 public:
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
485 EncodeJpeg(ImageToEncode& image,
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
486 const RestApiGetCall& call) :
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
487 image_(image)
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
488 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
489 std::string v = call.GetArgument("quality", "90" /* default JPEG quality */);
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
490 bool ok = false;
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
491
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
492 try
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
493 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
494 quality_ = boost::lexical_cast<unsigned int>(v);
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
495 ok = (quality_ >= 1 && quality_ <= 100);
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
496 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
497 catch (boost::bad_lexical_cast&)
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
498 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
499 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
500
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
501 if (!ok)
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
502 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
503 throw OrthancException(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
504 ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
505 "Bad quality for a JPEG encoding (must be a number between 0 and 100): " + v);
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
506 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
507 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
508
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
509 virtual void Handle(const std::string& type,
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
510 const std::string& subtype)
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
511 {
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
512 assert(type == "image");
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
513 assert(subtype == "jpeg");
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
514 image_.EncodeUsingJpeg(quality_);
1784
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
515 }
2dbf25006f88 ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1781
diff changeset
516 };
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
517 }
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
518
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
519
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
520 namespace
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
521 {
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
522 class IDecodedFrameHandler : public boost::noncopyable
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
523 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
524 public:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
525 virtual ~IDecodedFrameHandler()
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
526 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
527 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
528
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
529 virtual void Handle(RestApiGetCall& call,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
530 std::unique_ptr<ImageAccessor>& decoded,
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
531 const DicomMap& dicom) = 0;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
532
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
533 virtual bool RequiresDicomTags() const = 0;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
534
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
535 static void Apply(RestApiGetCall& call,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
536 IDecodedFrameHandler& handler)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
537 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
538 ServerContext& context = OrthancRestApi::GetContext(call);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
539
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
540 std::string frameId = call.GetUriComponent("frame", "0");
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
541
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
542 unsigned int frame;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
543 try
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
544 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
545 frame = boost::lexical_cast<unsigned int>(frameId);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
546 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
547 catch (boost::bad_lexical_cast&)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
548 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
549 return;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
550 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
551
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
552 DicomMap dicom;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
553 std::unique_ptr<ImageAccessor> decoded;
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
554
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
555 try
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
556 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
557 std::string publicId = call.GetUriComponent("id", "");
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
558
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
559 decoded.reset(context.DecodeDicomFrame(publicId, frame));
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
560
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
561 if (decoded.get() == NULL)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
562 {
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
563 throw OrthancException(ErrorCode_NotImplemented,
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
564 "Cannot decode DICOM instance with ID: " + publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
565 }
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
566
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
567 if (handler.RequiresDicomTags())
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
568 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
569 /**
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
570 * Retrieve a summary of the DICOM tags, which is
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
571 * necessary to deal with MONOCHROME1 photometric
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
572 * interpretation, and with windowing parameters.
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
573 **/
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
574 ServerContext::DicomCacheLocker locker(context, publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
575 locker.GetDicom().ExtractDicomSummary(dicom);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
576 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
577 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
578 catch (OrthancException& e)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
579 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
580 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange ||
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
581 e.GetErrorCode() == ErrorCode_UnknownResource)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
582 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
583 // The frame number is out of the range for this DICOM
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
584 // instance, the resource is not existent
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
585 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
586 else
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
587 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
588 std::string root = "";
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
589 for (size_t i = 1; i < call.GetFullUri().size(); i++)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
590 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
591 root += "../";
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
592 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
593
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
594 call.GetOutput().Redirect(root + "app/images/unsupported.png");
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
595 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
596 return;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
597 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
598
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
599 handler.Handle(call, decoded, dicom);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
600 }
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
601
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
602
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
603 static void DefaultHandler(RestApiGetCall& call,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
604 std::unique_ptr<ImageAccessor>& decoded,
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
605 ImageExtractionMode mode,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
606 bool invert)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
607 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
608 ImageToEncode image(decoded, mode, invert);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
609
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
610 HttpContentNegociation negociation;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
611 EncodePng png(image);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
612 negociation.Register(MIME_PNG, png);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
613
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
614 EncodeJpeg jpeg(image, call);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
615 negociation.Register(MIME_JPEG, jpeg);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
616
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
617 EncodePam pam(image);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
618 negociation.Register(MIME_PAM, pam);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
619
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
620 if (negociation.Apply(call.GetHttpHeaders()))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
621 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
622 image.Answer(call.GetOutput());
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
623 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
624 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
625 };
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
626
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
627
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
628 class GetImageHandler : public IDecodedFrameHandler
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
629 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
630 private:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
631 ImageExtractionMode mode_;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
632
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
633 public:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
634 GetImageHandler(ImageExtractionMode mode) :
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
635 mode_(mode)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
636 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
637 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
638
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
639 virtual void Handle(RestApiGetCall& call,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
640 std::unique_ptr<ImageAccessor>& decoded,
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
641 const DicomMap& dicom) ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
642 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
643 bool invert = false;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
644
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
645 if (mode_ == ImageExtractionMode_Preview)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
646 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
647 DicomImageInformation info(dicom);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
648 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
649 }
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
650
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
651 DefaultHandler(call, decoded, mode_, invert);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
652 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
653
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
654 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
655 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
656 return mode_ == ImageExtractionMode_Preview;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
657 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
658 };
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
659
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
660
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
661 class RenderedFrameHandler : public IDecodedFrameHandler
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
662 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
663 private:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
664 static void GetDicomParameters(bool& invert,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
665 float& rescaleSlope,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
666 float& rescaleIntercept,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
667 float& windowWidth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
668 float& windowCenter,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
669 const DicomMap& dicom)
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
670 {
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
671 DicomImageInformation info(dicom);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
672
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
673 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
674
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
675 rescaleSlope = 1.0f;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
676 rescaleIntercept = 0.0f;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
677
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
678 if (dicom.HasTag(Orthanc::DICOM_TAG_RESCALE_SLOPE) &&
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
679 dicom.HasTag(Orthanc::DICOM_TAG_RESCALE_INTERCEPT))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
680 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
681 dicom.ParseFloat(rescaleSlope, Orthanc::DICOM_TAG_RESCALE_SLOPE);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
682 dicom.ParseFloat(rescaleIntercept, Orthanc::DICOM_TAG_RESCALE_INTERCEPT);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
683 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
684
3816
09f091b6b569 /rendered route: fix automatic windowing of files without windowing tags and RescaleSlope != 1
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
685 windowWidth = static_cast<float>(1 << info.GetBitsStored()) * rescaleSlope;
09f091b6b569 /rendered route: fix automatic windowing of files without windowing tags and RescaleSlope != 1
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
686 windowCenter = windowWidth / 2.0f + rescaleIntercept;
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
687
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
688 if (dicom.HasTag(Orthanc::DICOM_TAG_WINDOW_CENTER) &&
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
689 dicom.HasTag(Orthanc::DICOM_TAG_WINDOW_WIDTH))
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
690 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
691 dicom.ParseFirstFloat(windowCenter, Orthanc::DICOM_TAG_WINDOW_CENTER);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
692 dicom.ParseFirstFloat(windowWidth, Orthanc::DICOM_TAG_WINDOW_WIDTH);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
693 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
694 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
695
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
696 static void GetUserArguments(float& windowWidth /* inout */,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
697 float& windowCenter /* inout */,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
698 unsigned int& argWidth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
699 unsigned int& argHeight,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
700 bool& smooth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
701 RestApiGetCall& call)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
702 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
703 static const char* ARG_WINDOW_CENTER = "window-center";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
704 static const char* ARG_WINDOW_WIDTH = "window-width";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
705 static const char* ARG_WIDTH = "width";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
706 static const char* ARG_HEIGHT = "height";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
707 static const char* ARG_SMOOTH = "smooth";
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
708
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
709 if (call.HasArgument(ARG_WINDOW_WIDTH))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
710 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
711 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
712 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
713 windowWidth = boost::lexical_cast<float>(call.GetArgument(ARG_WINDOW_WIDTH, ""));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
714 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
715 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
716 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
717 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
718 "Bad value for argument: " + std::string(ARG_WINDOW_WIDTH));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
719 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
720 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
721
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
722 if (call.HasArgument(ARG_WINDOW_CENTER))
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
723 {
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
724 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
725 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
726 windowCenter = boost::lexical_cast<float>(call.GetArgument(ARG_WINDOW_CENTER, ""));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
727 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
728 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
729 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
730 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
731 "Bad value for argument: " + std::string(ARG_WINDOW_CENTER));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
732 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
733 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
734
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
735 argWidth = 0;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
736 argHeight = 0;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
737
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
738 if (call.HasArgument(ARG_WIDTH))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
739 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
740 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
741 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
742 int tmp = boost::lexical_cast<int>(call.GetArgument(ARG_WIDTH, ""));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
743 if (tmp < 0)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
744 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
745 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
746 "Argument cannot be negative: " + std::string(ARG_WIDTH));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
747 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
748 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
749 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
750 argWidth = static_cast<unsigned int>(tmp);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
751 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
752 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
753 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
754 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
755 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
756 "Bad value for argument: " + std::string(ARG_WIDTH));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
757 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
758 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
759
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
760 if (call.HasArgument(ARG_HEIGHT))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
761 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
762 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
763 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
764 int tmp = boost::lexical_cast<int>(call.GetArgument(ARG_HEIGHT, ""));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
765 if (tmp < 0)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
766 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
767 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
768 "Argument cannot be negative: " + std::string(ARG_HEIGHT));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
769 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
770 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
771 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
772 argHeight = static_cast<unsigned int>(tmp);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
773 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
774 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
775 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
776 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
777 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
778 "Bad value for argument: " + std::string(ARG_HEIGHT));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
779 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
780 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
781
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
782 smooth = false;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
783
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
784 if (call.HasArgument(ARG_SMOOTH))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
785 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
786 std::string value = call.GetArgument(ARG_SMOOTH, "");
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
787 if (value == "0" ||
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
788 value == "false")
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
789 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
790 smooth = false;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
791 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
792 else if (value == "1" ||
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
793 value == "true")
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
794 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
795 smooth = true;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
796 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
797 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
798 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
799 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
800 "Argument must be Boolean: " + std::string(ARG_SMOOTH));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
801 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
802 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
803 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
804
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
805
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
806 public:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
807 virtual void Handle(RestApiGetCall& call,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
808 std::unique_ptr<ImageAccessor>& decoded,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
809 const DicomMap& dicom) ORTHANC_OVERRIDE
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
810 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
811 bool invert;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
812 float rescaleSlope, rescaleIntercept, windowWidth, windowCenter;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
813 GetDicomParameters(invert, rescaleSlope, rescaleIntercept, windowWidth, windowCenter, dicom);
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
814
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
815 unsigned int argWidth, argHeight;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
816 bool smooth;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
817 GetUserArguments(windowWidth, windowCenter, argWidth, argHeight, smooth, call);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
818
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
819 unsigned int targetWidth = decoded->GetWidth();
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
820 unsigned int targetHeight = decoded->GetHeight();
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
821
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
822 if (decoded->GetWidth() != 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
823 decoded->GetHeight() != 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
824 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
825 float ratio = 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
826
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
827 if (argWidth != 0 &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
828 argHeight != 0)
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
829 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
830 float ratioX = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth());
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
831 float ratioY = static_cast<float>(argHeight) / static_cast<float>(decoded->GetHeight());
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
832 ratio = std::min(ratioX, ratioY);
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
833 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
834 else if (argWidth != 0)
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
835 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
836 ratio = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth());
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
837 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
838 else if (argHeight != 0)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
839 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
840 ratio = static_cast<float>(argHeight) / static_cast<float>(decoded->GetHeight());
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
841 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
842
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
843 targetWidth = boost::math::iround(ratio * static_cast<float>(decoded->GetWidth()));
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
844 targetHeight = boost::math::iround(ratio * static_cast<float>(decoded->GetHeight()));
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
845 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
846
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
847 if (decoded->GetFormat() == PixelFormat_RGB24)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
848 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
849 if (targetWidth == decoded->GetWidth() &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
850 targetHeight == decoded->GetHeight())
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
851 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
852 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
853 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
854 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
855 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
856 std::unique_ptr<ImageAccessor> resized(
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
857 new Image(decoded->GetFormat(), targetWidth, targetHeight, false));
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
858
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
859 if (smooth &&
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
860 (targetWidth < decoded->GetWidth() ||
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
861 targetHeight < decoded->GetHeight()))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
862 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
863 ImageProcessing::SmoothGaussian5x5(*decoded);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
864 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
865
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
866 ImageProcessing::Resize(*resized, *decoded);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
867 DefaultHandler(call, resized, ImageExtractionMode_Preview, false);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
868 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
869 }
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
870 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
871 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
872 // Grayscale image: (1) convert to Float32, (2) apply
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
873 // windowing to get a Grayscale8, (3) possibly resize
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
874
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
875 Image converted(PixelFormat_Float32, decoded->GetWidth(), decoded->GetHeight(), false);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
876 ImageProcessing::Convert(converted, *decoded);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
877
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
878 // Avoid divisions by zero
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
879 if (windowWidth <= 1.0f)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
880 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
881 windowWidth = 1;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
882 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
883
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
884 if (std::abs(rescaleSlope) <= 0.1f)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
885 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
886 rescaleSlope = 0.1f;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
887 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
888
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
889 const float scaling = 255.0f * rescaleSlope / windowWidth;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
890 const float offset = (rescaleIntercept - windowCenter + windowWidth / 2.0f) / rescaleSlope;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
891
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
892 std::unique_ptr<ImageAccessor> rescaled(new Image(PixelFormat_Grayscale8, decoded->GetWidth(), decoded->GetHeight(), false));
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
893 ImageProcessing::ShiftScale(*rescaled, converted, offset, scaling, false);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
894
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
895 if (targetWidth == decoded->GetWidth() &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
896 targetHeight == decoded->GetHeight())
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
897 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
898 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
899 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
900 else
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
901 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
902 std::unique_ptr<ImageAccessor> resized(
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
903 new Image(PixelFormat_Grayscale8, targetWidth, targetHeight, false));
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
904
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
905 if (smooth &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
906 (targetWidth < decoded->GetWidth() ||
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
907 targetHeight < decoded->GetHeight()))
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
908 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
909 ImageProcessing::SmoothGaussian5x5(*rescaled);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
910 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
911
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
912 ImageProcessing::Resize(*resized, *rescaled);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
913 DefaultHandler(call, resized, ImageExtractionMode_UInt8, invert);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
914 }
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
915 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
916 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
917
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
918 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
919 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
920 return true;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
921 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
922 };
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
923 }
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
924
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
925
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 template <enum ImageExtractionMode mode>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
927 static void GetImage(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
929 Semaphore::Locker locker(throttlingSemaphore_);
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
930
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
931 GetImageHandler handler(mode);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
932 IDecodedFrameHandler::Apply(call, handler);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
933 }
1906
d7c1cb559431 optimization for multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
934
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
935
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
936 static void GetRenderedFrame(RestApiGetCall& call)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
937 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
938 Semaphore::Locker locker(throttlingSemaphore_);
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
939
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
940 RenderedFrameHandler handler;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
941 IDecodedFrameHandler::Apply(call, handler);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
945 static void GetMatlabImage(RestApiGetCall& call)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
946 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
947 Semaphore::Locker locker(throttlingSemaphore_);
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
948
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
949 ServerContext& context = OrthancRestApi::GetContext(call);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
950
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
951 std::string frameId = call.GetUriComponent("frame", "0");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
952
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
953 unsigned int frame;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
954 try
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
955 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
956 frame = boost::lexical_cast<unsigned int>(frameId);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
957 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
958 catch (boost::bad_lexical_cast&)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
959 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
960 return;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
961 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
962
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
963 std::string publicId = call.GetUriComponent("id", "");
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
964 std::unique_ptr<ImageAccessor> decoded(context.DecodeDicomFrame(publicId, frame));
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
965
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
966 if (decoded.get() == NULL)
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
967 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
968 throw OrthancException(ErrorCode_NotImplemented,
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
969 "Cannot decode DICOM instance with ID: " + publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
970 }
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
971 else
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
972 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
973 std::string result;
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
974 decoded->ToMatlabString(result);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
975 call.GetOutput().AnswerBuffer(result, MimeType_PlainText);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
976 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
977 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
978
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
979
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
980 template <bool GzipCompression>
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
981 static void GetRawFrame(RestApiGetCall& call)
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
982 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
983 std::string frameId = call.GetUriComponent("frame", "0");
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
984
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
985 unsigned int frame;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
986 try
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
987 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
988 frame = boost::lexical_cast<unsigned int>(frameId);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
989 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
990 catch (boost::bad_lexical_cast&)
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
991 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
992 return;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
993 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
994
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
995 std::string publicId = call.GetUriComponent("id", "");
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
996 std::string raw;
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
997 MimeType mime;
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
998
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
999 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1000 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1001 locker.GetDicom().GetRawFrame(raw, mime, frame);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1002 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1003
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1004 if (GzipCompression)
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1005 {
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1006 GzipCompressor gzip;
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1007 std::string compressed;
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1008 gzip.Compress(compressed, raw.empty() ? NULL : raw.c_str(), raw.size());
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1009 call.GetOutput().AnswerBuffer(compressed, MimeType_Gzip);
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1010 }
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1011 else
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1012 {
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1013 call.GetOutput().AnswerBuffer(raw, mime);
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1014 }
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1015 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1016
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1017
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1018 static void GetResourceStatistics(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 {
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1020 static const uint64_t MEGA_BYTES = 1024 * 1024;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1021
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 std::string publicId = call.GetUriComponent("id", "");
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1023
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1024 ResourceType type;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1025 uint64_t diskSize, uncompressedSize, dicomDiskSize, dicomUncompressedSize;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1026 unsigned int countStudies, countSeries, countInstances;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1027 OrthancRestApi::GetIndex(call).GetResourceStatistics(
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1028 type, diskSize, uncompressedSize, countStudies, countSeries,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1029 countInstances, dicomDiskSize, dicomUncompressedSize, publicId);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1030
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1031 Json::Value result = Json::objectValue;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1032 result["DiskSize"] = boost::lexical_cast<std::string>(diskSize);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1033 result["DiskSizeMB"] = static_cast<unsigned int>(diskSize / MEGA_BYTES);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1034 result["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1035 result["UncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize / MEGA_BYTES);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1036
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1037 result["DicomDiskSize"] = boost::lexical_cast<std::string>(dicomDiskSize);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1038 result["DicomDiskSizeMB"] = static_cast<unsigned int>(dicomDiskSize / MEGA_BYTES);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1039 result["DicomUncompressedSize"] = boost::lexical_cast<std::string>(dicomUncompressedSize);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1040 result["DicomUncompressedSizeMB"] = static_cast<unsigned int>(dicomUncompressedSize / MEGA_BYTES);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1041
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1042 switch (type)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1043 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1044 // Do NOT add "break" below this point!
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1045 case ResourceType_Patient:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1046 result["CountStudies"] = countStudies;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1047
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1048 case ResourceType_Study:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1049 result["CountSeries"] = countSeries;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1050
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1051 case ResourceType_Series:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1052 result["CountInstances"] = countInstances;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1053
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1054 case ResourceType_Instance:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1055 default:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1056 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1057 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1058
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064 // Handling of metadata -----------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1066 static void CheckValidResourceType(RestApiCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068 std::string resourceType = call.GetUriComponent("resourceType", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 StringToResourceType(resourceType.c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1073 static void ListMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 std::string publicId = call.GetUriComponent("id", "");
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1078 std::map<MetadataType, std::string> metadata;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1080 OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId);
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1081
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1082 Json::Value result;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1084 if (call.HasArgument("expand"))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 {
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1086 result = Json::objectValue;
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1087
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1088 for (std::map<MetadataType, std::string>::const_iterator
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1089 it = metadata.begin(); it != metadata.end(); ++it)
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1090 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1091 std::string key = EnumerationToString(it->first);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1092 result[key] = it->second;
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1093 }
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1094 }
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1095 else
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1096 {
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1097 result = Json::arrayValue;
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1098
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1099 for (std::map<MetadataType, std::string>::const_iterator
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1100 it = metadata.begin(); it != metadata.end(); ++it)
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1101 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1102 result.append(EnumerationToString(it->first));
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1103 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1110 static void GetMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 std::string value;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, publicId, metadata))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1121 call.GetOutput().AnswerBuffer(value, MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1126 static void DeleteMetadata(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1134 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1135 {
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1137 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1139 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1140 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1141 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1142 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1146 static void SetMetadata(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 MetadataType metadata = StringToMetadata(name);
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1153
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1154 std::string value;
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1155 call.BodyToString(value);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1157 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 // It is forbidden to modify internal metadata
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 OrthancRestApi::GetIndex(call).SetMetadata(publicId, metadata, value);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1161 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1163 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1164 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1165 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1166 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 // Handling of attached files -----------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1174 static void ListAttachments(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 std::string resourceType = call.GetUriComponent("resourceType", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 std::list<FileContentType> attachments;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str()));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 for (std::list<FileContentType>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 it = attachments.begin(); it != attachments.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 result.append(EnumerationToString(*it));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1193 static bool GetAttachmentInfo(FileInfo& info, RestApiCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 return OrthancRestApi::GetIndex(call).LookupAttachment(info, publicId, contentType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1205 static void GetAttachmentOperations(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 Json::Value operations = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1212 operations.append("compress");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 operations.append("compressed-data");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 if (info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 operations.append("compressed-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 operations.append("compressed-size");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 operations.append("data");
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1222 operations.append("is-compressed");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 if (info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 operations.append("md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 operations.append("size");
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1230 operations.append("uncompress");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 if (info.GetCompressedMD5() != "" &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 operations.append("verify-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 call.GetOutput().AnswerJson(operations);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 template <int uncompress>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1244 static void GetAttachmentData(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 std::string publicId = call.GetUriComponent("id", "");
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1251 FileContentType type = StringToContentType(call.GetUriComponent("name", ""));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1253 if (uncompress)
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1254 {
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1255 context.AnswerAttachment(call.GetOutput(), publicId, type);
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1256 }
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1257 else
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1258 {
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1259 // Return the raw data (possibly compressed), as stored on the filesystem
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1260 std::string content;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1261 context.ReadAttachment(content, publicId, type, false);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1262 call.GetOutput().AnswerBuffer(content, MimeType_Binary);
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1263 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1267 static void GetAttachmentSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1272 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedSize()), MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1273 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1277 static void GetAttachmentCompressedSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1282 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedSize()), MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1283 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1287 static void GetAttachmentMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1293 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedMD5()), MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1298 static void GetAttachmentCompressedMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1304 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedMD5()), MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1309 static void VerifyAttachment(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318 if (!GetAttachmentInfo(info, call) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319 info.GetCompressedMD5() == "" ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 info.GetUncompressedMD5() == "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 // Inexistent resource, or no MD5 available
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326 bool ok = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 // First check whether the compressed data is correctly stored in the disk
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 std::string data;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1330 context.ReadAttachment(data, publicId, StringToContentType(name), false);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 std::string actualMD5;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 if (actualMD5 == info.GetCompressedMD5())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 // The compressed data is OK. If a compression algorithm was
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 // applied to it, now check the MD5 of the uncompressed data.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 if (info.GetCompressionType() == CompressionType_None)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 ok = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 {
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1345 context.ReadAttachment(data, publicId, StringToContentType(name), true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347 ok = (actualMD5 == info.GetUncompressedMD5());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 if (ok)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has the right MD5";
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1354 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has bad MD5!";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1363 static void UploadAttachment(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 FileContentType contentType = StringToContentType(name);
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1372 if (IsUserContentType(contentType) && // It is forbidden to modify internal attachments
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1373 context.AddAttachment(publicId, StringToContentType(name), call.GetBodyData(), call.GetBodySize()))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1375 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1377 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1378 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1379 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1380 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1384 static void DeleteAttachment(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1392 bool allowed;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1393 if (IsUserContentType(contentType))
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1394 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1395 allowed = true;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1396 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1397 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1398 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1399 OrthancConfiguration::ReaderLock lock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1400
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1401 if (lock.GetConfiguration().GetBooleanParameter("StoreDicom", true) &&
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1402 contentType == FileContentType_DicomAsJson)
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1403 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1404 allowed = true;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1405 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1406 else
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1407 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1408 // It is forbidden to delete internal attachments, except for
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1409 // the "DICOM as JSON" summary as of Orthanc 1.2.0 (this summary
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1410 // would be automatically reconstructed on the next GET call)
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1411 allowed = false;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1412 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1413 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1414
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1415 if (allowed)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1418 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1420 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1421 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1422 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1423 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1426
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1427 template <enum CompressionType compression>
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1428 static void ChangeAttachmentCompression(RestApiPostCall& call)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1429 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1430 CheckValidResourceType(call);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1431
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1432 std::string publicId = call.GetUriComponent("id", "");
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1433 std::string name = call.GetUriComponent("name", "");
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1434 FileContentType contentType = StringToContentType(name);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1435
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1436 OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1437 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1438 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1439
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1440
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1441 static void IsAttachmentCompressed(RestApiGetCall& call)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1442 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1443 FileInfo info;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1444 if (GetAttachmentInfo(info, call))
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1445 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1446 std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1";
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1447 call.GetOutput().AnswerBuffer(answer, MimeType_PlainText);
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1448 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1449 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1450
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1451
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1452 // Raw access to the DICOM tags of an instance ------------------------------
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1453
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1454 static void GetRawContent(RestApiGetCall& call)
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1455 {
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1456 std::string id = call.GetUriComponent("id", "");
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1457
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1458 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1459
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1460 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1461 }
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1462
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1465 static bool ExtractSharedTags(Json::Value& shared,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1466 ServerContext& context,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1467 const std::string& publicId)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1468 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1469 // Retrieve all the instances of this patient/study/series
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1470 typedef std::list<std::string> Instances;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1471 Instances instances;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1472 context.GetIndex().GetChildInstances(instances, publicId); // (*)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1473
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1474 // Loop over the instances
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1475 bool isFirst = true;
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1476 shared = Json::objectValue;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1477
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1478 for (Instances::const_iterator it = instances.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1479 it != instances.end(); ++it)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1480 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1481 // Get the tags of the current instance, in the simplified format
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1482 Json::Value tags;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1483
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1484 try
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1485 {
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
1486 context.ReadDicomAsJson(tags, *it);
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1487 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1488 catch (OrthancException&)
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1489 {
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1490 // Race condition: This instance has been removed since
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1491 // (*). Ignore this instance.
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1492 continue;
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1493 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1494
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1495 if (tags.type() != Json::objectValue)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1496 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1497 return false; // Error
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1498 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1499
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1500 // Only keep the tags that are mapped to a string
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1501 Json::Value::Members members = tags.getMemberNames();
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1502 for (size_t i = 0; i < members.size(); i++)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1503 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1504 const Json::Value& tag = tags[members[i]];
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1505 if (tag.type() != Json::objectValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1506 tag["Type"].type() != Json::stringValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1507 tag["Type"].asString() != "String")
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1508 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1509 tags.removeMember(members[i]);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1510 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1511 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1512
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1513 if (isFirst)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1514 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1515 // This is the first instance, keep its tags as such
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1516 shared = tags;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1517 isFirst = false;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1518 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1519 else
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1520 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1521 // Loop over all the members of the shared tags extracted so
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1522 // far. If the value of one of these tags does not match its
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1523 // value in the current instance, remove it.
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1524 members = shared.getMemberNames();
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1525 for (size_t i = 0; i < members.size(); i++)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1526 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1527 if (!tags.isMember(members[i]) ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1528 tags[members[i]]["Value"].asString() != shared[members[i]]["Value"].asString())
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1529 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1530 shared.removeMember(members[i]);
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1531 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1532 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1533 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1534 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1535
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1536 return true;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1537 }
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1538
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1539
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1540 static void GetSharedTags(RestApiGetCall& call)
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1541 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1542 ServerContext& context = OrthancRestApi::GetContext(call);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1543 std::string publicId = call.GetUriComponent("id", "");
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1544
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1545 Json::Value sharedTags;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1546 if (ExtractSharedTags(sharedTags, context, publicId))
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1547 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1548 // Success: Send the value of the shared tags
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1549 AnswerDicomAsJson(call, sharedTags);
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1550 }
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1551 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1552
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1553
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1554 static void GetModuleInternal(RestApiGetCall& call,
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1555 ResourceType resourceType,
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1556 DicomModule module)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1557 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1558 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1559 (resourceType == ResourceType_Study && module == DicomModule_Patient) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1560 (resourceType == ResourceType_Study && module == DicomModule_Study) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1561 (resourceType == ResourceType_Series && module == DicomModule_Series) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1562 (resourceType == ResourceType_Instance && module == DicomModule_Instance) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1563 (resourceType == ResourceType_Instance && module == DicomModule_Image)))
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1564 {
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1565 throw OrthancException(ErrorCode_NotImplemented);
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1566 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1567
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1568 ServerContext& context = OrthancRestApi::GetContext(call);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1569 std::string publicId = call.GetUriComponent("id", "");
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1570
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1571 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1572 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1573
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1574 typedef std::set<DicomTag> ModuleTags;
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1575 ModuleTags moduleTags;
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
1576 DicomTag::AddTagsForModule(moduleTags, module);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1577
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1578 Json::Value tags;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1579
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1580 if (resourceType != ResourceType_Instance)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1581 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1582 // Retrieve all the instances of this patient/study/series
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1583 typedef std::list<std::string> Instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1584 Instances instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1585 context.GetIndex().GetChildInstances(instances, publicId);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1586
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1587 if (instances.empty())
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1588 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1589 return; // Error: No instance (should never happen)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1590 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1591
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1592 // Select one child instance
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1593 publicId = instances.front();
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1594 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1595
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1596 context.ReadDicomAsJson(tags, publicId, ignoreTagLength);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1597
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1598 // Filter the tags of the instance according to the module
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1599 Json::Value result = Json::objectValue;
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1600 for (ModuleTags::const_iterator tag = moduleTags.begin(); tag != moduleTags.end(); ++tag)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1601 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1602 std::string s = tag->Format();
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1603 if (tags.isMember(s))
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1604 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1605 result[s] = tags[s];
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1606 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1607 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1608
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1609 AnswerDicomAsJson(call, result);
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1610 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1611
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1612
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1613
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1614 template <enum ResourceType resourceType,
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1615 enum DicomModule module>
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1616 static void GetModule(RestApiGetCall& call)
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1617 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1618 GetModuleInternal(call, resourceType, module);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1619 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1620
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1621
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1622 namespace
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1623 {
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1624 typedef std::list< std::pair<ResourceType, std::string> > LookupResults;
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1625 }
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1626
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1627
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1628 static void AccumulateLookupResults(LookupResults& result,
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1629 ServerIndex& index,
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1630 const DicomTag& tag,
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1631 const std::string& value,
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1632 ResourceType level)
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1633 {
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1634 std::vector<std::string> tmp;
1728
4941494b5dd8 rename LookupIdentifier as LookupIdentifierExact
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1727
diff changeset
1635 index.LookupIdentifierExact(tmp, level, tag, value);
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1636
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1637 for (size_t i = 0; i < tmp.size(); i++)
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1638 {
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1639 result.push_back(std::make_pair(level, tmp[i]));
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1640 }
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1641 }
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1642
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1643
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1644 static void Lookup(RestApiPostCall& call)
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1645 {
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1646 std::string tag;
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1647 call.BodyToString(tag);
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1648
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1649 LookupResults resources;
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1650 ServerIndex& index = OrthancRestApi::GetIndex(call);
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1651 AccumulateLookupResults(resources, index, DICOM_TAG_PATIENT_ID, tag, ResourceType_Patient);
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1652 AccumulateLookupResults(resources, index, DICOM_TAG_STUDY_INSTANCE_UID, tag, ResourceType_Study);
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1653 AccumulateLookupResults(resources, index, DICOM_TAG_SERIES_INSTANCE_UID, tag, ResourceType_Series);
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1654 AccumulateLookupResults(resources, index, DICOM_TAG_SOP_INSTANCE_UID, tag, ResourceType_Instance);
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1655
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1656 Json::Value result = Json::arrayValue;
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1657 for (LookupResults::const_iterator
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1658 it = resources.begin(); it != resources.end(); ++it)
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1659 {
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1660 ResourceType type = it->first;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1661 const std::string& id = it->second;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1662
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1663 Json::Value item = Json::objectValue;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1664 item["Type"] = EnumerationToString(type);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1665 item["ID"] = id;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1666 item["Path"] = GetBasePath(type, id);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1667
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1668 result.append(item);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1669 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1670
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1671 call.GetOutput().AnswerJson(result);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1672 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1673
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1674
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1675 namespace
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1676 {
3021
2cbafb5d5a62 renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
1677 class FindVisitor : public ServerContext::ILookupVisitor
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1678 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1679 private:
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1680 bool isComplete_;
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1681 std::list<std::string> resources_;
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1682
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1683 public:
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1684 FindVisitor() :
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1685 isComplete_(false)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1686 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1687 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1688
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1689 virtual bool IsDicomAsJsonNeeded() const
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1690 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1691 return false; // (*)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1692 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1693
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1694 virtual void MarkAsComplete()
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1695 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1696 isComplete_ = true; // Unused information as of Orthanc 1.5.0
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1697 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1698
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1699 virtual void Visit(const std::string& publicId,
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1700 const std::string& instanceId /* unused */,
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1701 const DicomMap& mainDicomTags /* unused */,
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
1702 const Json::Value* dicomAsJson /* unused (*) */)
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1703 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1704 resources_.push_back(publicId);
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1705 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1706
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1707 void Answer(RestApiOutput& output,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1708 ServerIndex& index,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1709 ResourceType level,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1710 bool expand) const
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1711 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1712 AnswerListOfResources(output, index, resources_, level, expand);
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1713 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1714 };
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1715 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1716
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1717
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1718 static void Find(RestApiPostCall& call)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1719 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1720 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1721 static const char* const KEY_EXPAND = "Expand";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1722 static const char* const KEY_LEVEL = "Level";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1723 static const char* const KEY_LIMIT = "Limit";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1724 static const char* const KEY_QUERY = "Query";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1725 static const char* const KEY_SINCE = "Since";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1726
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1356
diff changeset
1727 ServerContext& context = OrthancRestApi::GetContext(call);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1728
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1729 Json::Value request;
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1730 if (!call.ParseJsonRequest(request) ||
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1731 request.type() != Json::objectValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1732 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1733 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1734 "The body must contain a JSON object");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1735 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1736 else if (!request.isMember(KEY_LEVEL) ||
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1737 request[KEY_LEVEL].type() != Json::stringValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1738 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1739 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1740 "Field \"" + std::string(KEY_LEVEL) + "\" is missing, or should be a string");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1741 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1742 else if (!request.isMember(KEY_QUERY) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1743 request[KEY_QUERY].type() != Json::objectValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1744 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1745 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1746 "Field \"" + std::string(KEY_QUERY) + "\" is missing, or should be a JSON object");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1747 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1748 else if (request.isMember(KEY_CASE_SENSITIVE) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1749 request[KEY_CASE_SENSITIVE].type() != Json::booleanValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1750 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1751 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1752 "Field \"" + std::string(KEY_CASE_SENSITIVE) + "\" should be a Boolean");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1753 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1754 else if (request.isMember(KEY_LIMIT) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1755 request[KEY_LIMIT].type() != Json::intValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1756 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1757 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1758 "Field \"" + std::string(KEY_LIMIT) + "\" should be an integer");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1759 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1760 else if (request.isMember(KEY_SINCE) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1761 request[KEY_SINCE].type() != Json::intValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1762 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1763 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1764 "Field \"" + std::string(KEY_SINCE) + "\" should be an integer");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1765 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1766 else
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1767 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1768 bool expand = false;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1769 if (request.isMember(KEY_EXPAND))
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1770 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1771 expand = request[KEY_EXPAND].asBool();
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1772 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1773
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
1774 bool caseSensitive = false;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1775 if (request.isMember(KEY_CASE_SENSITIVE))
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
1776 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1777 caseSensitive = request[KEY_CASE_SENSITIVE].asBool();
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
1778 }
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
1779
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
1780 size_t limit = 0;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1781 if (request.isMember(KEY_LIMIT))
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
1782 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1783 int tmp = request[KEY_LIMIT].asInt();
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
1784 if (tmp < 0)
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
1785 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1786 throw OrthancException(ErrorCode_ParameterOutOfRange,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1787 "Field \"" + std::string(KEY_LIMIT) + "\" should be a positive integer");
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
1788 }
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
1789
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
1790 limit = static_cast<size_t>(tmp);
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
1791 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
1792
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1793 size_t since = 0;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1794 if (request.isMember(KEY_SINCE))
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1795 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1796 int tmp = request[KEY_SINCE].asInt();
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1797 if (tmp < 0)
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1798 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1799 throw OrthancException(ErrorCode_ParameterOutOfRange,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1800 "Field \"" + std::string(KEY_SINCE) + "\" should be a positive integer");
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1801 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1802
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1803 since = static_cast<size_t>(tmp);
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1804 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1805
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1806 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
1807
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1808 DatabaseLookup query;
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1356
diff changeset
1809
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1810 Json::Value::Members members = request[KEY_QUERY].getMemberNames();
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1811 for (size_t i = 0; i < members.size(); i++)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1812 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1813 if (request[KEY_QUERY][members[i]].type() != Json::stringValue)
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1814 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1815 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1816 "Tag \"" + members[i] + "\" should be associated with a string");
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1817 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1818
3163
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1819 const std::string value = request[KEY_QUERY][members[i]].asString();
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1820
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1821 if (!value.empty())
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1822 {
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1823 // An empty string corresponds to an universal constraint,
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1824 // so we ignore it. This mimics the behavior of class
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1825 // "OrthancFindRequestHandler"
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1826 query.AddRestConstraint(FromDcmtkBridge::ParseTag(members[i]),
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1827 value, caseSensitive, true);
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
1828 }
1361
94ffb597d297 refactoring of C-Find SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1829 }
2876
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2836
diff changeset
1830
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1831 FindVisitor visitor;
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1832 context.Apply(visitor, query, level, since, limit);
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1833 visitor.Answer(call.GetOutput(), context.GetIndex(), level, expand);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1834 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1835 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1836
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1837
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1838 template <enum ResourceType start,
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1839 enum ResourceType end>
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1840 static void GetChildResources(RestApiGetCall& call)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1841 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1842 ServerIndex& index = OrthancRestApi::GetIndex(call);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1843
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1844 std::list<std::string> a, b, c;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1845 a.push_back(call.GetUriComponent("id", ""));
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1846
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1847 ResourceType type = start;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1848 while (type != end)
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1849 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1850 b.clear();
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1851
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1852 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1853 it = a.begin(); it != a.end(); ++it)
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1854 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1855 index.GetChildren(c, *it);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1856 b.splice(b.begin(), c);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1857 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1858
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
1859 type = GetChildResourceType(type);
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1860
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1861 a.clear();
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1862 a.splice(a.begin(), b);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1863 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1864
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1865 Json::Value result = Json::arrayValue;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1866
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1867 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1868 it = a.begin(); it != a.end(); ++it)
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1869 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1870 Json::Value item;
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1871
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1872 if (OrthancRestApi::GetIndex(call).LookupResource(item, *it, end))
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1873 {
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1874 result.append(item);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1875 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1876 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1877
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1878 call.GetOutput().AnswerJson(result);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1879 }
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1880
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1881
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1882 static void GetChildInstancesTags(RestApiGetCall& call)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1883 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1884 ServerContext& context = OrthancRestApi::GetContext(call);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1885 std::string publicId = call.GetUriComponent("id", "");
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1886 DicomToJsonFormat format = GetDicomFormat(call);
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1887
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1888 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1889 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1890
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1891 // Retrieve all the instances of this patient/study/series
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1892 typedef std::list<std::string> Instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1893 Instances instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1894
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1895 context.GetIndex().GetChildInstances(instances, publicId); // (*)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1896
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
1897 Json::Value result = Json::objectValue;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1898
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1899 for (Instances::const_iterator it = instances.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1900 it != instances.end(); ++it)
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1901 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1902 Json::Value full;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1903 context.ReadDicomAsJson(full, *it, ignoreTagLength);
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1904
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1905 if (format != DicomToJsonFormat_Full)
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1906 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1907 Json::Value simplified;
4055
9214e3a7b0a2 moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
1908 Toolbox::SimplifyDicomAsJson(simplified, full, format);
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
1909 result[*it] = simplified;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1910 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1911 else
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1912 {
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
1913 result[*it] = full;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1914 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1915 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1916
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1917 call.GetOutput().AnswerJson(result);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1918 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1919
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
1920
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
1921
1281
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1922 template <enum ResourceType start,
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1923 enum ResourceType end>
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1924 static void GetParentResource(RestApiGetCall& call)
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1925 {
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1926 assert(start > end);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1927
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1928 ServerIndex& index = OrthancRestApi::GetIndex(call);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1929
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1930 std::string current = call.GetUriComponent("id", "");
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1931 ResourceType currentType = start;
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1932 while (currentType > end)
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1933 {
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1934 std::string parent;
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1935 if (!index.LookupParent(parent, current))
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1936 {
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1937 // Error that could happen if the resource gets deleted by
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1938 // another concurrent call
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1939 return;
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1940 }
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1941
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1942 current = parent;
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
1943 currentType = GetParentResourceType(currentType);
1281
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1944 }
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1945
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1946 assert(currentType == end);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1947
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1948 Json::Value result;
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1949 if (index.LookupResource(result, current, end))
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1950 {
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1951 call.GetOutput().AnswerJson(result);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1952 }
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1953 }
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1954
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1955
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1956 static void ExtractPdf(RestApiGetCall& call)
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1957 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1958 const std::string id = call.GetUriComponent("id", "");
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1959
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1960 std::string pdf;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1961 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1962
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1963 if (locker.GetDicom().ExtractPdf(pdf))
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1964 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1965 call.GetOutput().AnswerBuffer(pdf, MimeType_Pdf);
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1966 return;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1967 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1968 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
1969
1281
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
1970
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1971 static void OrderSlices(RestApiGetCall& call)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1972 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1973 const std::string id = call.GetUriComponent("id", "");
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1974
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1975 ServerIndex& index = OrthancRestApi::GetIndex(call);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1976 SliceOrdering ordering(index, id);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1977
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
1978 Json::Value result;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
1979 ordering.Format(result);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
1980 call.GetOutput().AnswerJson(result);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1981 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1982
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
1983
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1984 static void GetInstanceHeader(RestApiGetCall& call)
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1985 {
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1986 ServerContext& context = OrthancRestApi::GetContext(call);
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1987
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1988 std::string publicId = call.GetUriComponent("id", "");
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1989
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1990 std::string dicomContent;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
1991 context.ReadDicom(dicomContent, publicId);
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1992
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
1993 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
1994 // speed up things here
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
1995
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1996 ParsedDicomFile dicom(dicomContent);
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1997
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1998 Json::Value header;
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
1999 dicom.HeaderToJson(header, DicomToJsonFormat_Full);
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2000
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
2001 AnswerDicomAsJson(call, header);
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2002 }
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2003
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2004
2129
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2005 static void InvalidateTags(RestApiPostCall& call)
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2006 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2007 ServerIndex& index = OrthancRestApi::GetIndex(call);
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2008
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2009 // Loop over the instances, grouping them by parent studies so as
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2010 // to avoid large memory consumption
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2011 std::list<std::string> studies;
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2012 index.GetAllUuids(studies, ResourceType_Study);
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2013
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2014 for (std::list<std::string>::const_iterator
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2015 study = studies.begin(); study != studies.end(); ++study)
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2016 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2017 std::list<std::string> instances;
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2018 index.GetChildInstances(instances, *study);
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2019
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2020 for (std::list<std::string>::const_iterator
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2021 instance = instances.begin(); instance != instances.end(); ++instance)
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2022 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2023 index.DeleteAttachment(*instance, FileContentType_DicomAsJson);
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2024 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2025 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2026
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2027 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
2129
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2028 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2029
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2030
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2031 template <enum ResourceType type>
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2032 static void ReconstructResource(RestApiPostCall& call)
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2033 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2034 ServerContext& context = OrthancRestApi::GetContext(call);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2035 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""));
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2036 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2037 }
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2038
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2039
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2040 static void ReconstructAllResources(RestApiPostCall& call)
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2041 {
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2042 ServerContext& context = OrthancRestApi::GetContext(call);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2043
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2044 std::list<std::string> studies;
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2045 context.GetIndex().GetAllUuids(studies, ResourceType_Study);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2046
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2047 for (std::list<std::string>::const_iterator
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2048 study = studies.begin(); study != studies.end(); ++study)
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2049 {
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2050 ServerToolbox::ReconstructResource(context, *study);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2051 }
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2052
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2053 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2054 }
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2055
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2056
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2057 void OrthancRestApi::RegisterResources()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2058 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2059 Register("/instances", ListResources<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2060 Register("/patients", ListResources<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2061 Register("/series", ListResources<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2062 Register("/studies", ListResources<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2063
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2064 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2065 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2066 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2067 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2068 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2069 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2070 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2071 Register("/studies/{id}", GetSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2072
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2073 Register("/instances/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2074 Register("/patients/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2075 Register("/studies/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2076 Register("/series/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2077
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2078 Register("/patients/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2079 Register("/series/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2080 Register("/studies/{id}/shared-tags", GetSharedTags);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2081
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2082 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2083 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2084 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2085 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2086 Register("/studies/{id}/module-patient", GetModule<ResourceType_Study, DicomModule_Patient>);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2087
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2088 Register("/instances/{id}/file", GetInstanceFile);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2089 Register("/instances/{id}/export", ExportInstanceFile);
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2090 Register("/instances/{id}/tags", GetInstanceTagsBis);
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
2091 Register("/instances/{id}/simplified-tags", GetInstanceTags<DicomToJsonFormat_Human>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2092 Register("/instances/{id}/frames", ListFrames);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2093
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2094 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2095 Register("/instances/{id}/frames/{frame}/rendered", GetRenderedFrame);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2096 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2097 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2098 Register("/instances/{id}/frames/{frame}/image-int16", GetImage<ImageExtractionMode_Int16>);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
2099 Register("/instances/{id}/frames/{frame}/matlab", GetMatlabImage);
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
2100 Register("/instances/{id}/frames/{frame}/raw", GetRawFrame<false>);
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
2101 Register("/instances/{id}/frames/{frame}/raw.gz", GetRawFrame<true>);
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2102 Register("/instances/{id}/pdf", ExtractPdf);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2103 Register("/instances/{id}/preview", GetImage<ImageExtractionMode_Preview>);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2104 Register("/instances/{id}/rendered", GetRenderedFrame);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2105 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2106 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2107 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
2108 Register("/instances/{id}/matlab", GetMatlabImage);
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2109 Register("/instances/{id}/header", GetInstanceHeader);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2110
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2111 Register("/patients/{id}/protected", IsProtectedPatient);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2112 Register("/patients/{id}/protected", SetPatientProtection);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2113
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2114 Register("/{resourceType}/{id}/metadata", ListMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2115 Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2116 Register("/{resourceType}/{id}/metadata/{name}", GetMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2117 Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2118
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2119 Register("/{resourceType}/{id}/attachments", ListAttachments);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2120 Register("/{resourceType}/{id}/attachments/{name}", DeleteAttachment);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2121 Register("/{resourceType}/{id}/attachments/{name}", GetAttachmentOperations);
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2122 Register("/{resourceType}/{id}/attachments/{name}", UploadAttachment);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2123 Register("/{resourceType}/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2124 Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2125 Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2126 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2127 Register("/{resourceType}/{id}/attachments/{name}/data", GetAttachmentData<1>);
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2128 Register("/{resourceType}/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2129 Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2130 Register("/{resourceType}/{id}/attachments/{name}/size", GetAttachmentSize);
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2131 Register("/{resourceType}/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2132 Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2133
2129
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2134 Register("/tools/invalidate-tags", InvalidateTags);
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2135 Register("/tools/lookup", Lookup);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2136 Register("/tools/find", Find);
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2137
1140
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2138 Register("/patients/{id}/studies", GetChildResources<ResourceType_Patient, ResourceType_Study>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2139 Register("/patients/{id}/series", GetChildResources<ResourceType_Patient, ResourceType_Series>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2140 Register("/patients/{id}/instances", GetChildResources<ResourceType_Patient, ResourceType_Instance>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2141 Register("/studies/{id}/series", GetChildResources<ResourceType_Study, ResourceType_Series>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2142 Register("/studies/{id}/instances", GetChildResources<ResourceType_Study, ResourceType_Instance>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2143 Register("/series/{id}/instances", GetChildResources<ResourceType_Series, ResourceType_Instance>);
94c5f6623b3a URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1139
diff changeset
2144
1281
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2145 Register("/studies/{id}/patient", GetParentResource<ResourceType_Study, ResourceType_Patient>);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2146 Register("/series/{id}/patient", GetParentResource<ResourceType_Series, ResourceType_Patient>);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2147 Register("/series/{id}/study", GetParentResource<ResourceType_Series, ResourceType_Study>);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2148 Register("/instances/{id}/patient", GetParentResource<ResourceType_Instance, ResourceType_Patient>);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2149 Register("/instances/{id}/study", GetParentResource<ResourceType_Instance, ResourceType_Study>);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2150 Register("/instances/{id}/series", GetParentResource<ResourceType_Instance, ResourceType_Series>);
8dac11c78d71 URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1276
diff changeset
2151
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2152 Register("/patients/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2153 Register("/studies/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2154 Register("/series/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2155
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2156 Register("/instances/{id}/content/*", GetRawContent);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2157
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2158 Register("/series/{id}/ordered-slices", OrderSlices);
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2159
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2160 Register("/patients/{id}/reconstruct", ReconstructResource<ResourceType_Patient>);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2161 Register("/studies/{id}/reconstruct", ReconstructResource<ResourceType_Study>);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2162 Register("/series/{id}/reconstruct", ReconstructResource<ResourceType_Series>);
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2163 Register("/instances/{id}/reconstruct", ReconstructResource<ResourceType_Instance>);
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2164 Register("/tools/reconstruct", ReconstructAllResources);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2165 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2166 }