annotate OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4406:4cb9f66a1c7c

documenting generation of images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Dec 2020 17:32:19 +0100
parents 5466f336b09f
children 2412601cd24b
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 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
164 if (call.IsDocumentation())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
165 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
166 const std::string resources = GetResourceTypeText(resourceType, true /* plural */, false /* lower case */);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
167 call.GetDocumentation()
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
168 .SetTag(GetResourceTypeText(resourceType, true /* plural */, true /* upper case */))
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
169 .SetSummary("List the available " + resources)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
170 .SetDescription("List the Orthanc identifiers of all the available DICOM " + resources)
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
171 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false)
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
172 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
173 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String,
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
174 "If present, retrieve detailed information about the individual " + resources, false)
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
175 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information "
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
176 "about the reported " + resources + " (if `expand` argument is provided)")
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
177 .SetHttpGetSample("https://demo.orthanc-server.com/" + resources + "?since=0&limit=2", true);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
178 return;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
179 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
180
1342
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
181 ServerIndex& index = OrthancRestApi::GetIndex(call);
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
182
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
183 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
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 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
186 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
187 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
188 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
189 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
190 throw OrthancException(ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
191 "Missing \"limit\" argument for GET request against: " +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
192 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
193 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
194
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
195 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
196 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
197 throw OrthancException(ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
198 "Missing \"since\" argument for GET request against: " +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
199 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
200 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
201
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
202 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
203 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
204 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
205 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
206 else
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
207 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
208 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
209 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
210
1342
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
211
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
212 AnswerListOfResources(call.GetOutput(), index, result, resourceType, call.HasArgument("expand"));
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
216 static void GetSingleResource(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
218 if (call.IsDocumentation())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
219 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
220 std::string sampleUrl;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
221 switch (resourceType)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
222 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
223 case Orthanc::ResourceType_Instance:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
224 sampleUrl = "https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
225 break;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
226 case Orthanc::ResourceType_Series:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
227 sampleUrl = "https://demo.orthanc-server.com/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
228 break;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
229 case Orthanc::ResourceType_Study:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
230 sampleUrl = "https://demo.orthanc-server.com/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
231 break;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
232 case Orthanc::ResourceType_Patient:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
233 sampleUrl = "https://demo.orthanc-server.com/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
234 break;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
235 default:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
236 throw OrthancException(ErrorCode_ParameterOutOfRange);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
237 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
238
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
239 const std::string resource = GetResourceTypeText(resourceType, false /* plural */, false /* lower case */);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
240 call.GetDocumentation()
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
241 .SetTag(GetResourceTypeText(resourceType, true /* plural */, true /* upper case */))
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
242 .SetSummary("Get information about some " + resource)
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
243 .SetDescription("Get detailed information about the DICOM " + resource + " of interest whose Orthanc identifier is provided in the URL")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
244 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
245 .SetHttpGetSample(sampleUrl, true);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
246 return;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
247 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
248
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 Json::Value result;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 call.GetOutput().AnswerJson(result);
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 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
257 static void DeleteSingleResource(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
259 if (call.IsDocumentation())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
260 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
261 const std::string resource = GetResourceTypeText(resourceType, false /* plural */, false /* lower case */);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
262 call.GetDocumentation()
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
263 .SetTag(GetResourceTypeText(resourceType, true /* plural */, true /* upper case */))
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
264 .SetSummary("Delete some " + resource)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
265 .SetDescription("Delete the DICOM " + resource + " of interest whose Orthanc identifier is provided in the URL")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
266 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest");
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
267 return;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
268 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
269
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 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
271 if (OrthancRestApi::GetContext(call).DeleteResource(result, call.GetUriComponent("id", ""), resourceType))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 // Get information about a single patient -----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
280 static void IsProtectedPatient(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
282 if (call.IsDocumentation())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
283 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
284 call.GetDocumentation()
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
285 .SetTag("Patients")
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
286 .SetSummary("Is the patient protected against recycling?")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
287 .SetUriArgument("id", "Orthanc identifier of the patient of interest")
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
288 .AddAnswerType(MimeType_PlainText, "`1` if protected, `0` if not protected");
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
289 return;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
290 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
291
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
294 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
298 static void SetPatientProtection(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
300 if (call.IsDocumentation())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
301 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
302 call.GetDocumentation()
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
303 .SetTag("Patients")
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
304 .SetSummary("Protect one patient against recycling")
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
305 .SetDescription("Check out configuration options `MaximumStorageSize` and `MaximumPatientCount`")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
306 .SetUriArgument("id", "Orthanc identifier of the patient of interest");
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
307 return;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
308 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
309
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 ServerContext& context = OrthancRestApi::GetContext(call);
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 publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
314 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
315 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
316 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
317
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
318 if (body == "0")
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 context.GetIndex().SetProtectedPatient(publicId, false);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
321 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
323 else if (body == "1")
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 context.GetIndex().SetProtectedPatient(publicId, true);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
326 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
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 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 // Bad request
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 // Get information about a single instance ----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
337 static void GetInstanceFile(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
339 if (call.IsDocumentation())
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
340 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
341 call.GetDocumentation()
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
342 .SetTag("Instances")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
343 .SetSummary("Download DICOM")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
344 .SetDescription("Download one DICOM instance")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
345 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
346 .SetHttpHeader("Accept", "This HTTP header can be set to retrieve the DICOM instance in DICOMweb format")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
347 .AddAnswerType(MimeType_Dicom, "The DICOM instance")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
348 .AddAnswerType(MimeType_DicomWebJson, "The DICOM instance, in DICOMweb JSON format")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
349 .AddAnswerType(MimeType_DicomWebXml, "The DICOM instance, in DICOMweb XML format");
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
350 return;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
351 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
352
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 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
356
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4294
diff changeset
357 HttpToolbox::Arguments::const_iterator accept = call.GetHttpHeaders().find("accept");
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
358 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
359 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
360 // 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
361 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
362 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
363 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
364
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
365 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
366 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
367 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
368 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
369
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
370 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
371 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
372 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
373 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
374
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
375 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
376 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
377 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
378 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
379 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
380 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
381 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
382 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
383 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
384 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
385 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
386
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
387 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
388 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
389 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
390 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
391 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
392 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
393 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
394
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
395 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
399 static void ExportInstanceFile(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 std::string dicom;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
406 context.ReadDicom(dicom, publicId);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
408 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
409 call.BodyToString(target);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
410 SystemToolbox::WriteFile(dicom, target);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
412 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
416 template <DicomToJsonFormat format>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
417 static void GetInstanceTags(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 {
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
419 if (call.IsDocumentation())
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
420 {
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
421 if (format == DicomToJsonFormat_Human)
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
422 {
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
423 call.GetDocumentation()
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
424 .SetTag("Instances")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
425 .SetSummary("Get human-readable tags")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
426 .SetDescription("Get the DICOM tags in human-readable format")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
427 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
428 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
429 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", true);
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
430 return;
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
431 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
432 else
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
433 {
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
434 throw OrthancException(ErrorCode_NotImplemented);
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
435 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
436 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
437
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 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
441
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
442 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
443 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
445 if (format != DicomToJsonFormat_Full ||
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
446 !ignoreTagLength.empty())
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 {
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
448 Json::Value full;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
449 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
450 AnswerDicomAsJson(call, full, format);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 {
3973
d86bddb50972 fix spelling errors according to debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3928
diff changeset
454 // 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
455 // 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
456 // is present
2127
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
457 std::string full;
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
458 context.ReadDicomAsJson(full, publicId);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
459 call.GetOutput().AnswerBuffer(full, MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
463
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
464 static void GetInstanceTagsBis(RestApiGetCall& call)
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
465 {
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
466 if (call.IsDocumentation())
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
467 {
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
468 call.GetDocumentation()
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
469 .SetTag("Instances")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
470 .SetSummary("Get DICOM tags")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
471 .SetDescription("Get the DICOM tags in the specified format. By default, the `full` format is used, which "
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
472 "combines hexadecimal tags with human-readable description.")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
473 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
474 .SetHttpGetArgument("simplify", RestApiCallDocumentation::Type_String,
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
475 "If present, report the DICOM tags in human-readable format "
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
476 "(same as the `/instances/{id}/simplified-tags` route)", false)
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
477 .SetHttpGetArgument("short", RestApiCallDocumentation::Type_String,
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
478 "If present, report the DICOM tags indexed in hexadecimal format", false)
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
479 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
480 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", true);
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
481 return;
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
482 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
483
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
484 switch (GetDicomFormat(call))
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
485 {
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
486 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
487 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
488 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
489
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
490 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
491 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
492 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
493
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
494 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
495 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
496 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
497
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
498 default:
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
499 throw OrthancException(ErrorCode_InternalError);
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
500 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
501 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
502
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
504 static void ListFrames(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
506 std::string publicId = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
508 unsigned int numberOfFrames;
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
509
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
510 {
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
511 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
512 numberOfFrames = locker.GetDicom().GetFramesCount();
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 }
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
514
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
515 Json::Value result = Json::arrayValue;
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
516 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
517 {
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
518 result.append(i);
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
519 }
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
520
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
521 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524
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
525 namespace
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
526 {
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
527 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
528 {
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
529 private:
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>& image_;
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
531 ImageExtractionMode mode_;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
532 bool invert_;
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
533 MimeType format_;
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
534 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
535
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
536 public:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
537 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
538 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
539 bool invert) :
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
540 image_(image),
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
541 mode_(mode),
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
542 invert_(invert),
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
543 format_(MimeType_Binary)
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
544 {
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
545 }
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
546
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
547 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
548 {
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
549 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
550 }
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
551
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
552 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
553 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
554 format_ = MimeType_Png;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
555 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
556 }
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
557
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
558 void EncodeUsingPam()
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
559 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
560 format_ = MimeType_Pam;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
561 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
562 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
563
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
564 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
565 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
566 format_ = MimeType_Jpeg;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
567 DicomImageDecoder::ExtractJpegImage(answer_, image_, mode_, invert_, quality);
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1784
diff changeset
568 }
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
569 };
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
570
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
571 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
572 {
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
573 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
574 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
575
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
576 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
577 explicit EncodePng(ImageToEncode& image) : image_(image)
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
578 {
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
579 }
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
580
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
581 virtual void Handle(const std::string& type,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
582 const std::string& subtype) ORTHANC_OVERRIDE
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
583 {
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
584 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
585 assert(subtype == "png");
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
586 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
587 }
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
588 };
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
589
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
590 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
591 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
592 private:
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
593 ImageToEncode& image_;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
594
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
595 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
596 explicit EncodePam(ImageToEncode& image) : image_(image)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
597 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
598 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
599
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
600 virtual void Handle(const std::string& type,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
601 const std::string& subtype) ORTHANC_OVERRIDE
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
602 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
603 assert(type == "image");
2780
am@osimis.io
parents: 2726
diff changeset
604 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
605 image_.EncodeUsingPam();
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
606 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
607 };
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
608
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
609 class EncodeJpeg : public HttpContentNegociation::IHandler
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
610 {
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
611 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
612 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
613 unsigned int quality_;
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
614
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
615 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
616 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
617 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
618 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
619 {
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
620 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
621 bool ok = false;
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
622
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
623 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
624 {
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
625 quality_ = boost::lexical_cast<unsigned int>(v);
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
626 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
627 }
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
628 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
629 {
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
630 }
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
631
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
632 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
633 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
634 throw OrthancException(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
635 ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
636 "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
637 }
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
638 }
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
639
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
640 virtual void Handle(const std::string& type,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
641 const std::string& subtype) ORTHANC_OVERRIDE
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
642 {
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
643 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
644 assert(subtype == "jpeg");
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
645 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
646 }
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
647 };
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
648 }
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
649
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
650
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
651 namespace
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
652 {
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
653 class IDecodedFrameHandler : public boost::noncopyable
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
654 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
655 public:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
656 virtual ~IDecodedFrameHandler()
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
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
660 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
661 std::unique_ptr<ImageAccessor>& decoded,
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
662 const DicomMap& dicom) = 0;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
663
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
664 virtual bool RequiresDicomTags() const = 0;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
665
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
666 static void Apply(RestApiGetCall& call,
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
667 IDecodedFrameHandler& handler,
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
668 ImageExtractionMode mode /* for generation of documentation */,
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
669 bool isRendered /* for generation of documentation */)
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
670 {
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
671 if (call.IsDocumentation())
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
672 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
673 std::string m;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
674 if (!isRendered)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
675 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
676 switch (mode)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
677 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
678 case ImageExtractionMode_Preview:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
679 m = "preview";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
680 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
681 case ImageExtractionMode_UInt8:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
682 m = "uint8";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
683 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
684 case ImageExtractionMode_UInt16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
685 m = "uint16";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
686 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
687 case ImageExtractionMode_Int16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
688 m = "int16";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
689 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
690 default:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
691 throw OrthancException(ErrorCode_ParameterOutOfRange);
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
692 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
693 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
694
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
695 std::string description;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
696 std::string verb = (isRendered ? "Render" : "Decode");
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
697
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
698 if (call.HasUriComponent("frame"))
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
699 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
700 description = verb + " one frame of interest from the given DICOM instance.";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
701 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
702 .SetSummary(verb + " a frame" + (m.empty() ? "" : " (" + m + ")"))
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
703 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)");
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
704 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
705 else
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
706 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
707 description = verb + " the first frame of the given DICOM instance.";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
708 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
709 .SetSummary(verb + " an image" + (m.empty() ? "" : " (" + m + ")"));
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
710 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
711
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
712 if (isRendered)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
713 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
714 description += (" This function takes scaling into account (`RescaleSlope` and `RescaleIntercept` tags), "
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
715 "as well as the default windowing stored in the DICOM file (`WindowCenter` and `WindowWidth`tags), "
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
716 "and can be used to resize the resulting image. Color images are not affected by windowing.");
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
717 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
718 .SetHttpGetArgument("window-center",RestApiCallDocumentation::Type_Number, "Windowing center", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
719 .SetHttpGetArgument("window-width",RestApiCallDocumentation::Type_Number, "Windowing width", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
720 .SetHttpGetArgument("width",RestApiCallDocumentation::Type_Number, "Width of the resized image", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
721 .SetHttpGetArgument("height",RestApiCallDocumentation::Type_Number, "Height of the resized image", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
722 .SetHttpGetArgument("smooth",RestApiCallDocumentation::Type_Boolean, "Whether to smooth image on resize", false);
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
723 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
724 else
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
725 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
726 switch (mode)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
727 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
728 case ImageExtractionMode_Preview:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
729 description += " The full dynamic range of grayscale images is rescaled to the [0,255] range.";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
730 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
731 case ImageExtractionMode_UInt8:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
732 description += " Pixels of grayscale images are truncated to the [0,255] range.";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
733 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
734 case ImageExtractionMode_UInt16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
735 description += " Pixels of grayscale images are truncated to the [0,65535] range.";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
736 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
737 case ImageExtractionMode_Int16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
738 description += (" Pixels of grayscale images are truncated to the [-32768,32767] range. "
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
739 "Negative values must be interpreted according to two's complement.");
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
740 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
741 default:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
742 throw OrthancException(ErrorCode_ParameterOutOfRange);
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
743 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
744 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
745
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
746 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
747 .SetTag("Instances")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
748 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
749 .SetHttpGetArgument("quality", RestApiCallDocumentation::Type_Number, "Quality for JPEG images (between 1 and 100, defaults to 90)", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
750 .SetHttpHeader("Accept", "Format of the resulting image. Can be `image/png` (default), `image/jpeg` or `image/x-portable-arbitrarymap`")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
751 .AddAnswerType(MimeType_Png, "PNG image")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
752 .AddAnswerType(MimeType_Jpeg, "JPEG image")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
753 .AddAnswerType(MimeType_Pam, "PAM image (Portable Arbitrary Map)")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
754 .SetDescription(description);
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
755
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
756 return;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
757 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
758
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
759 ServerContext& context = OrthancRestApi::GetContext(call);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
760
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
761 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
762
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
763 unsigned int frame;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
764 try
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
765 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
766 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
767 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
768 catch (boost::bad_lexical_cast&)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
769 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
770 return;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
771 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
772
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
773 DicomMap dicom;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
774 std::unique_ptr<ImageAccessor> decoded;
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
775
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
776 try
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
777 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
778 std::string publicId = call.GetUriComponent("id", "");
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
779
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
780 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
781
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
782 if (decoded.get() == NULL)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
783 {
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
784 throw OrthancException(ErrorCode_NotImplemented,
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
785 "Cannot decode DICOM instance with ID: " + publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
786 }
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
787
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
788 if (handler.RequiresDicomTags())
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
789 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
790 /**
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
791 * Retrieve a summary of the DICOM tags, which is
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
792 * necessary to deal with MONOCHROME1 photometric
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
793 * interpretation, and with windowing parameters.
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
794 **/
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
795 ServerContext::DicomCacheLocker locker(context, publicId);
4140
0ddc5297a8ab centralization of default parameters for JSON/DicomMap conversions from DCMTK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
796 OrthancConfiguration::DefaultExtractDicomSummary(dicom, locker.GetDicom());
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
797 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
798 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
799 catch (OrthancException& e)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
800 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
801 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange ||
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
802 e.GetErrorCode() == ErrorCode_UnknownResource)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
803 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
804 // 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
805 // instance, the resource is not existent
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
806 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
807 else
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
808 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
809 std::string root = "";
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
810 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
811 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
812 root += "../";
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
813 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
814
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
815 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
816 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
817 return;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
818 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
819
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
820 handler.Handle(call, decoded, dicom);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
821 }
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
822
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
823
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
824 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
825 std::unique_ptr<ImageAccessor>& decoded,
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
826 ImageExtractionMode mode,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
827 bool invert)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
828 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
829 ImageToEncode image(decoded, mode, invert);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
830
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
831 HttpContentNegociation negociation;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
832 EncodePng png(image);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
833 negociation.Register(MIME_PNG, png);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
834
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
835 EncodeJpeg jpeg(image, call);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
836 negociation.Register(MIME_JPEG, jpeg);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
837
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
838 EncodePam pam(image);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
839 negociation.Register(MIME_PAM, pam);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
840
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
841 if (negociation.Apply(call.GetHttpHeaders()))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
842 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
843 image.Answer(call.GetOutput());
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
844 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
845 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
846 };
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
847
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
848
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
849 class GetImageHandler : public IDecodedFrameHandler
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
850 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
851 private:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
852 ImageExtractionMode mode_;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
853
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
854 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
855 explicit GetImageHandler(ImageExtractionMode mode) :
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
856 mode_(mode)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
857 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
858 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
859
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
860 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
861 std::unique_ptr<ImageAccessor>& decoded,
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
862 const DicomMap& dicom) ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
863 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
864 bool invert = false;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
865
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
866 if (mode_ == ImageExtractionMode_Preview)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
867 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
868 DicomImageInformation info(dicom);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
869 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
870 }
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
871
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
872 DefaultHandler(call, decoded, mode_, invert);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
873 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
874
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
875 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
876 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
877 return mode_ == ImageExtractionMode_Preview;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
878 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
879 };
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
880
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
881
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
882 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
883 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
884 private:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
885 static void GetDicomParameters(bool& invert,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
886 float& rescaleSlope,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
887 float& rescaleIntercept,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
888 float& windowWidth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
889 float& windowCenter,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
890 const DicomMap& dicom)
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
891 {
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
892 DicomImageInformation info(dicom);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
893
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
894 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
895
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
896 rescaleSlope = 1.0f;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
897 rescaleIntercept = 0.0f;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
898
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
899 if (dicom.HasTag(Orthanc::DICOM_TAG_RESCALE_SLOPE) &&
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
900 dicom.HasTag(Orthanc::DICOM_TAG_RESCALE_INTERCEPT))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
901 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
902 dicom.ParseFloat(rescaleSlope, Orthanc::DICOM_TAG_RESCALE_SLOPE);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
903 dicom.ParseFloat(rescaleIntercept, Orthanc::DICOM_TAG_RESCALE_INTERCEPT);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
904 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
905
3816
09f091b6b569 /rendered route: fix automatic windowing of files without windowing tags and RescaleSlope != 1
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
906 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
907 windowCenter = windowWidth / 2.0f + rescaleIntercept;
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
908
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
909 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
910 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
911 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
912 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
913 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
914 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
915 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
916
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
917 static void GetUserArguments(float& windowWidth /* inout */,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
918 float& windowCenter /* inout */,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
919 unsigned int& argWidth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
920 unsigned int& argHeight,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
921 bool& smooth,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
922 const RestApiGetCall& call)
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
923 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
924 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
925 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
926 static const char* ARG_WIDTH = "width";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
927 static const char* ARG_HEIGHT = "height";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
928 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
929
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
930 if (call.HasArgument(ARG_WINDOW_WIDTH))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
931 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
932 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
933 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
934 windowWidth = boost::lexical_cast<float>(call.GetArgument(ARG_WINDOW_WIDTH, ""));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
935 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
936 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
937 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
938 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
939 "Bad value for argument: " + std::string(ARG_WINDOW_WIDTH));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
940 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
941 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
942
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
943 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
944 {
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
945 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
946 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
947 windowCenter = boost::lexical_cast<float>(call.GetArgument(ARG_WINDOW_CENTER, ""));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
948 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
949 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
950 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
951 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
952 "Bad value for argument: " + std::string(ARG_WINDOW_CENTER));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
953 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
954 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
955
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
956 argWidth = 0;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
957 argHeight = 0;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
958
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
959 if (call.HasArgument(ARG_WIDTH))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
960 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
961 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
962 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
963 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
964 if (tmp < 0)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
965 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
966 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
967 "Argument cannot be negative: " + std::string(ARG_WIDTH));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
968 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
969 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
970 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
971 argWidth = static_cast<unsigned int>(tmp);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
972 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
973 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
974 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
975 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
976 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
977 "Bad value for argument: " + std::string(ARG_WIDTH));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
978 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
979 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
980
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
981 if (call.HasArgument(ARG_HEIGHT))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
982 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
983 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
984 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
985 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
986 if (tmp < 0)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
987 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
988 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
989 "Argument cannot be negative: " + std::string(ARG_HEIGHT));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
990 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
991 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
992 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
993 argHeight = static_cast<unsigned int>(tmp);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
994 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
995 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
996 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
997 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
998 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
999 "Bad value for argument: " + std::string(ARG_HEIGHT));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1000 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1001 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1002
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1003 smooth = false;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1004
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1005 if (call.HasArgument(ARG_SMOOTH))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1006 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1007 std::string value = call.GetArgument(ARG_SMOOTH, "");
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1008 if (value == "0" ||
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1009 value == "false")
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1010 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1011 smooth = false;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1012 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1013 else if (value == "1" ||
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1014 value == "true")
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1015 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1016 smooth = true;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1017 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1018 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1019 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1020 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1021 "Argument must be Boolean: " + std::string(ARG_SMOOTH));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1022 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1023 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1024 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1025
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1026
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1027 public:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1028 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
1029 std::unique_ptr<ImageAccessor>& decoded,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1030 const DicomMap& dicom) ORTHANC_OVERRIDE
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1031 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1032 bool invert;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1033 float rescaleSlope, rescaleIntercept, windowWidth, windowCenter;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1034 GetDicomParameters(invert, rescaleSlope, rescaleIntercept, windowWidth, windowCenter, dicom);
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1035
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1036 unsigned int argWidth, argHeight;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1037 bool smooth;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1038 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
1039
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1040 unsigned int targetWidth = decoded->GetWidth();
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1041 unsigned int targetHeight = decoded->GetHeight();
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1042
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1043 if (decoded->GetWidth() != 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1044 decoded->GetHeight() != 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1045 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1046 float ratio = 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1047
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1048 if (argWidth != 0 &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1049 argHeight != 0)
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1050 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1051 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
1052 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
1053 ratio = std::min(ratioX, ratioY);
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1054 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1055 else if (argWidth != 0)
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1056 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1057 ratio = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth());
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1058 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1059 else if (argHeight != 0)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1060 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1061 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
1062 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1063
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1064 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
1065 targetHeight = boost::math::iround(ratio * static_cast<float>(decoded->GetHeight()));
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1066 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1067
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1068 if (decoded->GetFormat() == PixelFormat_RGB24)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1069 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1070 if (targetWidth == decoded->GetWidth() &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1071 targetHeight == decoded->GetHeight())
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1072 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1073 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1074 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1075 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1076 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
1077 std::unique_ptr<ImageAccessor> resized(
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1078 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
1079
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1080 if (smooth &&
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1081 (targetWidth < decoded->GetWidth() ||
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1082 targetHeight < decoded->GetHeight()))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1083 {
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4055
diff changeset
1084 ImageProcessing::SmoothGaussian5x5(*decoded, false /* be fast, don't round */);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1085 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1086
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1087 ImageProcessing::Resize(*resized, *decoded);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1088 DefaultHandler(call, resized, ImageExtractionMode_Preview, false);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1089 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1090 }
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1091 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1092 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1093 // 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
1094 // 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
1095
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1096 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
1097 ImageProcessing::Convert(converted, *decoded);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1098
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1099 // Avoid divisions by zero
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1100 if (windowWidth <= 1.0f)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1101 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1102 windowWidth = 1;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1103 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1104
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1105 if (std::abs(rescaleSlope) <= 0.1f)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1106 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1107 rescaleSlope = 0.1f;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1108 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1109
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1110 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
1111 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
1112
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
1113 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
1114 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
1115
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1116 if (targetWidth == decoded->GetWidth() &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1117 targetHeight == decoded->GetHeight())
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1118 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1119 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1120 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1121 else
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1122 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
1123 std::unique_ptr<ImageAccessor> resized(
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1124 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
1125
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1126 if (smooth &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1127 (targetWidth < decoded->GetWidth() ||
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1128 targetHeight < decoded->GetHeight()))
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1129 {
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4055
diff changeset
1130 ImageProcessing::SmoothGaussian5x5(*rescaled, false /* be fast, don't round */);
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1131 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1132
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1133 ImageProcessing::Resize(*resized, *rescaled);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1134 DefaultHandler(call, resized, ImageExtractionMode_UInt8, invert);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1135 }
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1136 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1137 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1138
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1139 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1140 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1141 return true;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1142 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1143 };
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
1144 }
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
1145
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1146
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 template <enum ImageExtractionMode mode>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1148 static void GetImage(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
1150 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
1151
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1152 GetImageHandler handler(mode);
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
1153 IDecodedFrameHandler::Apply(call, handler, mode, false /* not rendered */);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1154 }
1906
d7c1cb559431 optimization for multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
1155
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1156
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1157 static void GetRenderedFrame(RestApiGetCall& call)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1158 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
1159 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
1160
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1161 RenderedFrameHandler handler;
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
1162 IDecodedFrameHandler::Apply(call, handler, ImageExtractionMode_Preview /* arbitrary value */, true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1166 static void GetMatlabImage(RestApiGetCall& call)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1167 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
1168 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
1169
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1170 ServerContext& context = OrthancRestApi::GetContext(call);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1171
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1172 std::string frameId = call.GetUriComponent("frame", "0");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1173
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1174 unsigned int frame;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1175 try
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1176 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1177 frame = boost::lexical_cast<unsigned int>(frameId);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1178 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
1179 catch (boost::bad_lexical_cast&)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1180 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1181 return;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1182 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1183
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1184 std::string publicId = call.GetUriComponent("id", "");
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1185 std::unique_ptr<ImageAccessor> decoded(context.DecodeDicomFrame(publicId, frame));
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1186
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1187 if (decoded.get() == NULL)
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1188 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1189 throw OrthancException(ErrorCode_NotImplemented,
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1190 "Cannot decode DICOM instance with ID: " + publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1191 }
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1192 else
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1193 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1194 std::string result;
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1195 decoded->ToMatlabString(result);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1196 call.GetOutput().AnswerBuffer(result, MimeType_PlainText);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1197 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1198 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1199
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1200
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1201 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
1202 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
1203 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1204 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
1205
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1206 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
1207 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
1208 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1209 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
1210 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
1211 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
1212 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1213 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
1214 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1215
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1216 std::string publicId = call.GetUriComponent("id", "");
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1217 std::string raw;
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1218 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
1219
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1220 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1221 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
1222 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
1223 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1224
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1225 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
1226 {
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1227 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
1228 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
1229 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
1230 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
1231 }
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1232 else
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1233 {
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1234 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
1235 }
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
1236 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1237
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1238
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1239 static void GetResourceStatistics(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 {
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1241 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
1242
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 std::string publicId = call.GetUriComponent("id", "");
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1244
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1245 ResourceType type;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1246 uint64_t diskSize, uncompressedSize, dicomDiskSize, dicomUncompressedSize;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1247 unsigned int countStudies, countSeries, countInstances;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1248 OrthancRestApi::GetIndex(call).GetResourceStatistics(
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1249 type, diskSize, uncompressedSize, countStudies, countSeries,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1250 countInstances, dicomDiskSize, dicomUncompressedSize, publicId);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1251
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1252 Json::Value result = Json::objectValue;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1253 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
1254 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
1255 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
1256 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
1257
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1258 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
1259 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
1260 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
1261 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
1262
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1263 switch (type)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1264 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1265 // Do NOT add "break" below this point!
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1266 case ResourceType_Patient:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1267 result["CountStudies"] = countStudies;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1268
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1269 case ResourceType_Study:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1270 result["CountSeries"] = countSeries;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1271
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1272 case ResourceType_Series:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1273 result["CountInstances"] = countInstances;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1274
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1275 case ResourceType_Instance:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1276 default:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1277 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1278 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1279
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282
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 // Handling of metadata -----------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
1287 static void CheckValidResourceType(const RestApiCall& 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 std::string resourceType = call.GetUriComponent("resourceType", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 StringToResourceType(resourceType.c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1294 static void ListMetadata(RestApiGetCall& call)
751
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 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 std::string publicId = call.GetUriComponent("id", "");
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1299 std::map<MetadataType, std::string> metadata;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1301 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
1302
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1303 Json::Value result;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1305 if (call.HasArgument("expand"))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 {
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1307 result = Json::objectValue;
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1308
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1309 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
1310 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
1311 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1312 std::string key = EnumerationToString(it->first);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1313 result[key] = it->second;
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1314 }
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1315 }
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1316 else
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1317 {
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1318 result = Json::arrayValue;
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1319
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1320 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
1321 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
1322 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1323 result.append(EnumerationToString(it->first));
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1324 }
751
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1331 static void GetMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 CheckValidResourceType(call);
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 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 std::string value;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, publicId, metadata))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1342 call.GetOutput().AnswerBuffer(value, MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1347 static void DeleteMetadata(RestApiDeleteCall& call)
751
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 CheckValidResourceType(call);
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 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1355 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
1356 {
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1358 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1360 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1361 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1362 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
1363 }
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1367 static void SetMetadata(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 CheckValidResourceType(call);
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 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 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
1374
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1375 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
1376 call.BodyToString(value);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1378 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 // It is forbidden to modify internal metadata
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 OrthancRestApi::GetIndex(call).SetMetadata(publicId, metadata, value);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1382 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1384 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1385 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1386 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
1387 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 // Handling of attached files -----------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1395 static void ListAttachments(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 std::string resourceType = call.GetUriComponent("resourceType", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 std::list<FileContentType> attachments;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str()));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 for (std::list<FileContentType>::const_iterator
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 it = attachments.begin(); it != attachments.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407 result.append(EnumerationToString(*it));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1414 static bool GetAttachmentInfo(FileInfo& info, RestApiCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422 return OrthancRestApi::GetIndex(call).LookupAttachment(info, publicId, contentType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423 }
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
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1426 static void GetAttachmentOperations(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1427 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1429 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1430 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1431 Json::Value operations = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1432
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1433 operations.append("compress");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1434 operations.append("compressed-data");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1435
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1436 if (info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1438 operations.append("compressed-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1440
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1441 operations.append("compressed-size");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1442 operations.append("data");
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1443 operations.append("is-compressed");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1444
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445 if (info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1447 operations.append("md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1448 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1449
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1450 operations.append("size");
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1451 operations.append("uncompress");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453 if (info.GetCompressedMD5() != "" &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1454 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 operations.append("verify-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 call.GetOutput().AnswerJson(operations);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1460 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462
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 template <int uncompress>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1465 static void GetAttachmentData(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1467 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 std::string publicId = call.GetUriComponent("id", "");
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1472 FileContentType type = StringToContentType(call.GetUriComponent("name", ""));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1474 if (uncompress)
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1475 {
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1476 context.AnswerAttachment(call.GetOutput(), publicId, type);
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1477 }
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1478 else
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1479 {
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1480 // 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
1481 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
1482 context.ReadAttachment(content, publicId, type, false);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1483 call.GetOutput().AnswerBuffer(content, MimeType_Binary);
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1484 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1488 static void GetAttachmentSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1493 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
1494 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1495 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1498 static void GetAttachmentCompressedSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1503 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
1504 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1508 static void GetAttachmentMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1510 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1511 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1514 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
1515 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1519 static void GetAttachmentCompressedMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1521 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1522 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523 info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1525 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
1526 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1530 static void VerifyAttachment(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 if (!GetAttachmentInfo(info, call) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540 info.GetCompressedMD5() == "" ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 info.GetUncompressedMD5() == "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 // Inexistent resource, or no MD5 available
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 bool ok = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 // 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
1550 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
1551 context.ReadAttachment(data, publicId, StringToContentType(name), false);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 std::string actualMD5;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 if (actualMD5 == info.GetCompressedMD5())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 // The compressed data is OK. If a compression algorithm was
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559 // applied to it, now check the MD5 of the uncompressed data.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 if (info.GetCompressionType() == CompressionType_None)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 ok = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 {
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1566 context.ReadAttachment(data, publicId, StringToContentType(name), true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 ok = (actualMD5 == info.GetUncompressedMD5());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 if (ok)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573 {
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4272
diff changeset
1574 CLOG(INFO, HTTP) << "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
1575 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1576 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1578 {
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4272
diff changeset
1579 CLOG(INFO, HTTP) << "The attachment " << name << " of resource " << publicId << " has bad MD5!";
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1584 static void UploadAttachment(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1589 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1590 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1591
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1592 FileContentType contentType = StringToContentType(name);
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1593 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
1594 context.AddAttachment(publicId, StringToContentType(name), call.GetBodyData(), call.GetBodySize()))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1595 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1596 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1597 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1598 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1599 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1600 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
1601 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1604
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1605 static void DeleteAttachment(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1609 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1610 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1613 bool allowed;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1614 if (IsUserContentType(contentType))
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1615 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1616 allowed = true;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1617 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1618 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1619 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1620 OrthancConfiguration::ReaderLock lock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1621
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1622 if (lock.GetConfiguration().GetBooleanParameter("StoreDicom", true) &&
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1623 contentType == FileContentType_DicomAsJson)
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1624 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1625 allowed = true;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1626 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1627 else
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1628 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1629 // 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
1630 // 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
1631 // 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
1632 allowed = false;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
1633 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1634 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1635
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1636 if (allowed)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1639 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1640 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1641 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1642 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1643 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
1644 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1648 template <enum CompressionType compression>
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1649 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
1650 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1651 CheckValidResourceType(call);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1652
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1653 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
1654 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
1655 FileContentType contentType = StringToContentType(name);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1656
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1657 OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1658 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
1659 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1660
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1661
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1662 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
1663 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1664 FileInfo info;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1665 if (GetAttachmentInfo(info, call))
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1666 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1667 std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1";
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1668 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
1669 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1670 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1671
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1672
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1673 // Raw access to the DICOM tags of an instance ------------------------------
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1674
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1675 static void GetRawContent(RestApiGetCall& call)
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1676 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1677 if (call.IsDocumentation())
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1678 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1679 call.GetDocumentation()
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1680 .SetTag("Instances")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1681 .SetSummary("Get raw tag")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1682 .SetDescription("Get the raw content of one DICOM tag in the hierarchy of DICOM dataset")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1683 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1684 .SetUriArgument("...", "Path to the DICOM tag. This is the interleaving of one DICOM tag, possibly followed "
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1685 "by an index for sequences. Sequences are accessible as, for instance, `/0008-1140/1/0008-1150`")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1686 .AddAnswerType(MimeType_Binary, "The raw value of the tag of intereset "
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1687 "(binary data, whose memory layout depends on the underlying transfer syntax), "
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1688 "or JSON array containing the list of available tags if accessing a dataset");
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1689 return;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1690 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
1691
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1692 std::string id = call.GetUriComponent("id", "");
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1693
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1694 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1695
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1696 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1697 }
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
1698
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1699
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1700
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1701 static bool ExtractSharedTags(Json::Value& shared,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1702 ServerContext& context,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1703 const std::string& publicId)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1704 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1705 // 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
1706 typedef std::list<std::string> Instances;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1707 Instances instances;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1708 context.GetIndex().GetChildInstances(instances, publicId); // (*)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1709
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1710 // Loop over the instances
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1711 bool isFirst = true;
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1712 shared = Json::objectValue;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1713
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1714 for (Instances::const_iterator it = instances.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1715 it != instances.end(); ++it)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1716 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1717 // 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
1718 Json::Value tags;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1719
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1720 try
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1721 {
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
1722 context.ReadDicomAsJson(tags, *it);
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1723 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1724 catch (OrthancException&)
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1725 {
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1726 // Race condition: This instance has been removed since
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1727 // (*). Ignore this instance.
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1728 continue;
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1729 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
1730
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1731 if (tags.type() != Json::objectValue)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1732 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1733 return false; // Error
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1734 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1735
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1736 // 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
1737 Json::Value::Members members = tags.getMemberNames();
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1738 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
1739 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1740 const Json::Value& tag = tags[members[i]];
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1741 if (tag.type() != Json::objectValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1742 tag["Type"].type() != Json::stringValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1743 tag["Type"].asString() != "String")
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1744 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1745 tags.removeMember(members[i]);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1746 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1747 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1748
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1749 if (isFirst)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1750 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1751 // 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
1752 shared = tags;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1753 isFirst = false;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1754 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1755 else
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1756 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1757 // 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
1758 // 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
1759 // value in the current instance, remove it.
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1760 members = shared.getMemberNames();
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1761 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
1762 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1763 if (!tags.isMember(members[i]) ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1764 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
1765 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1766 shared.removeMember(members[i]);
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1767 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1768 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1769 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1770 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1771
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1772 return true;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1773 }
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1774
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1775
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1776 static void GetSharedTags(RestApiGetCall& call)
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1777 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1778 ServerContext& context = OrthancRestApi::GetContext(call);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1779 std::string publicId = call.GetUriComponent("id", "");
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1780
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1781 Json::Value sharedTags;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1782 if (ExtractSharedTags(sharedTags, context, publicId))
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1783 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1784 // 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
1785 AnswerDicomAsJson(call, sharedTags);
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
1786 }
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1787 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1788
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
1789
1054
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1790 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
1791 ResourceType resourceType,
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1792 DicomModule module)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1793 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1794 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1795 (resourceType == ResourceType_Study && module == DicomModule_Patient) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1796 (resourceType == ResourceType_Study && module == DicomModule_Study) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1797 (resourceType == ResourceType_Series && module == DicomModule_Series) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1798 (resourceType == ResourceType_Instance && module == DicomModule_Instance) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1799 (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
1800 {
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1801 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
1802 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1803
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1804 ServerContext& context = OrthancRestApi::GetContext(call);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1805 std::string publicId = call.GetUriComponent("id", "");
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1806
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1807 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1808 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1809
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1810 typedef std::set<DicomTag> ModuleTags;
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1811 ModuleTags moduleTags;
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
1812 DicomTag::AddTagsForModule(moduleTags, module);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1813
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1814 Json::Value tags;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1815
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1816 if (resourceType != ResourceType_Instance)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1817 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1818 // Retrieve all the instances of this patient/study/series
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1819 typedef std::list<std::string> Instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1820 Instances instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1821 context.GetIndex().GetChildInstances(instances, publicId);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1822
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1823 if (instances.empty())
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1824 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1825 return; // Error: No instance (should never happen)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1826 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1827
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1828 // Select one child instance
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1829 publicId = instances.front();
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1830 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1831
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
1832 context.ReadDicomAsJson(tags, publicId, ignoreTagLength);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1833
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1834 // 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
1835 Json::Value result = Json::objectValue;
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
1836 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
1837 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1838 std::string s = tag->Format();
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1839 if (tags.isMember(s))
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1840 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1841 result[s] = tags[s];
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1842 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1843 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1844
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1845 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
1846 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1847
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1848
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
1849
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1850 template <enum ResourceType resourceType,
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1851 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
1852 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
1853 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
1854 GetModuleInternal(call, resourceType, module);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1855 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1856
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
1857
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1858 namespace
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1859 {
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1860 typedef std::list< std::pair<ResourceType, std::string> > LookupResults;
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1861 }
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1862
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1863
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1864 static void AccumulateLookupResults(LookupResults& result,
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1865 ServerIndex& index,
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1866 const DicomTag& tag,
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1867 const std::string& value,
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1868 ResourceType level)
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1869 {
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1870 std::vector<std::string> tmp;
1728
4941494b5dd8 rename LookupIdentifier as LookupIdentifierExact
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1727
diff changeset
1871 index.LookupIdentifierExact(tmp, level, tag, value);
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1872
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1873 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
1874 {
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1875 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
1876 }
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1877 }
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1878
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1879
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1880 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
1881 {
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1882 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
1883 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
1884
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1885 LookupResults resources;
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1886 ServerIndex& index = OrthancRestApi::GetIndex(call);
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
1887 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
1888 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
1889 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
1890 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
1891
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1892 Json::Value result = Json::arrayValue;
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
1893 for (LookupResults::const_iterator
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
1894 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
1895 {
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1896 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
1897 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
1898
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1899 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
1900 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
1901 item["ID"] = id;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1902 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
1903
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1904 result.append(item);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1905 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1906
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1907 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
1908 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1909
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
1910
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1911 namespace
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1912 {
3021
2cbafb5d5a62 renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
1913 class FindVisitor : public ServerContext::ILookupVisitor
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1914 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1915 private:
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1916 bool isComplete_;
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1917 std::list<std::string> resources_;
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1918
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1919 public:
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1920 FindVisitor() :
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1921 isComplete_(false)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1922 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1923 }
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
1924
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
1925 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
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
1926 {
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
1927 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
1928 }
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
1929
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
1930 virtual void MarkAsComplete() ORTHANC_OVERRIDE
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1931 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1932 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
1933 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1934
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1935 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
1936 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
1937 const DicomMap& mainDicomTags /* unused */,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
1938 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1939 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1940 resources_.push_back(publicId);
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1941 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1942
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1943 void Answer(RestApiOutput& output,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1944 ServerIndex& index,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1945 ResourceType level,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1946 bool expand) const
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1947 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1948 AnswerListOfResources(output, index, resources_, level, expand);
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1949 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1950 };
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1951 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1952
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1953
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1954 static void Find(RestApiPostCall& call)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1955 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1956 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1957 static const char* const KEY_EXPAND = "Expand";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1958 static const char* const KEY_LEVEL = "Level";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1959 static const char* const KEY_LIMIT = "Limit";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1960 static const char* const KEY_QUERY = "Query";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1961 static const char* const KEY_SINCE = "Since";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1962
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1356
diff changeset
1963 ServerContext& context = OrthancRestApi::GetContext(call);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1964
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
1965 Json::Value request;
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1966 if (!call.ParseJsonRequest(request) ||
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1967 request.type() != Json::objectValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1968 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1969 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1970 "The body must contain a JSON object");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1971 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1972 else if (!request.isMember(KEY_LEVEL) ||
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1973 request[KEY_LEVEL].type() != Json::stringValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1974 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1975 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1976 "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
1977 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1978 else if (!request.isMember(KEY_QUERY) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1979 request[KEY_QUERY].type() != Json::objectValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1980 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1981 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1982 "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
1983 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1984 else if (request.isMember(KEY_CASE_SENSITIVE) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1985 request[KEY_CASE_SENSITIVE].type() != Json::booleanValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1986 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1987 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1988 "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
1989 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1990 else if (request.isMember(KEY_LIMIT) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1991 request[KEY_LIMIT].type() != Json::intValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1992 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1993 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1994 "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
1995 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1996 else if (request.isMember(KEY_SINCE) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1997 request[KEY_SINCE].type() != Json::intValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1998 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
1999 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2000 "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
2001 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2002 else
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2003 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2004 bool expand = false;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2005 if (request.isMember(KEY_EXPAND))
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2006 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2007 expand = request[KEY_EXPAND].asBool();
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2008 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2009
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2010 bool caseSensitive = false;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2011 if (request.isMember(KEY_CASE_SENSITIVE))
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2012 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2013 caseSensitive = request[KEY_CASE_SENSITIVE].asBool();
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2014 }
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2015
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2016 size_t limit = 0;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2017 if (request.isMember(KEY_LIMIT))
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2018 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2019 int tmp = request[KEY_LIMIT].asInt();
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
2020 if (tmp < 0)
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2021 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2022 throw OrthancException(ErrorCode_ParameterOutOfRange,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2023 "Field \"" + std::string(KEY_LIMIT) + "\" should be a positive integer");
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2024 }
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
2025
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
2026 limit = static_cast<size_t>(tmp);
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2027 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2028
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2029 size_t since = 0;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2030 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
2031 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2032 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
2033 if (tmp < 0)
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2034 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2035 throw OrthancException(ErrorCode_ParameterOutOfRange,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2036 "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
2037 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2038
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2039 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
2040 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2041
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
2042 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
2043
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
2044 DatabaseLookup query;
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1356
diff changeset
2045
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2046 Json::Value::Members members = request[KEY_QUERY].getMemberNames();
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2047 for (size_t i = 0; i < members.size(); i++)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2048 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2049 if (request[KEY_QUERY][members[i]].type() != Json::stringValue)
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2050 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2051 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2052 "Tag \"" + members[i] + "\" should be associated with a string");
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2053 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2054
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
2055 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
2056
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
2057 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
2058 {
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
2059 // 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
2060 // 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
2061 // "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
2062 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
2063 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
2064 }
1361
94ffb597d297 refactoring of C-Find SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
2065 }
2876
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2836
diff changeset
2066
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2067 FindVisitor visitor;
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
2068 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
2069 visitor.Answer(call.GetOutput(), context.GetIndex(), level, expand);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2070 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2071 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2072
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2073
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
2074 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
2075 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
2076 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
2077 {
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
2078 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
2079
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
2080 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
2081 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
2082
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
2083 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
2084 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
2085 {
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
2086 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
2087
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
2088 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2089 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
2090 {
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
2091 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
2092 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
2093 }
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
2094
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
2095 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
2096
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
2097 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
2098 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
2099 }
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
2100
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
2101 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
2102
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
2103 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2104 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
2105 {
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
2106 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
2107
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
2108 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
2109 {
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
2110 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
2111 }
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
2112 }
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
2113
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
2114 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
2115 }
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
2116
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
2117
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2118 static void GetChildInstancesTags(RestApiGetCall& call)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2119 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2120 ServerContext& context = OrthancRestApi::GetContext(call);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2121 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
2122 DicomToJsonFormat format = GetDicomFormat(call);
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2123
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2124 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2125 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2126
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2127 // Retrieve all the instances of this patient/study/series
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2128 typedef std::list<std::string> Instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2129 Instances instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2130
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2131 context.GetIndex().GetChildInstances(instances, publicId); // (*)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2132
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
2133 Json::Value result = Json::objectValue;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2134
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2135 for (Instances::const_iterator it = instances.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2136 it != instances.end(); ++it)
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2137 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2138 Json::Value full;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2139 context.ReadDicomAsJson(full, *it, ignoreTagLength);
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2140
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
2141 if (format != DicomToJsonFormat_Full)
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2142 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2143 Json::Value simplified;
4055
9214e3a7b0a2 moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
2144 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
2145 result[*it] = simplified;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2146 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2147 else
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2148 {
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
2149 result[*it] = full;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2150 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2151 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2152
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2153 call.GetOutput().AnswerJson(result);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2154 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2155
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2156
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
2157
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
2158 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
2159 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
2160 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
2161 {
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
2162 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
2163
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
2164 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
2165
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
2166 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
2167 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
2168 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
2169 {
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
2170 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
2171 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
2172 {
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
2173 // 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
2174 // 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
2175 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
2176 }
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
2177
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
2178 current = parent;
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
2179 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
2180 }
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
2181
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
2182 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
2183
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
2184 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
2185 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
2186 {
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
2187 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
2188 }
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
2189 }
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
2190
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
2191
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2192 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
2193 {
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2194 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
2195
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2196 std::string pdf;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2197 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
2198
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2199 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
2200 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2201 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
2202 return;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2203 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2204 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2205
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
2206
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2207 static void OrderSlices(RestApiGetCall& call)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2208 {
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2209 const std::string id = call.GetUriComponent("id", "");
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2210
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2211 ServerIndex& index = OrthancRestApi::GetIndex(call);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2212 SliceOrdering ordering(index, id);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2213
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
2214 Json::Value result;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
2215 ordering.Format(result);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
2216 call.GetOutput().AnswerJson(result);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2217 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2218
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2219
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2220 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
2221 {
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2222 if (call.IsDocumentation())
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2223 {
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2224 call.GetDocumentation()
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2225 .SetTag("Instances")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2226 .SetSummary("Get DICOM meta-header")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2227 .SetDescription("Get the DICOM tags in the meta-header of the DICOM instance. By default, the `full` format is used, which "
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2228 "combines hexadecimal tags with human-readable description.")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2229 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2230 .SetHttpGetArgument("simplify", RestApiCallDocumentation::Type_String,
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2231 "If present, report the DICOM tags in human-readable format", false)
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2232 .SetHttpGetArgument("short", RestApiCallDocumentation::Type_String,
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2233 "If present, report the DICOM tags indexed in hexadecimal format", false)
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2234 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2235 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/header", true);
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2236 return;
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2237 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2238
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2239 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
2240
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2241 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
2242
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2243 std::string dicomContent;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
2244 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
2245
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
2246 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
2247 // speed up things here
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
2248
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2249 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
2250
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2251 Json::Value header;
4140
0ddc5297a8ab centralization of default parameters for JSON/DicomMap conversions from DCMTK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
2252 OrthancConfiguration::DefaultDicomHeaderToJson(header, dicom);
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2253
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
2254 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
2255 }
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2256
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2257
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
2258 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
2259 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2260 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
2261
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2262 // 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
2263 // 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
2264 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
2265 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
2266
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2267 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
2268 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
2269 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2270 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
2271 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
2272
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2273 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
2274 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
2275 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2276 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
2277 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2278 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2279
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2280 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
2281 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2282
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
2283
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
2284 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
2285 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
2286 {
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2287 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
2288 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""));
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2289 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
2290 }
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2291
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2292
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2293 static void ReconstructAllResources(RestApiPostCall& call)
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2294 {
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2295 ServerContext& context = OrthancRestApi::GetContext(call);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2296
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2297 std::list<std::string> studies;
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2298 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
2299
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2300 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
2301 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
2302 {
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2303 ServerToolbox::ReconstructResource(context, *study);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2304 }
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2305
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2306 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
2307 }
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2308
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
2309
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2310 void OrthancRestApi::RegisterResources()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2311 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2312 Register("/instances", ListResources<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2313 Register("/patients", ListResources<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2314 Register("/series", ListResources<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2315 Register("/studies", ListResources<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2316
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2317 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2318 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2319 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2320 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2321 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2322 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2323 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2324 Register("/studies/{id}", GetSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2325
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2326 Register("/instances/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2327 Register("/patients/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2328 Register("/studies/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2329 Register("/series/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2330
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2331 Register("/patients/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2332 Register("/series/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2333 Register("/studies/{id}/shared-tags", GetSharedTags);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2334
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2335 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2336 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2337 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2338 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2339 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
2340
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2341 Register("/instances/{id}/file", GetInstanceFile);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2342 Register("/instances/{id}/export", ExportInstanceFile);
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
2343 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
2344 Register("/instances/{id}/simplified-tags", GetInstanceTags<DicomToJsonFormat_Human>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2345 Register("/instances/{id}/frames", ListFrames);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2346
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2347 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
2348 Register("/instances/{id}/frames/{frame}/rendered", GetRenderedFrame);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2349 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2350 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2351 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
2352 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
2353 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
2354 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
2355 Register("/instances/{id}/pdf", ExtractPdf);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2356 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
2357 Register("/instances/{id}/rendered", GetRenderedFrame);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2358 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2359 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2360 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
2361 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
2362 Register("/instances/{id}/header", GetInstanceHeader);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2363
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2364 Register("/patients/{id}/protected", IsProtectedPatient);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2365 Register("/patients/{id}/protected", SetPatientProtection);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2366
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2367 Register("/{resourceType}/{id}/metadata", ListMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2368 Register("/{resourceType}/{id}/metadata/{name}", DeleteMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2369 Register("/{resourceType}/{id}/metadata/{name}", GetMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2370 Register("/{resourceType}/{id}/metadata/{name}", SetMetadata);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2371
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2372 Register("/{resourceType}/{id}/attachments", ListAttachments);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2373 Register("/{resourceType}/{id}/attachments/{name}", DeleteAttachment);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2374 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
2375 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
2376 Register("/{resourceType}/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2377 Register("/{resourceType}/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2378 Register("/{resourceType}/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2379 Register("/{resourceType}/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2380 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
2381 Register("/{resourceType}/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2382 Register("/{resourceType}/{id}/attachments/{name}/md5", GetAttachmentMD5);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2383 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
2384 Register("/{resourceType}/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2385 Register("/{resourceType}/{id}/attachments/{name}/verify-md5", VerifyAttachment);
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2386
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
2387 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
2388 Register("/tools/lookup", Lookup);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2389 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
2390
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
2391 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
2392 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
2393 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
2394 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
2395 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
2396 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
2397
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
2398 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
2399 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
2400 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
2401 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
2402 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
2403 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
2404
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2405 Register("/patients/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2406 Register("/studies/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2407 Register("/series/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2408
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2409 Register("/instances/{id}/content/*", GetRawContent);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2410
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2411 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
2412
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
2413 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
2414 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
2415 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
2416 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
2417 Register("/tools/reconstruct", ReconstructAllResources);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2418 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2419 }