annotate OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4698:d16c3c7f11ef

new route "/tools/bulk-content" to get the content of a set of resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Jun 2021 16:37:12 +0200
parents 569d9ef165b1
children facea16b055b
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4424
diff changeset
5 * Copyright (C) 2017-2021 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"
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
47 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
48
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
49 #include "../OrthancConfiguration.h"
3094
61da3c9b4121 cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3085
diff changeset
50 #include "../Search/DatabaseLookup.h"
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1385
diff changeset
51 #include "../ServerContext.h"
2131
bb199bccdc45 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
52 #include "../ServerToolbox.h"
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
53 #include "../SliceOrdering.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
3687
e6d6f8d23d02 fix linking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3686
diff changeset
55 // This "include" is mandatory for Release builds using Linux Standard Base
e6d6f8d23d02 fix linking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3686
diff changeset
56 #include <boost/math/special_functions/round.hpp>
e6d6f8d23d02 fix linking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3686
diff changeset
57
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
59 /**
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
60 * 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
61 * 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
62 * 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
63 **/
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
64 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
65
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
66
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
67 static const std::string CHECK_REVISIONS = "CheckRevisions";
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
68
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
69
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
72 static std::string GetDocumentationSampleResource(ResourceType type)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
73 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
74 switch (type)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
75 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
76 case Orthanc::ResourceType_Instance:
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
77 return "https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2";
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
78 break;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
79
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
80 case Orthanc::ResourceType_Series:
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
81 return "https://demo.orthanc-server.com/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52";
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
82 break;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
83
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
84 case Orthanc::ResourceType_Study:
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
85 return "https://demo.orthanc-server.com/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988";
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
86 break;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
87
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
88 case Orthanc::ResourceType_Patient:
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
89 return "https://demo.orthanc-server.com/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382";
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
90 break;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
91
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
92 default:
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
93 throw OrthancException(ErrorCode_ParameterOutOfRange);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
94 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
95 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
96
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
97
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
98 static void AnswerDicomAsJson(RestApiCall& call,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
99 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
100 DicomToJsonFormat mode)
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
101 {
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
102 if (mode != DicomToJsonFormat_Full)
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
103 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
104 Json::Value simplified;
4055
9214e3a7b0a2 moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
105 Toolbox::SimplifyDicomAsJson(simplified, dicom, mode);
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
106 call.GetOutput().AnswerJson(simplified);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
107 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
108 else
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
109 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
110 call.GetOutput().AnswerJson(dicom);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
111 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
112 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
113
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 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
116 const RestApiGetCall& call,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
117 const std::string& 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 target.clear();
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
120
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
121 if (call.HasArgument(argument))
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
122 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
123 std::vector<std::string> tags;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
124 Toolbox::TokenizeString(tags, call.GetArgument(argument, ""), ',');
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 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
127 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
128 target.insert(FromDcmtkBridge::ParseTag(tags[i]));
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
129 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
130 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
131 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
132
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
133
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 // List all the patients, studies, series or instances ----------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
136 static void AnswerListOfResources(RestApiOutput& output,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
137 ServerIndex& index,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
138 const std::list<std::string>& resources,
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
139 ResourceType level,
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
140 bool expand,
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
141 DicomToJsonFormat format)
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 Json::Value answer = Json::arrayValue;
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 for (std::list<std::string>::const_iterator
1384
d6971e18a324 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1374
diff changeset
146 resource = resources.begin(); resource != resources.end(); ++resource)
1354
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 if (expand)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
149 {
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
150 Json::Value expanded;
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
151 if (index.ExpandResource(expanded, *resource, level, format))
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
152 {
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
153 answer.append(expanded);
1354
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 else
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
157 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
158 answer.append(*resource);
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 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
161
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
162 output.AnswerJson(answer);
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
163 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
164
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
165
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
167 static void ListResources(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
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
169 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
170 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
171 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
172
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 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
174 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
175 .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
176 .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
177 .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
178 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false)
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
179 .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
180 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String,
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
181 "If present, retrieve detailed information about the individual " + resources, false)
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
182 .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
183 "about the reported " + resources + " (if `expand` argument is provided)")
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
184 .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
185 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
186 }
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
187
1342
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
188 ServerIndex& index = OrthancRestApi::GetIndex(call);
9ec7ac03152d "?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
189
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
190 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
191
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
192 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
193 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
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("limit"))
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 \"limit\" 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 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
203 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
204 throw OrthancException(ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
205 "Missing \"since\" argument for GET request against: " +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
206 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
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
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
209 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
210 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
211 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
212 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
213 else
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
214 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
215 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
216 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
217
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
218 AnswerListOfResources(call.GetOutput(), index, result, resourceType, call.HasArgument("expand"),
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
219 OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
222
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
223
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
225 static void GetSingleResource(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
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
227 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
228 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
229 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
230
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
231 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
232 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
233 .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
234 .SetSummary("Get information about some " + resource)
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
235 .SetDescription("Get detailed information about the DICOM " + resource + " whose Orthanc identifier is provided in the URL")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
236 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
237 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource)
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
238 .SetHttpGetSample(GetDocumentationSampleResource(resourceType), 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
239 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
240 }
4551
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
241
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
242 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
243
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
244 Json::Value json;
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
245 if (OrthancRestApi::GetIndex(call).ExpandResource(
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
246 json, call.GetUriComponent("id", ""), resourceType, format))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
248 call.GetOutput().AnswerJson(json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
253 static void DeleteSingleResource(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
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
255 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
256 {
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
257 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
258 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
259 .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
260 .SetSummary("Delete some " + resource)
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
261 .SetDescription("Delete the DICOM " + resource + " whose Orthanc identifier is provided in the URL")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
262 .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
263 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
264 }
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
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
266 Json::Value remainingAncestor;
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
267 if (OrthancRestApi::GetContext(call).DeleteResource(remainingAncestor, call.GetUriComponent("id", ""), resourceType))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
269 call.GetOutput().AnswerJson(remainingAncestor);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 // Get information about a single patient -----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
276 static void IsProtectedPatient(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
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
278 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
279 {
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
280 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
281 .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
282 .SetSummary("Is the patient protected against recycling?")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
283 .SetUriArgument("id", "Orthanc identifier of the patient of interest")
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
284 .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
285 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
286 }
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
287
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
290 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
294 static void SetPatientProtection(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
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
296 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
297 {
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
298 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
299 .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
300 .SetSummary("Protect one patient against recycling")
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
301 .SetDescription("Check out configuration options `MaximumStorageSize` and `MaximumPatientCount`")
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
302 .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
303 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
304 }
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
305
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
4473
68f52897c119 new URIs: /tools/accepted-transfer-syntaxes and /tools/unknown-sop-class-accepted to replace Lua callbacks for transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4460
diff changeset
310 context.GetIndex().SetProtectedPatient(publicId, call.ParseBooleanBody());
68f52897c119 new URIs: /tools/accepted-transfer-syntaxes and /tools/unknown-sop-class-accepted to replace Lua callbacks for transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4460
diff changeset
311 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 // Get information about a single instance ----------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
317 static void GetInstanceFile(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
319 if (call.IsDocumentation())
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
320 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
321 call.GetDocumentation()
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
322 .SetTag("Instances")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
323 .SetSummary("Download DICOM")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
324 .SetDescription("Download one DICOM instance")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
325 .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
326 .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
327 .AddAnswerType(MimeType_Dicom, "The DICOM instance")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
328 .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
329 .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
330 return;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
331 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
332
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 ServerContext& context = OrthancRestApi::GetContext(call);
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 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
336
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4294
diff changeset
337 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
338 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
339 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
340 // 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
341 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
342 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
343 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
344
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
345 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
346 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
347 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
348 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
349
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
350 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
351 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
352 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
353 }
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
354
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
355 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
356 {
810772486249 URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
357 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
358 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
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 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
361 {
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 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
363 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
364 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
365 }
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
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 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
368 }
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 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
371 {
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 }
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
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
375 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
379 static void ExportInstanceFile(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
381 if (call.IsDocumentation())
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
382 {
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
383 call.GetDocumentation()
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
384 .SetTag("Instances")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
385 .SetSummary("Write DICOM onto filesystem")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
386 .SetDescription("Write the DICOM file onto the filesystem where Orthanc is running")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
387 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
388 .AddRequestType(MimeType_PlainText, "Target path on the filesystem");
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
389 return;
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
390 }
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
391
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 std::string dicom;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
397 context.ReadDicom(dicom, publicId);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
399 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
400 call.BodyToString(target);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
401 SystemToolbox::WriteFile(dicom, target);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
403 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
407 template <DicomToJsonFormat format>
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
408 static void GetInstanceTagsInternal(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 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
413
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
414 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
415 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
417 if (format != DicomToJsonFormat_Full ||
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
418 !ignoreTagLength.empty())
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 {
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
420 Json::Value full;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
421 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
422 AnswerDicomAsJson(call, full, format);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
3973
d86bddb50972 fix spelling errors according to debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3928
diff changeset
426 // 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
427 // 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
428 // is present
4513
1f455b86b054 simplification in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4473
diff changeset
429 Json::Value full;
2127
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
430 context.ReadDicomAsJson(full, publicId);
4513
1f455b86b054 simplification in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4473
diff changeset
431 call.GetOutput().AnswerJson(full);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
435
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
436 static void GetInstanceTags(RestApiGetCall& call)
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
437 {
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
438 if (call.IsDocumentation())
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
439 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
440 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full);
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
441 call.GetDocumentation()
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
442 .SetTag("Instances")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
443 .SetSummary("Get DICOM tags")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
444 .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
445 "combines hexadecimal tags with human-readable description.")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
446 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
447 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
448 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10);
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
449 return;
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
450 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
451
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
452 switch (OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full))
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
453 {
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
454 case DicomToJsonFormat_Human:
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
455 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call);
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
456 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
457
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
458 case DicomToJsonFormat_Short:
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
459 GetInstanceTagsInternal<DicomToJsonFormat_Short>(call);
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
460 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
461
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
462 case DicomToJsonFormat_Full:
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
463 GetInstanceTagsInternal<DicomToJsonFormat_Full>(call);
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
464 break;
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
465
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
466 default:
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
467 throw OrthancException(ErrorCode_InternalError);
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
468 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
469 }
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
470
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
472 static void GetInstanceSimplifiedTags(RestApiGetCall& call)
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
473 {
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
474 if (call.IsDocumentation())
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
475 {
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
476 call.GetDocumentation()
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
477 .SetTag("Instances")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
478 .SetSummary("Get human-readable tags")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
479 .SetDescription("Get the DICOM tags in human-readable format (same as the `/instances/{id}/tags?simplify` route)")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
480 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
481 .SetHttpGetArgument("ignore-length", RestApiCallDocumentation::Type_JsonListOfStrings,
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
482 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false)
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
483 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
484 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", 10);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
485 return;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
486 }
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
487 else
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
488 {
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
489 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
490 }
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
491 }
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
492
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
493
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
494 static void ListFrames(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
496 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
497 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
498 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
499 .SetTag("Instances")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
500 .SetSummary("List available frames")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
501 .SetDescription("List the frames that are available in the DICOM instance of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
502 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
503 .AddAnswerType(MimeType_Json, "The list of the indices of the available frames")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
504 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/frames", true);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
505 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
506 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
507
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
508 std::string publicId = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
510 unsigned int numberOfFrames;
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
511
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
512 {
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
513 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
514 numberOfFrames = locker.GetDicom().GetFramesCount();
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
516
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
517 Json::Value result = Json::arrayValue;
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
518 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
519 {
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
520 result.append(i);
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
521 }
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
522
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
523 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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 namespace
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
528 {
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
529 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
530 {
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
531 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
532 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
533 ImageExtractionMode mode_;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
534 bool invert_;
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
535 MimeType format_;
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
536 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
537
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
538 public:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
539 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
540 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
541 bool invert) :
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
542 image_(image),
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
543 mode_(mode),
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
544 invert_(invert),
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
545 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
546 {
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
547 }
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 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
550 {
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
551 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
552 }
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
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
554 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
555 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
556 format_ = MimeType_Png;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
557 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
558 }
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
559
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
560 void EncodeUsingPam()
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
561 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
562 format_ = MimeType_Pam;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
563 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
564 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
565
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
566 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
567 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
568 format_ = MimeType_Jpeg;
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
569 DicomImageDecoder::ExtractJpegImage(answer_, image_, mode_, invert_, quality);
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1784
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 };
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
572
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
573 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
574 {
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 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
576 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
577
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 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
579 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
580 {
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 }
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
582
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 virtual void Handle(const std::string& type,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
584 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
585 {
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
586 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
587 assert(subtype == "png");
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
588 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
589 }
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
590 };
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
591
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
592 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
593 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
594 private:
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
595 ImageToEncode& image_;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
596
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
597 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
598 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
599 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
600 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
601
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
602 virtual void Handle(const std::string& type,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
603 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
604 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
605 assert(type == "image");
2780
am@osimis.io
parents: 2726
diff changeset
606 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
607 image_.EncodeUsingPam();
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
608 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
diff changeset
609 };
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2622
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 class EncodeJpeg : public HttpContentNegociation::IHandler
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
612 {
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
613 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
614 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
615 unsigned int quality_;
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
616
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
617 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
618 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
619 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
620 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
621 {
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
622 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
623 bool ok = false;
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
624
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
625 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
626 {
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 quality_ = boost::lexical_cast<unsigned int>(v);
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
628 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
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 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
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 }
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
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
634 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
635 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
636 throw OrthancException(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
637 ErrorCode_BadRequest,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
638 "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
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 }
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
641
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 virtual void Handle(const std::string& type,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
643 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
644 {
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
645 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
646 assert(subtype == "jpeg");
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
647 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
648 }
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
649 };
1781
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
650 }
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
651
5ad4e4d92ecb AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1773
diff changeset
652
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
653 namespace
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
654 {
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
655 class IDecodedFrameHandler : public boost::noncopyable
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
656 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
657 public:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
658 virtual ~IDecodedFrameHandler()
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 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
661
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
662 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
663 std::unique_ptr<ImageAccessor>& decoded,
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
664 const DicomMap& dicom) = 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 virtual bool RequiresDicomTags() const = 0;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
667
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
668 static void Apply(RestApiGetCall& call,
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
669 IDecodedFrameHandler& handler,
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
670 ImageExtractionMode mode /* for generation of documentation */,
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
671 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
672 {
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
673 if (call.IsDocumentation())
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
674 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
675 std::string m;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
676 if (!isRendered)
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 switch (mode)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
679 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
680 case ImageExtractionMode_Preview:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
681 m = "preview";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
682 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
683 case ImageExtractionMode_UInt8:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
684 m = "uint8";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
685 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
686 case ImageExtractionMode_UInt16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
687 m = "uint16";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
688 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
689 case ImageExtractionMode_Int16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
690 m = "int16";
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
691 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
692 default:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
693 throw OrthancException(ErrorCode_ParameterOutOfRange);
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 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
696
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
697 std::string description;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
698 std::string verb = (isRendered ? "Render" : "Decode");
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 if (call.HasUriComponent("frame"))
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
701 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
702 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
703 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
704 .SetSummary(verb + " a frame" + (m.empty() ? "" : " (" + m + ")"))
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
705 .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
706 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
707 else
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
708 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
709 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
710 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
711 .SetSummary(verb + " an image" + (m.empty() ? "" : " (" + m + ")"));
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
712 }
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 if (isRendered)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
715 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
716 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
717 "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
718 "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
719 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
720 .SetHttpGetArgument("window-center",RestApiCallDocumentation::Type_Number, "Windowing center", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
721 .SetHttpGetArgument("window-width",RestApiCallDocumentation::Type_Number, "Windowing width", false)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
722 .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
723 .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
724 .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
725 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
726 else
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 switch (mode)
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
729 {
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
730 case ImageExtractionMode_Preview:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
731 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
732 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
733 case ImageExtractionMode_UInt8:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
734 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
735 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
736 case ImageExtractionMode_UInt16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
737 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
738 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
739 case ImageExtractionMode_Int16:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
740 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
741 "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
742 break;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
743 default:
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
744 throw OrthancException(ErrorCode_ParameterOutOfRange);
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 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
747
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
748 call.GetDocumentation()
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
749 .SetTag("Instances")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
750 .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
751 .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
752 .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
753 .AddAnswerType(MimeType_Png, "PNG image")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
754 .AddAnswerType(MimeType_Jpeg, "JPEG image")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
755 .AddAnswerType(MimeType_Pam, "PAM image (Portable Arbitrary Map)")
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
756 .SetDescription(description);
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 return;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
759 }
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
760
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
761 ServerContext& context = OrthancRestApi::GetContext(call);
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 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
764
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
765 unsigned int frame;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
766 try
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 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
769 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
770 catch (boost::bad_lexical_cast&)
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 return;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
773 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
774
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
775 DicomMap dicom;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
776 std::unique_ptr<ImageAccessor> decoded;
3683
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 try
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
779 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
780 std::string publicId = call.GetUriComponent("id", "");
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
781
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
782 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
783
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
784 if (decoded.get() == NULL)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
785 {
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
786 throw OrthancException(ErrorCode_NotImplemented,
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
787 "Cannot decode DICOM instance with ID: " + publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
788 }
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 if (handler.RequiresDicomTags())
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
791 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
792 /**
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
793 * Retrieve a summary of the DICOM tags, which is
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
794 * necessary to deal with MONOCHROME1 photometric
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
795 * interpretation, and with windowing parameters.
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
796 **/
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
797 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
798 OrthancConfiguration::DefaultExtractDicomSummary(dicom, locker.GetDicom());
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
799 }
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 catch (OrthancException& e)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
802 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
803 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange ||
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
804 e.GetErrorCode() == ErrorCode_UnknownResource)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
805 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
806 // 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
807 // instance, the resource is not existent
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 else
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
810 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
811 std::string root = "";
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
812 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
813 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
814 root += "../";
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
815 }
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 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
818 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
819 return;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
820 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
821
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
822 handler.Handle(call, decoded, dicom);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
823 }
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
824
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
825
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
826 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
827 std::unique_ptr<ImageAccessor>& decoded,
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
828 ImageExtractionMode mode,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
829 bool 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 ImageToEncode image(decoded, mode, invert);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
832
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
833 HttpContentNegociation negociation;
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
834 EncodePng png(image);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
835 negociation.Register(MIME_PNG, png);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
836
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
837 EncodeJpeg jpeg(image, call);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
838 negociation.Register(MIME_JPEG, jpeg);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
839
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
840 EncodePam pam(image);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
841 negociation.Register(MIME_PAM, pam);
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 if (negociation.Apply(call.GetHttpHeaders()))
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 image.Answer(call.GetOutput());
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
846 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
847 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
848 };
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
849
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
850
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
851 class GetImageHandler : public IDecodedFrameHandler
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
852 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
853 private:
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
854 ImageExtractionMode mode_;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
855
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
856 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
857 explicit GetImageHandler(ImageExtractionMode mode) :
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
858 mode_(mode)
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 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
861
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
862 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
863 std::unique_ptr<ImageAccessor>& decoded,
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
864 const DicomMap& dicom) ORTHANC_OVERRIDE
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 bool invert = false;
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 if (mode_ == ImageExtractionMode_Preview)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
869 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
870 DicomImageInformation info(dicom);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
871 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1);
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
872 }
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
873
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
874 DefaultHandler(call, decoded, mode_, invert);
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
875 }
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 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE
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 return mode_ == ImageExtractionMode_Preview;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
880 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
881 };
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
882
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
883
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
884 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
885 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
886 private:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
887 static void GetDicomParameters(bool& invert,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
888 float& rescaleSlope,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
889 float& rescaleIntercept,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
890 float& windowWidth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
891 float& windowCenter,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
892 const DicomMap& dicom)
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
893 {
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
894 DicomImageInformation info(dicom);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
895
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
896 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
897
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
898 rescaleSlope = 1.0f;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
899 rescaleIntercept = 0.0f;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
900
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
901 if (dicom.HasTag(Orthanc::DICOM_TAG_RESCALE_SLOPE) &&
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
902 dicom.HasTag(Orthanc::DICOM_TAG_RESCALE_INTERCEPT))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
903 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
904 dicom.ParseFloat(rescaleSlope, Orthanc::DICOM_TAG_RESCALE_SLOPE);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
905 dicom.ParseFloat(rescaleIntercept, Orthanc::DICOM_TAG_RESCALE_INTERCEPT);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
906 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
907
3816
09f091b6b569 /rendered route: fix automatic windowing of files without windowing tags and RescaleSlope != 1
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
908 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
909 windowCenter = windowWidth / 2.0f + rescaleIntercept;
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
910
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
911 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
912 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
913 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
914 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
915 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
916 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
917 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
918
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
919 static void GetUserArguments(float& windowWidth /* inout */,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
920 float& windowCenter /* inout */,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
921 unsigned int& argWidth,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
922 unsigned int& argHeight,
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
923 bool& smooth,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
924 const RestApiGetCall& call)
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
925 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
926 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
927 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
928 static const char* ARG_WIDTH = "width";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
929 static const char* ARG_HEIGHT = "height";
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
930 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
931
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
932 if (call.HasArgument(ARG_WINDOW_WIDTH))
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 try
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 windowWidth = boost::lexical_cast<float>(call.GetArgument(ARG_WINDOW_WIDTH, ""));
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 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
939 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
940 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
941 "Bad value for argument: " + std::string(ARG_WINDOW_WIDTH));
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 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
944
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
945 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
946 {
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
947 try
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 windowCenter = boost::lexical_cast<float>(call.GetArgument(ARG_WINDOW_CENTER, ""));
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 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
952 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
953 throw OrthancException(ErrorCode_ParameterOutOfRange,
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
954 "Bad value for argument: " + std::string(ARG_WINDOW_CENTER));
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
955 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
956 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
957
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
958 argWidth = 0;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
959 argHeight = 0;
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
960
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
961 if (call.HasArgument(ARG_WIDTH))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
962 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
963 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
964 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
965 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
966 if (tmp < 0)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
967 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
968 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
969 "Argument cannot be negative: " + std::string(ARG_WIDTH));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
970 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
971 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
972 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
973 argWidth = static_cast<unsigned int>(tmp);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
974 }
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 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
977 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
978 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
979 "Bad value for argument: " + std::string(ARG_WIDTH));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
980 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
981 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
982
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
983 if (call.HasArgument(ARG_HEIGHT))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
984 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
985 try
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
986 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
987 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
988 if (tmp < 0)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
989 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
990 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
991 "Argument cannot be negative: " + std::string(ARG_HEIGHT));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
992 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
993 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
994 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
995 argHeight = static_cast<unsigned int>(tmp);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
996 }
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 catch (boost::bad_lexical_cast&)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
999 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1000 throw OrthancException(ErrorCode_ParameterOutOfRange,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1001 "Bad value for argument: " + std::string(ARG_HEIGHT));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1002 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1003 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1004
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1005 smooth = false;
3685
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 if (call.HasArgument(ARG_SMOOTH))
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1008 {
4473
68f52897c119 new URIs: /tools/accepted-transfer-syntaxes and /tools/unknown-sop-class-accepted to replace Lua callbacks for transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4460
diff changeset
1009 smooth = RestApiCall::ParseBoolean(call.GetArgument(ARG_SMOOTH, ""));
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1010 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1011 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1012
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1013
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1014 public:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1015 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
1016 std::unique_ptr<ImageAccessor>& decoded,
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1017 const DicomMap& dicom) ORTHANC_OVERRIDE
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1018 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1019 bool invert;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1020 float rescaleSlope, rescaleIntercept, windowWidth, windowCenter;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1021 GetDicomParameters(invert, rescaleSlope, rescaleIntercept, windowWidth, windowCenter, dicom);
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1022
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1023 unsigned int argWidth, argHeight;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1024 bool smooth;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1025 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
1026
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1027 unsigned int targetWidth = decoded->GetWidth();
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1028 unsigned int targetHeight = decoded->GetHeight();
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1029
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1030 if (decoded->GetWidth() != 0 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1031 decoded->GetHeight() != 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1032 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1033 float ratio = 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1034
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1035 if (argWidth != 0 &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1036 argHeight != 0)
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1037 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1038 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
1039 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
1040 ratio = std::min(ratioX, ratioY);
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1041 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1042 else if (argWidth != 0)
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1043 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1044 ratio = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth());
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1045 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1046 else if (argHeight != 0)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1047 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1048 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
1049 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1050
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1051 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
1052 targetHeight = boost::math::iround(ratio * static_cast<float>(decoded->GetHeight()));
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1053 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1054
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1055 if (decoded->GetFormat() == PixelFormat_RGB24)
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1056 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1057 if (targetWidth == decoded->GetWidth() &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1058 targetHeight == decoded->GetHeight())
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1059 {
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1060 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false);
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1061 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1062 else
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1063 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
1064 std::unique_ptr<ImageAccessor> resized(
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1065 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
1066
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1067 if (smooth &&
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1068 (targetWidth < decoded->GetWidth() ||
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1069 targetHeight < decoded->GetHeight()))
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1070 {
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4055
diff changeset
1071 ImageProcessing::SmoothGaussian5x5(*decoded, false /* be fast, don't round */);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1072 }
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1073
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1074 ImageProcessing::Resize(*resized, *decoded);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1075 DefaultHandler(call, resized, ImageExtractionMode_Preview, false);
3685
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1076 }
2cc34837d694 rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3683
diff changeset
1077 }
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1078 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1079 {
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1080 // 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
1081 // 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
1082
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1083 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
1084 ImageProcessing::Convert(converted, *decoded);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1085
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1086 // Avoid divisions by zero
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1087 if (windowWidth <= 1.0f)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1088 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1089 windowWidth = 1;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1090 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1091
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1092 if (std::abs(rescaleSlope) <= 0.1f)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1093 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1094 rescaleSlope = 0.1f;
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
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1097 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
1098 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
1099
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
1100 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
1101 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
1102
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1103 if (targetWidth == decoded->GetWidth() &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1104 targetHeight == decoded->GetHeight())
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1105 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1106 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1107 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1108 else
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1109 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
1110 std::unique_ptr<ImageAccessor> resized(
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1111 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
1112
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1113 if (smooth &&
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1114 (targetWidth < decoded->GetWidth() ||
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1115 targetHeight < decoded->GetHeight()))
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1116 {
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4055
diff changeset
1117 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
1118 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1119
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1120 ImageProcessing::Resize(*resized, *rescaled);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1121 DefaultHandler(call, resized, ImageExtractionMode_UInt8, invert);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3687
diff changeset
1122 }
3686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3685
diff changeset
1123 }
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1124 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1125
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1126 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1127 {
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1128 return true;
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1129 }
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1130 };
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
1131 }
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3203
diff changeset
1132
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1133
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 template <enum ImageExtractionMode mode>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1135 static void GetImage(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
1137 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
1138
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1139 GetImageHandler handler(mode);
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
1140 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
1141 }
1906
d7c1cb559431 optimization for multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1902
diff changeset
1142
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
1143
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1144 static void GetRenderedFrame(RestApiGetCall& call)
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1145 {
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
1146 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
1147
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1148 RenderedFrameHandler handler;
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
1149 IDecodedFrameHandler::Apply(call, handler, ImageExtractionMode_Preview /* arbitrary value */, true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1153 static void GetMatlabImage(RestApiGetCall& call)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1154 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1155 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1156 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1157 std::string description;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1158
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1159 if (call.HasUriComponent("frame"))
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1160 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1161 description = "Decode one frame of interest from the given DICOM instance";
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1162 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1163 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1164 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1165 else
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1166 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1167 description = "Decode the first frame of the given DICOM instance.";
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1168 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1169
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1170 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1171 .SetTag("Instances")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1172 .SetSummary("Decode frame for Matlab")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1173 .SetDescription(description + ", and export this frame as a Octave/Matlab matrix to be imported with `eval()`: "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1174 "https://book.orthanc-server.com/faq/matlab.html")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1175 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1176 .AddAnswerType(MimeType_PlainText, "Octave/Matlab matrix");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1177 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1178 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1179
3926
2910b0d30fe0 Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3816
diff changeset
1180 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
1181
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1182 ServerContext& context = OrthancRestApi::GetContext(call);
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 frameId = call.GetUriComponent("frame", "0");
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1185
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1186 unsigned int frame;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1187 try
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1188 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1189 frame = boost::lexical_cast<unsigned int>(frameId);
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1190 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
1191 catch (boost::bad_lexical_cast&)
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1192 {
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1193 return;
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1194 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1195
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1196 std::string publicId = call.GetUriComponent("id", "");
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1197 std::unique_ptr<ImageAccessor> decoded(context.DecodeDicomFrame(publicId, frame));
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1198
3928
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1199 if (decoded.get() == NULL)
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1200 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1201 throw OrthancException(ErrorCode_NotImplemented,
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1202 "Cannot decode DICOM instance with ID: " + publicId);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1203 }
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1204 else
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1205 {
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1206 std::string result;
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1207 decoded->ToMatlabString(result);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1208 call.GetOutput().AnswerBuffer(result, MimeType_PlainText);
4cdc875510d1 ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3926
diff changeset
1209 }
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1210 }
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1211
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1212
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1213 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
1214 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
1215 {
4408
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1216 if (call.IsDocumentation())
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1217 {
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1218 call.GetDocumentation()
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1219 .SetTag("Instances")
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1220 .SetSummary("Access raw frame" + std::string(GzipCompression ? " (compressed)" : ""))
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1221 .SetDescription("Access the raw content of one individual frame of the DICOM instance of interest, "
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1222 "bypassing image decoding. This is notably useful to access the source files "
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1223 "in compressed transfer syntaxes." +
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1224 std::string(GzipCompression ? " The image is compressed using gzip" : ""))
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4422
diff changeset
1225 .SetUriArgument("id", "Orthanc identifier of the instance of interest")
4408
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1226 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)");
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1227
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1228 if (GzipCompression)
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1229 {
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1230 call.GetDocumentation().AddAnswerType(MimeType_Gzip, "The raw frame, compressed using gzip");
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1231 }
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1232 else
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1233 {
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1234 call.GetDocumentation().AddAnswerType(MimeType_Binary, "The raw frame");
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1235 }
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1236 return;
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1237 }
d2bfadc2948b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4407
diff changeset
1238
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
1239 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
1240
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1241 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
1242 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
1243 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1244 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
1245 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2804
diff changeset
1246 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
1247 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1248 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
1249 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1250
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1251 std::string publicId = call.GetUriComponent("id", "");
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1252 std::string raw;
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1253 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
1254
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1255 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1256 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
1257 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
1258 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1259
2408
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1260 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
1261 {
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1262 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
1263 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
1264 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
1265 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
1266 }
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1267 else
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1268 {
26a0cc24d48d New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
1269 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
1270 }
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
1271 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1272
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
1273
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1274 static void GetResourceStatistics(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 {
4418
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1276 if (call.IsDocumentation())
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1277 {
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1278 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1279 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1280 call.GetDocumentation()
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1281 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1282 .SetSummary("Get " + r + " statistics")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1283 .SetDescription("Get statistics about the given " + r)
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1284 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1285 .SetAnswerField("DiskSize", RestApiCallDocumentation::Type_String,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1286 "Size of the " + r + " on the disk in bytes, expressed as a string for 64bit compatibility with JSON")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1287 .SetAnswerField("DiskSizeMB", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1288 "Size of the " + r + " on the disk, expressed in megabytes (MB)")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1289 .SetAnswerField("UncompressedSize", RestApiCallDocumentation::Type_String,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1290 "Size of the " + r + " after decompression in bytes, expressed as a string for 64bit compatibility with JSON")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1291 .SetAnswerField("UncompressedSizeMB", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1292 "Size of the " + r + " after decompression, expressed in megabytes (MB). "
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1293 "This is different from `DiskSizeMB` iff `StorageCompression` is `true`.")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1294 .SetAnswerField("DicomDiskSize", RestApiCallDocumentation::Type_String,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1295 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in bytes")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1296 .SetAnswerField("DicomDiskSizeMB", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1297 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in megabytes (MB)")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1298 .SetAnswerField("DicomUncompressedSize", RestApiCallDocumentation::Type_String,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1299 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in bytes")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1300 .SetAnswerField("DicomUncompressedSizeMB", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1301 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in megabytes (MB)")
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1302 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/statistics", true);
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1303
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1304 switch (t)
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1305 {
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1306 // Do NOT add "break" below this point!
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1307 case ResourceType_Patient:
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1308 call.GetDocumentation().SetAnswerField("CountStudies", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1309 "Number of child studies within this " + r);
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1310
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1311 case ResourceType_Study:
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1312 call.GetDocumentation().SetAnswerField("CountSeries", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1313 "Number of child series within this " + r);
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1314
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1315 case ResourceType_Series:
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1316 call.GetDocumentation().SetAnswerField("CountInstances", RestApiCallDocumentation::Type_Number,
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1317 "Number of child instances within this " + r);
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1318
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1319 case ResourceType_Instance:
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1320 default:
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1321 break;
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1322 }
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1323
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1324 return;
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1325 }
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1326
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1327 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
1328
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 std::string publicId = call.GetUriComponent("id", "");
3174
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1330
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1331 ResourceType type;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1332 uint64_t diskSize, uncompressedSize, dicomDiskSize, dicomUncompressedSize;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1333 unsigned int countStudies, countSeries, countInstances;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1334 OrthancRestApi::GetIndex(call).GetResourceStatistics(
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1335 type, diskSize, uncompressedSize, countStudies, countSeries,
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1336 countInstances, dicomDiskSize, dicomUncompressedSize, publicId);
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1337
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1338 Json::Value result = Json::objectValue;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1339 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
1340 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
1341 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
1342 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
1343
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1344 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
1345 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
1346 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
1347 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
1348
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1349 switch (type)
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1350 {
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1351 // Do NOT add "break" below this point!
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1352 case ResourceType_Patient:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1353 result["CountStudies"] = countStudies;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1354
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1355 case ResourceType_Study:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1356 result["CountSeries"] = countSeries;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1357
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1358 case ResourceType_Series:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1359 result["CountInstances"] = countInstances;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1360
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1361 case ResourceType_Instance:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1362 default:
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1363 break;
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1364 }
8ea7c4546c3a primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3163
diff changeset
1365
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369
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 // Handling of metadata -----------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
1373 static void CheckValidResourceType(const RestApiCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 {
4460
6831de40acd9 New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1375 assert(!call.GetFullUri().empty());
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1376 const std::string resourceType = call.GetFullUri() [0];
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377 StringToResourceType(resourceType.c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378 }
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
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1381 static void ListMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1383 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1384 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1385 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1386 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1387 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1388 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1389 .SetSummary("List metadata")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1390 .SetDescription("Get the list of metadata that are associated with the given " + r)
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1391 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1392 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String,
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1393 "If present, also retrieve the value of the individual metadata", false)
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1394 .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1395 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1396 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1397 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1398 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1399
4460
6831de40acd9 New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1400 assert(!call.GetFullUri().empty());
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1401 const std::string publicId = call.GetUriComponent("id", "");
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1402 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str());
4551
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
1403
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
1404 typedef std::map<MetadataType, std::string> Metadata;
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
1405
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
1406 Metadata metadata;
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1407 OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId, level);
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1408
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1409 Json::Value result;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1411 if (call.HasArgument("expand"))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 {
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1413 result = Json::objectValue;
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1414
4551
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
1415 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1416 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1417 std::string key = EnumerationToString(it->first);
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1418 result[key] = it->second;
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1419 }
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1420 }
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1421 else
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1422 {
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1423 result = Json::arrayValue;
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1424
4551
350a22c094f2 testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4514
diff changeset
1425 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1426 {
3187
4bbadcd03966 refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3174
diff changeset
1427 result.append(EnumerationToString(it->first));
2726
46061a91c88a new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2704
diff changeset
1428 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1429 }
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 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1432 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1433
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1434
4657
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
1435 static void SetStringContentETag(const RestApiOutput& output,
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
1436 int64_t revision,
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
1437 const std::string& value)
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1438 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1439 std::string md5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1440 Toolbox::ComputeMD5(md5, value);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1441 const std::string etag = "\"" + boost::lexical_cast<std::string>(revision) + "-" + md5 + "\"";
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1442 output.GetLowLevelOutput().AddHeader("ETag", etag);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1443 }
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1444
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1445
4657
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
1446 static void SetBufferContentETag(const RestApiOutput& output,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1447 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1448 const void* data,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1449 size_t size)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1450 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1451 std::string md5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1452 Toolbox::ComputeMD5(md5, data, size);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1453 const std::string etag = "\"" + boost::lexical_cast<std::string>(revision) + "-" + md5 + "\"";
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1454 output.GetLowLevelOutput().AddHeader("ETag", etag);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1455 }
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1456
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1457
4657
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
1458 static void SetAttachmentETag(const RestApiOutput& output,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1459 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1460 const FileInfo& info)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1461 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1462 const std::string etag = ("\"" + boost::lexical_cast<std::string>(revision) + "-" +
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1463 info.GetUncompressedMD5() + "\"");
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1464 output.GetLowLevelOutput().AddHeader("ETag", etag);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1465 }
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1466
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1467
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1468 static std::string GetMD5(const std::string& value)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1469 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1470 std::string md5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1471 Toolbox::ComputeMD5(md5, value);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1472 return md5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1473 }
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1474
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1475
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1476 static bool GetRevisionHeader(int64_t& revision /* out */,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1477 std::string& md5 /* out */,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1478 const RestApiCall& call,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1479 const std::string& header)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1480 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1481 std::string lower;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1482 Toolbox::ToLowerCase(lower, header);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1483
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1484 HttpToolbox::Arguments::const_iterator found = call.GetHttpHeaders().find(lower);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1485 if (found == call.GetHttpHeaders().end())
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1486 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1487 return false;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1488 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1489 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1490 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1491 std::string value = Toolbox::StripSpaces(found->second);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1492 Toolbox::RemoveSurroundingQuotes(value);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1493
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1494 try
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1495 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1496 size_t comma = value.find('-');
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1497 if (comma != std::string::npos)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1498 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1499 revision = boost::lexical_cast<int64_t>(value.substr(0, comma));
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1500 md5 = value.substr(comma + 1);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1501 return true;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1502 }
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1503 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1504 catch (boost::bad_lexical_cast&)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1505 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1506 }
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1507
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1508 throw OrthancException(ErrorCode_ParameterOutOfRange, "The \"" + header +
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1509 "\" HTTP header should contain the ETag (revision followed by MD5 hash), but found: " + value);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1510 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1511 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1512
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1513
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1514 static void GetMetadata(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1515 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1516 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1517 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1518 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1519 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1520 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1521 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1522 .SetSummary("Get metadata")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1523 .SetDescription("Get the value of a metadata that is associated with the given " + r)
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1524 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1525 .SetUriArgument("name", "The name of the metadata, or its index (cf. `UserMetadata` configuration option)")
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1526 .AddAnswerType(MimeType_PlainText, "Value of the metadata")
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1527 .SetAnswerHeader("ETag", "Revision of the metadata, to be used in further `PUT` or `DELETE` operations")
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1528 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed");
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1529 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1530 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1531
4460
6831de40acd9 New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1532 assert(!call.GetFullUri().empty());
6831de40acd9 New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1533 const std::string publicId = call.GetUriComponent("id", "");
6831de40acd9 New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1534 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str());
6831de40acd9 New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1535
751
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 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 std::string value;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1540 int64_t revision;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1541 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, revision, publicId, level, metadata))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1543 SetStringContentETag(call.GetOutput(), revision, value); // New in Orthanc 1.9.2
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1544
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1545 int64_t userRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1546 std::string userMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1547 if (GetRevisionHeader(userRevision, userMD5, call, "If-None-Match") &&
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1548 userRevision == revision &&
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1549 userMD5 == GetMD5(value))
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1550 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1551 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1552 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1553 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1554 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1555 call.GetOutput().AnswerBuffer(value, MimeType_PlainText);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1556 }
751
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 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1561 static void DeleteMetadata(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1563 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1564 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1565 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1566 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1567 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1568 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1569 .SetSummary("Delete metadata")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1570 .SetDescription("Delete some metadata associated with the given DICOM " + r +
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1571 ". This call will fail if trying to delete a system metadata (i.e. whose index is < 1024).")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1572 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1573 .SetUriArgument("name", "The name of the metadata, or its index (cf. `UserMetadata` configuration option)")
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1574 .SetHttpHeader("If-Match", "Revision of the metadata, to check if its content has not changed and can "
4661
b1d87d41874e typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4657
diff changeset
1575 "be deleted. This header is mandatory if `CheckRevisions` option is `true`.");
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1576 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1577 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1578
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 CheckValidResourceType(call);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1580 const std::string publicId = call.GetUriComponent("id", "");
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1581
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583 MetadataType metadata = StringToMetadata(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1585 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1586 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1587 bool found;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1588 int64_t revision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1589 std::string md5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1590 if (GetRevisionHeader(revision, md5, call, "if-match"))
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1591 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1592 found = OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata, true, revision, md5);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1593 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1594 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1595 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1596 OrthancConfiguration::ReaderLock lock;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1597 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1598 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1599 throw OrthancException(ErrorCode_Revision,
4661
b1d87d41874e typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4657
diff changeset
1600 "HTTP header \"If-Match\" is missing, as \"CheckRevisions\" is \"true\"");
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1601 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1602 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1603 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1604 found = OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata, false, -1 /* dummy value */, "");
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1605 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1606 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1607
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1608 if (found)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1609 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1610 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1611 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1612 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1613 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1614 throw OrthancException(ErrorCode_UnknownResource);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1615 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1616 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1617 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1618 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1619 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
1620 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1621 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1622
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1623
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1624 static void SetMetadata(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1625 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1626 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1627 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1628 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1629 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1630 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1631 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1632 .SetSummary("Set metadata")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1633 .SetDescription("Set the value of some metadata in the given DICOM " + r +
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1634 ". This call will fail if trying to modify a system metadata (i.e. whose index is < 1024).")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1635 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1636 .SetUriArgument("name", "The name of the metadata, or its index (cf. `UserMetadata` configuration option)")
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1637 .AddRequestType(MimeType_PlainText, "String value of the metadata")
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1638 .SetHttpHeader("If-Match", "Revision of the metadata, if this is not the first time this metadata is set.");
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1639 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1640 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1641
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1642 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 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
1647
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
1648 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
1649 call.BodyToString(value);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1650
1773
613df4362575 New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1759
diff changeset
1651 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1652 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1653 int64_t oldRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1654 std::string oldMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1655 bool hasOldRevision = GetRevisionHeader(oldRevision, oldMD5, call, "if-match");
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1656
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1657 if (!hasOldRevision)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1658 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1659 OrthancConfiguration::ReaderLock lock;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1660 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1661 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1662 // "StatelessDatabaseOperations::SetMetadata()" will ignore
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1663 // the actual value of "oldRevision" if the metadata is
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1664 // inexistent as expected
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1665 hasOldRevision = true;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1666 oldRevision = -1; // dummy value
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1667 oldMD5.clear(); // dummy value
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1668 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1669 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1670
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
1671 int64_t newRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1672 OrthancRestApi::GetIndex(call).SetMetadata(newRevision, publicId, metadata, value,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1673 hasOldRevision, oldRevision, oldMD5);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1674
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1675 SetStringContentETag(call.GetOutput(), newRevision, value); // New in Orthanc 1.9.2
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1676 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1677 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1678 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1679 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
1680 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
1681 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1685
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687 // Handling of attached files -----------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1689 static void ListAttachments(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1691 if (call.IsDocumentation())
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1692 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1693 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1694 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1695 call.GetDocumentation()
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1696 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1697 .SetSummary("List attachments")
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1698 .SetDescription("Get the list of attachments that are associated with the given " + r)
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1699 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1700 .AddAnswerType(MimeType_Json, "JSON array containing the names of the attachments")
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1701 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/attachments", true);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1702 return;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1703 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1704
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1705 const std::string resourceType = call.GetFullUri() [0];
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1706 const std::string publicId = call.GetUriComponent("id", "");
4514
5b929e6b3c36 removal of "dicom-as-json" attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4513
diff changeset
1707 std::set<FileContentType> attachments;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1708 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str()));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1709
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1710 Json::Value result = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1711
4514
5b929e6b3c36 removal of "dicom-as-json" attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4513
diff changeset
1712 for (std::set<FileContentType>::const_iterator
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1713 it = attachments.begin(); it != attachments.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1714 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1715 result.append(EnumerationToString(*it));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1716 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1717
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1718 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1719 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1720
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1721
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1722 static void AddAttachmentDocumentation(RestApiGetCall& call,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1723 const std::string& resourceType)
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1724 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1725 call.GetDocumentation()
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1726 .SetUriArgument("id", "Orthanc identifier of the " + resourceType + " of interest")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1727 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1728 .SetAnswerHeader("ETag", "Revision of the attachment, to be used in further `PUT` or `DELETE` operations")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1729 .SetHttpHeader("If-None-Match", "Optional revision of the attachment, to check if its content has changed");
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1730 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1731
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1732
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1733 static bool GetAttachmentInfo(FileInfo& info,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1734 RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1735 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1736 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1737
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1738 const std::string publicId = call.GetUriComponent("id", "");
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1739 const std::string name = call.GetUriComponent("name", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1740 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1741
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1742 int64_t revision;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1743 if (OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1744 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1745 SetAttachmentETag(call.GetOutput(), revision, info); // New in Orthanc 1.9.2
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1746
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1747 int64_t userRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1748 std::string userMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1749 if (GetRevisionHeader(userRevision, userMD5, call, "If-None-Match") &&
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1750 revision == userRevision &&
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1751 info.GetUncompressedMD5() == userMD5)
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1752 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1753 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1754 return false;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1755 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1756 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1757 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1758 return true;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1759 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1760 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1761 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1762 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1763 throw OrthancException(ErrorCode_UnknownResource);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1764 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1765 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1767
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1768 static void GetAttachmentOperations(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1770 if (call.IsDocumentation())
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1771 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1772 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1773 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1774 AddAttachmentDocumentation(call, r);
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1775 call.GetDocumentation()
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1776 .SetTag("Other")
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1777 .SetSummary("List operations on attachments")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1778 .SetDescription("Get the list of the operations that are available for attachments associated with the given " + r)
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1779 .AddAnswerType(MimeType_Json, "List of the available operations")
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1780 .SetHttpGetSample("https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2/attachments/dicom", true);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1781 return;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1782 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1783
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1784 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1785 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1786 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1787 Json::Value operations = Json::arrayValue;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1788
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1789 operations.append("compress");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1790 operations.append("compressed-data");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1791
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1792 if (info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1793 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1794 operations.append("compressed-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1795 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1796
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1797 operations.append("compressed-size");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1798 operations.append("data");
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1799 operations.append("is-compressed");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1800
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1801 if (info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1802 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1803 operations.append("md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1804 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1805
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1806 operations.append("size");
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
1807 operations.append("uncompress");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1808
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1809 if (info.GetCompressedMD5() != "" &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1810 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1811 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1812 operations.append("verify-md5");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1813 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1814
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1815 call.GetOutput().AnswerJson(operations);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1816 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1817 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1818
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1819
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1820 template <int uncompress>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1821 static void GetAttachmentData(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1822 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1823 if (call.IsDocumentation())
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1824 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1825 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1826 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1827 call.GetDocumentation()
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1828 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1829 .SetSummary("Get attachment" + std::string(uncompress ? "" : " (no decompression)"))
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1830 .SetDescription("Get the (binary) content of one attachment associated with the given " + r +
4418
9d6fa3da8f00 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
1831 std::string(uncompress ? "" : ". The attachment will not be decompressed if `StorageCompression` is `true`."))
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1832 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1833 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)")
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1834 .AddAnswerType(MimeType_Binary, "The attachment")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1835 .SetAnswerHeader("ETag", "Revision of the attachment, to be used in further `PUT` or `DELETE` operations")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1836 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed");
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1837 return;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1838 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1839
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1842 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1843
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1844 std::string publicId = call.GetUriComponent("id", "");
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1845 FileContentType type = StringToContentType(call.GetUriComponent("name", ""));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1846
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1847 FileInfo info;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1848 if (GetAttachmentInfo(info, call))
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1849 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1850 // NB: "SetAttachmentETag()" is already invoked by "GetAttachmentInfo()"
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1851
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1852 if (uncompress)
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1853 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1854 context.AnswerAttachment(call.GetOutput(), publicId, type);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1855 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1856 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1857 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1858 // Return the raw data (possibly compressed), as stored on the filesystem
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1859 std::string content;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1860 int64_t revision;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1861 context.ReadAttachment(content, revision, publicId, type, false);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1862
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1863 int64_t userRevision;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1864 std::string userMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1865 if (GetRevisionHeader(userRevision, userMD5, call, "If-None-Match") &&
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1866 revision == userRevision &&
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1867 info.GetUncompressedMD5() == userMD5)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1868 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1869 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1870 }
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1871 else
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1872 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1873 call.GetOutput().AnswerBuffer(content, MimeType_Binary);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
1874 }
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1875 }
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
1876 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1877 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1878
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1879
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1880 static void GetAttachmentSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1881 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1882 if (call.IsDocumentation())
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1883 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1884 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1885 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1886 AddAttachmentDocumentation(call, r);
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1887 call.GetDocumentation()
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1888 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1889 .SetSummary("Get size of attachment")
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1890 .SetDescription("Get the size of one attachment associated with the given " + r)
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1891 .AddAnswerType(MimeType_PlainText, "The size of the attachment");
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1892 return;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1893 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1894
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1895 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1896 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1897 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1898 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
1899 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1900 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1901
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1902
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1903 static void GetAttachmentCompressedSize(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1904 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1905 if (call.IsDocumentation())
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1906 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1907 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1908 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1909 AddAttachmentDocumentation(call, r);
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1910 call.GetDocumentation()
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1911 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1912 .SetSummary("Get size of attachment on disk")
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1913 .SetDescription("Get the size of one attachment associated with the given " + r + ", as stored on the disk. "
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
1914 "This is different from `.../size` iff `EnableStorage` is `true`.")
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1915 .AddAnswerType(MimeType_PlainText, "The size of the attachment, as stored on the disk");
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1916 return;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1917 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
1918
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1919 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1920 if (GetAttachmentInfo(info, call))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1921 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1922 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
1923 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1924 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1925
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1926
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1927 static void GetAttachmentMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1928 {
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1929 if (call.IsDocumentation())
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1930 {
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1931 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1932 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1933 AddAttachmentDocumentation(call, r);
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1934 call.GetDocumentation()
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1935 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1936 .SetSummary("Get MD5 of attachment")
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1937 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r)
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1938 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment");
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1939 return;
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1940 }
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1941
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1942 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1943 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1944 info.GetUncompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1945 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1946 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
1947 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1948 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1949
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1950
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1951 static void GetAttachmentCompressedMD5(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1952 {
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1953 if (call.IsDocumentation())
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1954 {
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1955 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1956 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1957 AddAttachmentDocumentation(call, r);
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1958 call.GetDocumentation()
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1959 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1960 .SetSummary("Get MD5 of attachment on disk")
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1961 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r + ", as stored on the disk. "
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
1962 "This is different from `.../md5` iff `EnableStorage` is `true`.")
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1963 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment, as stored on the disk");
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1964 return;
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1965 }
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1966
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1967 FileInfo info;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1968 if (GetAttachmentInfo(info, call) &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1969 info.GetCompressedMD5() != "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1970 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
1971 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
1972 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1973 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1974
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1975
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
1976 static void VerifyAttachment(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1977 {
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1978 if (call.IsDocumentation())
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1979 {
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1980 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1981 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1982 call.GetDocumentation()
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1983 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1984 .SetSummary("Verify attachment")
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1985 .SetDescription("Verify that the attachment is not corrupted, by validating its MD5 hash")
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1986 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
1987 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)")
4410
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1988 .AddAnswerType(MimeType_Json, "On success, a valid JSON object is returned");
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1989 return;
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1990 }
a6abe5f512db cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
1991
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1992 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1993 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1994
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1995 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1996 std::string name = call.GetUriComponent("name", "");
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1997 FileContentType contentType = StringToContentType(name);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1998
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1999 FileInfo info;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2000 int64_t revision; // Ignored
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2001 if (!OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType) ||
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2002 info.GetCompressedMD5() == "" ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2003 info.GetUncompressedMD5() == "")
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2004 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2005 // Inexistent resource, or no MD5 available
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2006 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2007 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2008
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2009 bool ok = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2010
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2011 // 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
2012 std::string data;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2013 context.ReadAttachment(data, revision, publicId, StringToContentType(name), false);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2014
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2015 std::string actualMD5;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2016 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2017
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2018 if (actualMD5 == info.GetCompressedMD5())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2019 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2020 // The compressed data is OK. If a compression algorithm was
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2021 // applied to it, now check the MD5 of the uncompressed data.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2022 if (info.GetCompressionType() == CompressionType_None)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2023 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2024 ok = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2025 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2026 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2027 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2028 context.ReadAttachment(data, revision, publicId, StringToContentType(name), true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2029 Toolbox::ComputeMD5(actualMD5, data);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2030 ok = (actualMD5 == info.GetUncompressedMD5());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2031 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2032 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2033
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2034 if (ok)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2035 {
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4272
diff changeset
2036 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
2037 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2038 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2039 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2040 {
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4272
diff changeset
2041 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
2042 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2043 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2044
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2045
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
2046 static void UploadAttachment(RestApiPutCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2047 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2048 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2049 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2050 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2051 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2052 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2053 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2054 .SetSummary("Set attachment")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2055 .SetDescription("Attach a file to the given DICOM " + r +
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2056 ". This call will fail if trying to modify a system attachment (i.e. whose index is < 1024).")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2057 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2058 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2059 .AddRequestType(MimeType_Binary, "Binary data containing the attachment")
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2060 .AddAnswerType(MimeType_Json, "Empty JSON object in the case of a success")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2061 .SetHttpHeader("If-Match", "Revision of the attachment, if this is not the first time this attachment is set.");
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2062 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2063 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2064
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2065 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2066 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2067
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2068 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2069 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2070
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2071 FileContentType contentType = StringToContentType(name);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2072 if (IsUserContentType(contentType)) // It is forbidden to modify internal attachments
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2073 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2074 int64_t oldRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2075 std::string oldMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2076 bool hasOldRevision = GetRevisionHeader(oldRevision, oldMD5, call, "if-match");
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2077
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2078 if (!hasOldRevision)
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2079 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2080 OrthancConfiguration::ReaderLock lock;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2081 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2082 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2083 // "StatelessDatabaseOperations::AddAttachment()" will ignore
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2084 // the actual value of "oldRevision" if the metadata is
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2085 // inexistent as expected
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2086 hasOldRevision = true;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2087 oldRevision = -1; // dummy value
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2088 oldMD5.clear(); // dummy value
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2089 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2090 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2091
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2092 int64_t newRevision;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2093 context.AddAttachment(newRevision, publicId, StringToContentType(name), call.GetBodyData(),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2094 call.GetBodySize(), hasOldRevision, oldRevision, oldMD5);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2095
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2096 SetBufferContentETag(call.GetOutput(), newRevision, call.GetBodyData(), call.GetBodySize()); // New in Orthanc 1.9.2
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2097 call.GetOutput().AnswerBuffer("{}", MimeType_Json);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2098 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2099 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2100 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2101 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
2102 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2103 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2104
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2105
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
2106 static void DeleteAttachment(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2107 {
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2108 if (call.IsDocumentation())
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2109 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2110 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2111 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2112 call.GetDocumentation()
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2113 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2114 .SetSummary("Delete attachment")
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2115 .SetDescription("Delete an attachment associated with the given DICOM " + r +
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2116 ". This call will fail if trying to delete a system attachment (i.e. whose index is < 1024).")
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2117 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2118 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)")
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2119 .SetHttpHeader("If-Match", "Revision of the attachment, to check if its content has not changed and can "
4661
b1d87d41874e typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4657
diff changeset
2120 "be deleted. This header is mandatory if `CheckRevisions` option is `true`.");
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2121 return;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2122 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2123
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2124 CheckValidResourceType(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2125
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2126 std::string publicId = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2127 std::string name = call.GetUriComponent("name", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2128 FileContentType contentType = StringToContentType(name);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2129
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2130 bool allowed;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2131 if (IsUserContentType(contentType))
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2132 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2133 allowed = true;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2134 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2135 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2136 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2137 OrthancConfiguration::ReaderLock lock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2138
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2139 if (lock.GetConfiguration().GetBooleanParameter("StoreDicom", true) &&
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2140 contentType == FileContentType_DicomAsJson)
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2141 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2142 allowed = true;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2143 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2144 else
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2145 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2146 // 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
2147 // 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
2148 // 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
2149 allowed = false;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2935
diff changeset
2150 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2151 }
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2152
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2153 if (allowed)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2154 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2155 bool found;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2156 int64_t revision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2157 std::string md5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2158 if (GetRevisionHeader(revision, md5, call, "if-match"))
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2159 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2160 found = OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType, true, revision, md5);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2161 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2162 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2163 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2164 OrthancConfiguration::ReaderLock lock;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2165 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2166 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2167 throw OrthancException(ErrorCode_Revision,
4661
b1d87d41874e typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4657
diff changeset
2168 "HTTP header \"If-Match\" is missing, as \"CheckRevisions\" is \"true\"");
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2169 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2170 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2171 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2172 found = OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
2173 false, -1 /* dummy value */, "" /* dummy value */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2174 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2175 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2176
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2177 if (found)
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2178 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2179 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2180 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2181 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2182 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2183 throw OrthancException(ErrorCode_UnknownResource);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2184 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2185 }
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2186 else
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2187 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
2188 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
2189 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2190 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2191
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2192
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2193 template <enum CompressionType compression>
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2194 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
2195 {
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2196 if (call.IsDocumentation())
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2197 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2198 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2199 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2200 call.GetDocumentation()
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2201 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2202 .SetSummary(compression == CompressionType_None ? "Uncompress attachment" : "Compress attachment")
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2203 .SetDescription("Change the compression scheme that is used to store an attachment.")
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2204 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
2205 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)");
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2206 return;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2207 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2208
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2209 CheckValidResourceType(call);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2210
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2211 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
2212 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
2213 FileContentType contentType = StringToContentType(name);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2214
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2215 OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression);
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2216 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
2217 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2218
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2219
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2220 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
2221 {
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2222 if (call.IsDocumentation())
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2223 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2224 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2225 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2226 AddAttachmentDocumentation(call, r);
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2227 call.GetDocumentation()
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2228 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2229 .SetSummary("Is attachment compressed?")
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2230 .SetDescription("Test whether the attachment has been stored as a compressed file on the disk.")
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2231 .AddAnswerType(MimeType_PlainText, "`0` if the attachment was stored uncompressed, `1` if it was compressed");
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2232 return;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2233 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
2234
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2235 FileInfo info;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2236 if (GetAttachmentInfo(info, call))
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2237 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2238 std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1";
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2239 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
2240 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2241 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2242
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1556
diff changeset
2243
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2244 // Raw access to the DICOM tags of an instance ------------------------------
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2245
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
2246 static void GetRawContent(RestApiGetCall& call)
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2247 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2248 if (call.IsDocumentation())
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2249 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2250 call.GetDocumentation()
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2251 .SetTag("Instances")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2252 .SetSummary("Get raw tag")
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2253 .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
2254 .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
2255 .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
2256 "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
2257 .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
2258 "(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
2259 "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
2260 return;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2261 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
2262
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2263 std::string id = call.GetUriComponent("id", "");
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2264
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2265 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2266
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2267 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2268 }
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
2269
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2270
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2271
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2272 static bool ExtractSharedTags(Json::Value& shared,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2273 ServerContext& context,
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2274 const std::string& publicId)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2275 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2276 // 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
2277 typedef std::list<std::string> Instances;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2278 Instances instances;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2279 context.GetIndex().GetChildInstances(instances, publicId); // (*)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2280
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2281 // Loop over the instances
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2282 bool isFirst = true;
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2283 shared = Json::objectValue;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2284
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2285 for (Instances::const_iterator it = instances.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2286 it != instances.end(); ++it)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2287 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2288 // 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
2289 Json::Value tags;
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2290
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2291 try
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2292 {
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
2293 context.ReadDicomAsJson(tags, *it);
959
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2294 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2295 catch (OrthancException&)
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2296 {
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2297 // Race condition: This instance has been removed since
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2298 // (*). Ignore this instance.
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2299 continue;
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2300 }
bd5659f2a50a fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 958
diff changeset
2301
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2302 if (tags.type() != Json::objectValue)
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2303 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2304 return false; // Error
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2305 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2306
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2307 // 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
2308 Json::Value::Members members = tags.getMemberNames();
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2309 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
2310 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2311 const Json::Value& tag = tags[members[i]];
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2312 if (tag.type() != Json::objectValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2313 tag["Type"].type() != Json::stringValue ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2314 tag["Type"].asString() != "String")
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2315 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2316 tags.removeMember(members[i]);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2317 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2318 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2319
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2320 if (isFirst)
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2321 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2322 // 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
2323 shared = tags;
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2324 isFirst = false;
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2325 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2326 else
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2327 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2328 // 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
2329 // 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
2330 // value in the current instance, remove it.
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2331 members = shared.getMemberNames();
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2332 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
2333 {
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2334 if (!tags.isMember(members[i]) ||
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2335 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
2336 {
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2337 shared.removeMember(members[i]);
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2338 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2339 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2340 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2341 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2342
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2343 return true;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2344 }
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2345
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2346
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 964
diff changeset
2347 static void GetSharedTags(RestApiGetCall& call)
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2348 {
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2349 if (call.IsDocumentation())
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2350 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2351 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2352
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2353 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2354 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2355 call.GetDocumentation()
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2356 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2357 .SetSummary("Get shared tags")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2358 .SetDescription("Extract the DICOM tags whose value is constant across all the child instances of "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2359 "the DICOM " + r + " whose Orthanc identifier is provided in the URL")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2360 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2361 .AddAnswerType(MimeType_Json, "JSON object containing the values of the DICOM tags")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2362 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/shared-tags", 5);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2363 return;
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2364 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2365
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2366 ServerContext& context = OrthancRestApi::GetContext(call);
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2367 std::string publicId = call.GetUriComponent("id", "");
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2368
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2369 Json::Value sharedTags;
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2370 if (ExtractSharedTags(sharedTags, context, publicId))
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2371 {
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2372 // Success: Send the value of the shared tags
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2373 AnswerDicomAsJson(call, sharedTags, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full));
960
abac5c83134f simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 959
diff changeset
2374 }
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2375 }
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2376
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
2377
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2378 template <enum ResourceType resourceType,
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2379 enum DicomModule module>
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2380 static void GetModule(RestApiGetCall& call)
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2381 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2382 if (call.IsDocumentation())
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2383 {
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2384 const std::string resource = GetResourceTypeText(resourceType, false /* plural */, false /* lower case */);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2385 std::string m;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2386 switch (module)
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2387 {
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2388 case DicomModule_Patient:
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2389 m = "patient";
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2390 break;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2391 case DicomModule_Study:
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2392 m = "study";
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2393 break;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2394 case DicomModule_Series:
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2395 m = "series";
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2396 break;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2397 case DicomModule_Instance:
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2398 m = "instance";
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2399 break;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2400 default:
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2401 throw OrthancException(ErrorCode_ParameterOutOfRange);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2402 }
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2403
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2404 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2405
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2406 call.GetDocumentation()
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2407 .SetTag(GetResourceTypeText(resourceType, true /* plural */, true /* upper case */))
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2408 .SetSummary("Get " + m + " module" + std::string(resource == m ? "" : " of " + resource))
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2409 .SetDescription("Get the " + m + " module of the DICOM " + resource + " whose Orthanc identifier is provided in the URL")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2410 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2411 .SetHttpGetArgument("ignore-length", RestApiCallDocumentation::Type_JsonListOfStrings,
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2412 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false)
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2413 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource)
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2414 .SetHttpGetSample(GetDocumentationSampleResource(resourceType) + "/" + (*call.GetFullUri().rbegin()), true);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2415 return;
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2416 }
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2417
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2418 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2419 (resourceType == ResourceType_Study && module == DicomModule_Patient) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2420 (resourceType == ResourceType_Study && module == DicomModule_Study) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2421 (resourceType == ResourceType_Series && module == DicomModule_Series) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2422 (resourceType == ResourceType_Instance && module == DicomModule_Instance) ||
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2423 (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
2424 {
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
2425 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
2426 }
1701dcb6f554 Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
2427
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2428 ServerContext& context = OrthancRestApi::GetContext(call);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2429 std::string publicId = call.GetUriComponent("id", "");
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2430
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2431 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2432 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2433
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2434 typedef std::set<DicomTag> ModuleTags;
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2435 ModuleTags moduleTags;
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2436 DicomTag::AddTagsForModule(moduleTags, module);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2437
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2438 Json::Value tags;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2439
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2440 if (resourceType != ResourceType_Instance)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2441 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2442 // Retrieve all the instances of this patient/study/series
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2443 typedef std::list<std::string> Instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2444 Instances instances;
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2445 context.GetIndex().GetChildInstances(instances, publicId);
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2446
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2447 if (instances.empty())
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2448 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2449 return; // Error: No instance (should never happen)
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2450 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2451
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2452 // Select one child instance
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2453 publicId = instances.front();
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2454 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2455
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2456 context.ReadDicomAsJson(tags, publicId, ignoreTagLength);
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2457
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2458 // 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
2459 Json::Value result = Json::objectValue;
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2460 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
2461 {
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
2462 std::string s = tag->Format();
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2463 if (tags.isMember(s))
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2464 {
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2465 result[s] = tags[s];
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2466 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2467 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2468
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2469 AnswerDicomAsJson(call, result, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full));
963
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2470 }
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2471
81134ea872ff retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 960
diff changeset
2472
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2473 namespace
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2474 {
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2475 typedef std::list< std::pair<ResourceType, std::string> > LookupResults;
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2476 }
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2477
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2478
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2479 static void AccumulateLookupResults(LookupResults& result,
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2480 ServerIndex& index,
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2481 const DicomTag& tag,
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
2482 const std::string& value,
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
2483 ResourceType level)
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2484 {
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
2485 std::vector<std::string> tmp;
1728
4941494b5dd8 rename LookupIdentifier as LookupIdentifierExact
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1727
diff changeset
2486 index.LookupIdentifierExact(tmp, level, tag, value);
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
2487
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
2488 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
2489 {
3034
54e422fe31ce moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
2490 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
2491 }
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2492 }
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2493
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2494
1139
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2495 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
2496 {
4422
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2497 if (call.IsDocumentation())
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2498 {
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2499 call.GetDocumentation()
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2500 .SetTag("System")
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2501 .SetSummary("Look for DICOM identifiers")
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2502 .SetDescription("This URI can be used to convert one DICOM identifier to a list of matching Orthanc resources")
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2503 .AddRequestType(MimeType_PlainText, "The DICOM identifier of interest (i.e. the value of `PatientID`, "
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2504 "`StudyInstanceUID`, `SeriesInstanceUID`, or `SOPInstanceUID`)")
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2505 .AddAnswerType(MimeType_Json, "JSON array containing a list of matching Orthanc resources, each item in the "
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2506 "list corresponding to a JSON object with the fields `Type`, `ID` and `Path` identifying one "
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2507 "DICOM resource that is stored by Orthanc");
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2508 return;
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2509 }
48303e493135 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
2510
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
2511 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
2512 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
2513
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2514 LookupResults resources;
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2515 ServerIndex& index = OrthancRestApi::GetIndex(call);
1719
3b1f7e706d38 fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1718
diff changeset
2516 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
2517 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
2518 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
2519 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
2520
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2521 Json::Value result = Json::arrayValue;
1722
f1901004f3e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1719
diff changeset
2522 for (LookupResults::const_iterator
1718
2b812969e136 getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1703
diff changeset
2523 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
2524 {
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2525 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
2526 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
2527
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2528 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
2529 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
2530 item["ID"] = id;
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2531 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
2532
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2533 result.append(item);
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2534 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2535
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2536 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
2537 }
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2538
f167b672db94 /tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1054
diff changeset
2539
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2540 namespace
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2541 {
3021
2cbafb5d5a62 renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
2542 class FindVisitor : public ServerContext::ILookupVisitor
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2543 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2544 private:
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2545 bool isComplete_;
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2546 std::list<std::string> resources_;
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2547 DicomToJsonFormat format_;
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2548
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2549 public:
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2550 FindVisitor(DicomToJsonFormat format) :
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2551 isComplete_(false),
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2552 format_(format)
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2553 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2554 }
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
2555
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
2556 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
2557 {
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
2558 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
2559 }
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
2560
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
2561 virtual void MarkAsComplete() ORTHANC_OVERRIDE
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2562 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2563 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
2564 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2565
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2566 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
2567 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
2568 const DicomMap& mainDicomTags /* unused */,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
2569 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
2570 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2571 resources_.push_back(publicId);
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2572 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2573
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2574 void Answer(RestApiOutput& output,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2575 ServerIndex& index,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2576 ResourceType level,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2577 bool expand) const
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2578 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2579 AnswerListOfResources(output, index, resources_, level, expand, format_);
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2580 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2581 };
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2582 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2583
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2584
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2585 static void Find(RestApiPostCall& call)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2586 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2587 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2588 static const char* const KEY_EXPAND = "Expand";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2589 static const char* const KEY_LEVEL = "Level";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2590 static const char* const KEY_LIMIT = "Limit";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2591 static const char* const KEY_QUERY = "Query";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2592 static const char* const KEY_SINCE = "Since";
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2593
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2594 if (call.IsDocumentation())
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2595 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2596 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2597
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2598 call.GetDocumentation()
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2599 .SetTag("System")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2600 .SetSummary("Look for local resources")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2601 .SetDescription("This URI can be used to perform a search on the content of the local Orthanc server, "
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2602 "in a way that is similar to querying remote DICOM modalities using C-FIND SCU: "
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2603 "https://book.orthanc-server.com/users/rest.html#performing-finds-within-orthanc")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2604 .SetRequestField(KEY_CASE_SENSITIVE, RestApiCallDocumentation::Type_Boolean,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2605 "Enable case-sensitive search for PN value representations (defaults to configuration option `CaseSensitivePN`)", false)
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2606 .SetRequestField(KEY_EXPAND, RestApiCallDocumentation::Type_Boolean,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2607 "Also retrieve the content of the matching resources, not only their Orthanc identifiers", false)
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2608 .SetRequestField(KEY_LEVEL, RestApiCallDocumentation::Type_String,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2609 "Level of the query (`Patient`, `Study`, `Series` or `Instance`)", true)
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2610 .SetRequestField(KEY_LIMIT, RestApiCallDocumentation::Type_Number,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2611 "Limit the number of reported resources", false)
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2612 .SetRequestField(KEY_SINCE, RestApiCallDocumentation::Type_Number,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2613 "Show only the resources since the provided index (in conjunction with `Limit`)", false)
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2614 .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2615 "Associative array containing the filter on the values of the DICOM tags", true)
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2616 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information "
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2617 "about the reported resources (if `Expand` argument is `true`)");
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2618 return;
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2619 }
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2620
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1356
diff changeset
2621 ServerContext& context = OrthancRestApi::GetContext(call);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2622
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2623 Json::Value request;
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2624 if (!call.ParseJsonRequest(request) ||
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2625 request.type() != Json::objectValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2626 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2627 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2628 "The body must contain a JSON object");
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2629 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2630 else if (!request.isMember(KEY_LEVEL) ||
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2631 request[KEY_LEVEL].type() != Json::stringValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2632 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2633 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2634 "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
2635 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2636 else if (!request.isMember(KEY_QUERY) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2637 request[KEY_QUERY].type() != Json::objectValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2638 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2639 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2640 "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
2641 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2642 else if (request.isMember(KEY_CASE_SENSITIVE) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2643 request[KEY_CASE_SENSITIVE].type() != Json::booleanValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2644 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2645 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2646 "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
2647 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2648 else if (request.isMember(KEY_LIMIT) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2649 request[KEY_LIMIT].type() != Json::intValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2650 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2651 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2652 "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
2653 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2654 else if (request.isMember(KEY_SINCE) &&
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2655 request[KEY_SINCE].type() != Json::intValue)
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2656 {
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2657 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2658 "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
2659 }
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2660 else
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2661 {
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2662 bool expand = false;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2663 if (request.isMember(KEY_EXPAND))
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2664 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2665 expand = request[KEY_EXPAND].asBool();
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2666 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2667
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2668 bool caseSensitive = false;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2669 if (request.isMember(KEY_CASE_SENSITIVE))
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2670 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2671 caseSensitive = request[KEY_CASE_SENSITIVE].asBool();
1374
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2672 }
a1745d9be6e9 CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1361
diff changeset
2673
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2674 size_t limit = 0;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2675 if (request.isMember(KEY_LIMIT))
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2676 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2677 int tmp = request[KEY_LIMIT].asInt();
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
2678 if (tmp < 0)
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2679 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2680 throw OrthancException(ErrorCode_ParameterOutOfRange,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2681 "Field \"" + std::string(KEY_LIMIT) + "\" should be a positive integer");
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2682 }
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
2683
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
2684 limit = static_cast<size_t>(tmp);
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2685 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
2686
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2687 size_t since = 0;
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2688 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
2689 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2690 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
2691 if (tmp < 0)
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2692 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2693 throw OrthancException(ErrorCode_ParameterOutOfRange,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2694 "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
2695 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2696
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2697 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
2698 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
2699
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
2700 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString());
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1358
diff changeset
2701
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
2702 DatabaseLookup query;
1358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1356
diff changeset
2703
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2704 Json::Value::Members members = request[KEY_QUERY].getMemberNames();
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2705 for (size_t i = 0; i < members.size(); i++)
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2706 {
2998
0a52af0c66e7 sharing strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
2707 if (request[KEY_QUERY][members[i]].type() != Json::stringValue)
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2708 {
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2709 throw OrthancException(ErrorCode_BadRequest,
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2998
diff changeset
2710 "Tag \"" + members[i] + "\" should be associated with a string");
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2711 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2712
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
2713 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
2714
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
2715 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
2716 {
cf91b6f22278 Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3094
diff changeset
2717 // 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
2718 // 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
2719 // "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
2720 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
2721 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
2722 }
1361
94ffb597d297 refactoring of C-Find SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
2723 }
2876
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2836
diff changeset
2724
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2725 FindVisitor visitor(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human));
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
2726 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
2727 visitor.Answer(call.GetOutput(), context.GetIndex(), level, expand);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2728 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2729 }
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2730
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
2731
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
2732 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
2733 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
2734 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
2735 {
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2736 if (call.IsDocumentation())
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2737 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2738 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2739
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2740 const std::string children = GetResourceTypeText(end, true /* plural */, false /* lower case */);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2741 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2742 call.GetDocumentation()
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2743 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */))
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2744 .SetSummary("Get child " + children)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2745 .SetDescription("Get detailed information about the child " + children + " of the DICOM " +
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2746 resource + " whose Orthanc identifier is provided in the URL")
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2747 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2748 .AddAnswerType(MimeType_Json, "JSON array containing information about the child DICOM " + children)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2749 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + children, 5);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2750 return;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2751 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2752
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
2753 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
2754
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
2755 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
2756 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
2757
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
2758 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
2759 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
2760 {
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
2761 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
2762
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
2763 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2764 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
2765 {
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
2766 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
2767 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
2768 }
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
2769
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
2770 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
2771
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
2772 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
2773 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
2774 }
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
2775
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
2776 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
2777
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2778 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2779
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
2780 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2781 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
2782 {
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
2783 Json::Value resource;
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2784 if (OrthancRestApi::GetIndex(call).ExpandResource(resource, *it, end, format))
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
2785 {
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
2786 result.append(resource);
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
2787 }
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
2788 }
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
2789
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
2790 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
2791 }
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
2792
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
2793
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2794 static void GetChildInstancesTags(RestApiGetCall& call)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2795 {
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2796 if (call.IsDocumentation())
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2797 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2798 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2799
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2800 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2801 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2802 call.GetDocumentation()
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2803 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2804 .SetSummary("Get tags of instances")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2805 .SetDescription("Get the tags of all the child instances of the DICOM " + r +
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2806 " whose Orthanc identifier is provided in the URL")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2807 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2808 .SetHttpGetArgument("ignore-length", RestApiCallDocumentation::Type_JsonListOfStrings,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2809 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2810 .AddAnswerType(MimeType_Json, "JSON object associating the Orthanc identifiers of the instances, with the values of their DICOM tags")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2811 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/instances-tags", 5);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2812 return;
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2813 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2814
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2815 ServerContext& context = OrthancRestApi::GetContext(call);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2816 std::string publicId = call.GetUriComponent("id", "");
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2817 DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full);
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2818
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2819 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2820 ParseSetOfTags(ignoreTagLength, call, "ignore-length");
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2821
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2822 // Retrieve all the instances of this patient/study/series
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2823 typedef std::list<std::string> Instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2824 Instances instances;
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2825
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2826 context.GetIndex().GetChildInstances(instances, publicId); // (*)
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2827
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
2828 Json::Value result = Json::objectValue;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2829
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2830 for (Instances::const_iterator it = instances.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
2831 it != instances.end(); ++it)
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2832 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2833 Json::Value full;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2408
diff changeset
2834 context.ReadDicomAsJson(full, *it, ignoreTagLength);
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2835
2622
3603a2e14592 New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
2836 if (format != DicomToJsonFormat_Full)
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2837 {
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2838 Json::Value simplified;
4055
9214e3a7b0a2 moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
2839 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
2840 result[*it] = simplified;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2841 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2842 else
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2843 {
1201
09aa7c126be9 URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1172
diff changeset
2844 result[*it] = full;
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2845 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2846 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2847
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2848 call.GetOutput().AnswerJson(result);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2849 }
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2850
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
2851
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
2852
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
2853 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
2854 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
2855 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
2856 {
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
2857 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
2858
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2859 if (call.IsDocumentation())
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2860 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2861 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2862
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2863 const std::string parent = GetResourceTypeText(end, false /* plural */, false /* lower case */);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2864 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2865 call.GetDocumentation()
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2866 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */))
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2867 .SetSummary("Get parent " + parent)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2868 .SetDescription("Get detailed information about the parent " + parent + " of the DICOM " +
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
2869 resource + " whose Orthanc identifier is provided in the URL")
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2870 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2871 .AddAnswerType(MimeType_Json, "Information about the parent DICOM " + parent)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2872 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + parent, 10);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2873 return;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2874 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
2875
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
2876 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
2877
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
2878 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
2879 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
2880 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
2881 {
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
2882 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
2883 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
2884 {
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
2885 // 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
2886 // 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
2887 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
2888 }
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
2889
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
2890 current = parent;
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
2891 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
2892 }
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
2893
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
2894 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
2895
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2896 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2897
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
2898 Json::Value resource;
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2899 if (OrthancRestApi::GetIndex(call).ExpandResource(resource, current, end, format))
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
2900 {
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
2901 call.GetOutput().AnswerJson(resource);
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
2902 }
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
2903 }
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
2904
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
2905
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2906 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
2907 {
4407
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2908 if (call.IsDocumentation())
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2909 {
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2910 call.GetDocumentation()
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2911 .SetTag("Instances")
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2912 .SetSummary("Get embedded PDF")
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2913 .SetDescription("Get the PDF file that is embedded in one DICOM instance. "
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2914 "If the DICOM instance doesn't contain the `EncapsulatedDocument` tag or if the "
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2915 "`MIMETypeOfEncapsulatedDocument` tag doesn't correspond to the PDF type, a `404` HTTP error is raised.")
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2916 .SetUriArgument("id", "Orthanc identifier of the instance interest")
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2917 .AddAnswerType(MimeType_Pdf, "PDF file");
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2918 return;
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2919 }
2412601cd24b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4406
diff changeset
2920
1556
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2921 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
2922 std::string pdf;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2923 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
2924
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2925 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
2926 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
2927 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
2928 return;
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2929 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2930 }
b8dc2f855a83 Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
2931
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
2932
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2933 static void OrderSlices(RestApiGetCall& call)
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2934 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2935 if (call.IsDocumentation())
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2936 {
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2937 call.GetDocumentation()
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2938 .SetDeprecated()
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2939 .SetTag("Series")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2940 .SetSummary("Order the slices")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2941 .SetDescription("Sort the instances and frames (slices) of the DICOM series whose Orthanc identifier is provided in the URL. "
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2942 "This URI is essentially used by the Orthanc Web viewer and by the Osimis Web viewer.")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2943 .SetUriArgument("id", "Orthanc identifier of the series of interest")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2944 .SetAnswerField("Dicom", RestApiCallDocumentation::Type_JsonListOfStrings,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2945 "Ordered list of paths to DICOM instances")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2946 .SetAnswerField("Slices", RestApiCallDocumentation::Type_JsonListOfStrings,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2947 "Ordered list of paths to frames. It is recommended to use this field, as it is also valid "
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2948 "in the case of multiframe images.")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2949 .SetAnswerField("SlicesShort", RestApiCallDocumentation::Type_JsonListOfObjects,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2950 "Same information as the `Slices` field, but in a compact form")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2951 .SetAnswerField("Type", RestApiCallDocumentation::Type_String,
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2952 "Can be `Volume` (for 3D volumes) or `Sequence` (notably for cine images)")
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2953 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/series/1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0/ordered-slices", 10);
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2954 return;
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2955 }
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4420
diff changeset
2956
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2957 const std::string id = call.GetUriComponent("id", "");
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2958
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2959 ServerIndex& index = OrthancRestApi::GetIndex(call);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2960 SliceOrdering ordering(index, id);
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2961
1703
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
2962 Json::Value result;
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
2963 ordering.Format(result);
b80e76dd1d56 ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1702
diff changeset
2964 call.GetOutput().AnswerJson(result);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2965 }
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2966
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
2967
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2968 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
2969 {
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2970 if (call.IsDocumentation())
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2971 {
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2972 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full);
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2973 call.GetDocumentation()
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2974 .SetTag("Instances")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2975 .SetSummary("Get DICOM meta-header")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2976 .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
2977 "combines hexadecimal tags with human-readable description.")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2978 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2979 .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
2980 .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
2981 return;
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2982 }
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
2983
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2984 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
2985
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2986 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
2987
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2988 std::string dicomContent;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
2989 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
2990
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
2991 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
2992 // speed up things here
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2003
diff changeset
2993
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2994 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
2995
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
2996 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
2997 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
2998
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
2999 AnswerDicomAsJson(call, header, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full));
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
3000 }
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
3001
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
3002
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
3003 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
3004 {
4420
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3005 if (call.IsDocumentation())
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3006 {
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3007 call.GetDocumentation()
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3008 .SetTag("System")
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3009 .SetSummary("Invalidate DICOM-as-JSON summaries")
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3010 .SetDescription("Remove all the attachments of the type \"DICOM-as-JSON\" that are associated will all the "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3011 "DICOM instances stored in Orthanc. These summaries will be automatically re-created on the next access. "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3012 "This is notably useful after changes to the `Dictionary` configuration option. "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3013 "https://book.orthanc-server.com/faq/orthanc-storage.html#storage-area");
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3014 return;
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3015 }
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3016
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
3017 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
3018
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3019 // 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
3020 // 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
3021 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
3022 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
3023
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3024 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
3025 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
3026 {
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3027 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
3028 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
3029
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3030 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
3031 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
3032 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
3033 index.DeleteAttachment(*instance, FileContentType_DicomAsJson,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
3034 false /* no revision checks */, -1 /* dummy */, "" /* dummy */);
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
3035 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3036 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3037
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
3038 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
3039 }
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3040
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
3041
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
3042 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
3043 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
3044 {
4420
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3045 if (call.IsDocumentation())
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3046 {
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3047 const std::string resource = GetResourceTypeText(type, false /* plural */, false /* lower case */);
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3048 call.GetDocumentation()
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3049 .SetTag(GetResourceTypeText(type, true /* plural */, true /* upper case */))
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3050 .SetSummary("Reconstruct tags of " + resource)
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3051 .SetDescription("Reconstruct the main DICOM tags of the " + resource + " whose Orthanc identifier is provided "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3052 "in the URL. This is useful if child studies/series/instances have inconsistent values for "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3053 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3054 "Beware that this is a time-consuming operation, as all the children DICOM instances will be "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3055 "parsed again, and the Orthanc index will be updated accordingly.")
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3056 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest");
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3057 return;
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3058 }
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3059
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
3060 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
3061 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""));
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
3062 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
3063 }
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
3064
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
3065
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3066 static void ReconstructAllResources(RestApiPostCall& call)
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3067 {
4420
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3068 if (call.IsDocumentation())
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3069 {
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3070 call.GetDocumentation()
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3071 .SetTag("System")
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3072 .SetSummary("Reconstruct all the index")
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3073 .SetDescription("Reconstruct the index of all the tags of all the DICOM instances that are stored in Orthanc. "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3074 "This is notably useful after the deletion of resources whose children resources have inconsistent "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3075 "values with their sibling resources. Beware that this is a highly time-consuming operation, "
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3076 "as all the DICOM instances will be parsed again, and as all the Orthanc index will be regenerated.");
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3077 return;
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3078 }
f95ad769e671 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4419
diff changeset
3079
2804
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3080 ServerContext& context = OrthancRestApi::GetContext(call);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3081
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3082 std::list<std::string> studies;
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3083 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
3084
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3085 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
3086 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
3087 {
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3088 ServerToolbox::ReconstructResource(context, *study);
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3089 }
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3090
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
3091 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
3092 }
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3093
d88970f1ffbf fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2780
diff changeset
3094
4698
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3095 static void BulkContent(RestApiPostCall& call)
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3096 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3097 if (call.IsDocumentation())
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3098 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3099 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3100
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3101 call.GetDocumentation()
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3102 .SetTag("System")
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3103 .SetSummary("Describe a set of instances")
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3104 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings,
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3105 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", false)
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3106 .SetDescription("Get the content all the DICOM patients, studies, series or instances "
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3107 "whose identifiers are provided in the `Resources` field, in one single call.");
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3108 return;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3109 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3110
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3111 Json::Value request;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3112 if (!call.ParseJsonRequest(request) ||
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3113 request.type() != Json::objectValue)
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3114 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3115 throw OrthancException(ErrorCode_BadRequest,
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3116 "The body must contain a JSON object");
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3117 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3118 else
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3119 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3120 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human);
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3121
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3122 ServerIndex& index = OrthancRestApi::GetIndex(call);
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3123
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3124 std::list<std::string> resources;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3125 SerializationToolbox::ReadListOfStrings(resources, request, "Resources");
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3126
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3127 Json::Value answer = Json::arrayValue;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3128 for (std::list<std::string>::const_iterator
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3129 it = resources.begin(); it != resources.end(); ++it)
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3130 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3131 ResourceType type;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3132 Json::Value item;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3133 if (index.LookupResourceType(type, *it) &&
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3134 index.ExpandResource(item, *it, type, format))
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3135 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3136 answer.append(item);
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3137 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3138 else
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3139 {
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3140 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it;
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3141 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3142 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3143
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3144 call.GetOutput().AnswerJson(answer);
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3145 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3146 }
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3147
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3148
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3149 static void BulkDelete(RestApiPostCall& call)
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3150 {
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3151 if (call.IsDocumentation())
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3152 {
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3153 call.GetDocumentation()
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3154 .SetTag("System")
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3155 .SetSummary("Delete a set of instances")
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3156 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings,
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3157 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", false)
4698
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3158 .SetDescription("Delete all the DICOM patients, studies, series or instances "
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3159 "whose identifiers are provided in the `Resources` field.");
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3160 return;
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3161 }
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3162
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3163 ServerContext& context = OrthancRestApi::GetContext(call);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3164
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3165 Json::Value request;
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3166 if (!call.ParseJsonRequest(request) ||
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3167 request.type() != Json::objectValue)
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3168 {
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3169 throw OrthancException(ErrorCode_BadRequest,
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3170 "The body must contain a JSON object");
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3171 }
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3172 else
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3173 {
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3174 std::set<std::string> resources;
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3175 SerializationToolbox::ReadSetOfStrings(resources, request, "Resources");
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3176
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3177 for (std::set<std::string>::const_iterator
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3178 it = resources.begin(); it != resources.end(); ++it)
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3179 {
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3180 ResourceType type;
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3181 Json::Value remainingAncestor; // Unused
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3182
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3183 if (!context.GetIndex().LookupResourceType(type, *it) ||
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3184 !context.DeleteResource(remainingAncestor, *it, type))
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3185 {
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3186 CLOG(INFO, HTTP) << "Unknown resource during a bulk deletion: " << *it;
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3187 }
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3188 }
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3189
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3190 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3191 }
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3192 }
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3193
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3194
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3195 void OrthancRestApi::RegisterResources()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3196 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3197 Register("/instances", ListResources<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3198 Register("/patients", ListResources<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3199 Register("/series", ListResources<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3200 Register("/studies", ListResources<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3201
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3202 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3203 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3204 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3205 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3206 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3207 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3208 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3209 Register("/studies/{id}", GetSingleResource<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3210
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3211 Register("/instances/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3212 Register("/patients/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3213 Register("/studies/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3214 Register("/series/{id}/statistics", GetResourceStatistics);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3215
964
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
3216 Register("/patients/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
3217 Register("/series/{id}/shared-tags", GetSharedTags);
cc7a4ae474c1 simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 963
diff changeset
3218 Register("/studies/{id}/shared-tags", GetSharedTags);
958
1fbe89dc18b5 extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 874
diff changeset
3219
1276
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
3220 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
3221 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
3222 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
3223 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>);
6164f7200c43 refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1201
diff changeset
3224 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
3225
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3226 Register("/instances/{id}/file", GetInstanceFile);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3227 Register("/instances/{id}/export", ExportInstanceFile);
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
3228 Register("/instances/{id}/tags", GetInstanceTags);
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
3229 Register("/instances/{id}/simplified-tags", GetInstanceSimplifiedTags);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3230 Register("/instances/{id}/frames", ListFrames);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3231
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4422
diff changeset
3232 Register("/instances/{id}/frames/{frame}", RestApi::AutoListChildren);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3233 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
3234 Register("/instances/{id}/frames/{frame}/rendered", GetRenderedFrame);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3235 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3236 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3237 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
3238 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
3239 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
3240 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
3241 Register("/instances/{id}/pdf", ExtractPdf);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3242 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
3243 Register("/instances/{id}/rendered", GetRenderedFrame);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3244 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3245 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3246 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>);
874
87791ebc1f50 download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
3247 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
3248 Register("/instances/{id}/header", GetInstanceHeader);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3249
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3250 Register("/patients/{id}/protected", IsProtectedPatient);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3251 Register("/patients/{id}/protected", SetPatientProtection);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3252
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3253 std::vector<std::string> resourceTypes;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3254 resourceTypes.push_back("patients");
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3255 resourceTypes.push_back("studies");
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3256 resourceTypes.push_back("series");
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3257 resourceTypes.push_back("instances");
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3258
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3259 for (size_t i = 0; i < resourceTypes.size(); i++)
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3260 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3261 Register("/" + resourceTypes[i] + "/{id}/metadata", ListMetadata);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3262 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", DeleteMetadata);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3263 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", GetMetadata);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3264 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", SetMetadata);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3265
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3266 Register("/" + resourceTypes[i] + "/{id}/attachments", ListAttachments);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3267 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", DeleteAttachment);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3268 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", GetAttachmentOperations);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3269 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", UploadAttachment);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3270 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3271 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3272 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3273 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3274 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/data", GetAttachmentData<1>);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3275 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3276 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3277 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3278 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3279 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment);
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4408
diff changeset
3280 }
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
3281
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
3282 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
3283 Register("/tools/lookup", Lookup);
1354
3dd494f201a1 ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1342
diff changeset
3284 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
3285
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
3286 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
3287 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
3288 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
3289 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
3290 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
3291 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
3292
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
3293 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
3294 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
3295 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
3296 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
3297 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
3298 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
3299
1166
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
3300 Register("/patients/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
3301 Register("/studies/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
3302 Register("/series/{id}/instances-tags", GetChildInstancesTags);
a921e3b5e763 bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
3303
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
3304 Register("/instances/{id}/content/*", GetRawContent);
1702
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
3305
9980875edc7c started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
3306 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
3307
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
3308 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
3309 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
3310 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
3311 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
3312 Register("/tools/reconstruct", ReconstructAllResources);
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3313
4698
d16c3c7f11ef new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4697
diff changeset
3314 Register("/tools/bulk-content", BulkContent);
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4661
diff changeset
3315 Register("/tools/bulk-delete", BulkDelete);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3316 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3317 }