Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5843:7df3d533c294 find-refactoring-clean
integration find-refactoring->find-refactoring-clean
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Oct 2024 13:11:40 +0000 |
parents | 58c549b881ae 57ab63fe9108 |
children | 1980354c8113 |
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 | 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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5558
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5558
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5467
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * 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
|
11 * published by the Free Software Foundation, either version 3 of the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * License, or (at your option) any later version. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * 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
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * 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
|
20 * 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
|
21 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
24 #include "../PrecompiledHeadersServer.h" |
5608 | 25 #include "../ResourceFinder.h" |
26 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
4045 | 29 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h" |
30 #include "../../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h" | |
31 #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h" | |
32 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
33 #include "../../../OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.h" | |
34 #include "../../../OrthancFramework/Sources/HttpServer/HttpContentNegociation.h" | |
35 #include "../../../OrthancFramework/Sources/Images/Image.h" | |
36 #include "../../../OrthancFramework/Sources/Images/ImageProcessing.h" | |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
37 #include "../../../OrthancFramework/Sources/Images/NumpyWriter.h" |
4045 | 38 #include "../../../OrthancFramework/Sources/Logging.h" |
39 #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
|
40 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" |
4045 | 41 |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
42 #include "../OrthancConfiguration.h" |
3094
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3085
diff
changeset
|
43 #include "../Search/DatabaseLookup.h" |
5828 | 44 #include "../Search/DatabaseMetadataConstraint.h" |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1385
diff
changeset
|
45 #include "../ServerContext.h" |
2131 | 46 #include "../ServerToolbox.h" |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
47 #include "../SliceOrdering.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
3687 | 49 // This "include" is mandatory for Release builds using Linux Standard Base |
50 #include <boost/math/special_functions/round.hpp> | |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
51 #include <boost/shared_ptr.hpp> |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
53 /** |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
54 * 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
|
55 * 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
|
56 * 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
|
57 **/ |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
58 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
|
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 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
61 static const std::string CHECK_REVISIONS = "CheckRevisions"; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
62 |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
63 static const char* const IGNORE_LENGTH = "ignore-length"; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
64 static const char* const RECONSTRUCT_FILES = "ReconstructFiles"; |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
65 static const char* const LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS = "LimitToThisLevelMainDicomTags"; |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
66 static const char* const ARG_WHOLE = "whole"; |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
67 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
68 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
4415 | 71 static std::string GetDocumentationSampleResource(ResourceType type) |
72 { | |
73 switch (type) | |
74 { | |
75 case Orthanc::ResourceType_Instance: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
76 return "https://orthanc.uclouvain.be/demo/instances/6582b1c0-292ad5ab-ba0f088f-f7a1766f-9a29a54f"; |
4415 | 77 break; |
78 | |
79 case Orthanc::ResourceType_Series: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
80 return "https://orthanc.uclouvain.be/demo/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52"; |
4415 | 81 break; |
82 | |
83 case Orthanc::ResourceType_Study: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
84 return "https://orthanc.uclouvain.be/demo/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988"; |
4415 | 85 break; |
86 | |
87 case Orthanc::ResourceType_Patient: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
88 return "https://orthanc.uclouvain.be/demo/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382"; |
4415 | 89 break; |
90 | |
91 default: | |
92 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
93 } | |
94 } | |
95 | |
96 | |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
97 static void AnswerDicomAsJson(RestApiCall& call, |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
98 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
|
99 DicomToJsonFormat mode) |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
100 { |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
101 if (mode != DicomToJsonFormat_Full) |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
102 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
103 Json::Value simplified; |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
104 Toolbox::SimplifyDicomAsJson(simplified, dicom, mode); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
105 call.GetOutput().AnswerJson(simplified); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
106 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
107 else |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
108 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
109 call.GetOutput().AnswerJson(dicom); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
110 } |
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 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
|
115 const RestApiGetCall& call, |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
116 const std::string& argument) |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
117 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
118 target.clear(); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
119 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
120 if (call.HasArgument(argument)) |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
121 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
122 std::vector<std::string> tags; |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
123 Toolbox::TokenizeString(tags, call.GetArgument(argument, ""), ','); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
124 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
125 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
|
126 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
127 target.insert(FromDcmtkBridge::ParseTag(tags[i])); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
128 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
129 } |
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 |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
133 static bool ExpandResource(Json::Value& target, |
5714
2b05428843d2
removed dangerous overload of ResourceFinder::Execute()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5713
diff
changeset
|
134 ServerContext& context, |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
135 ResourceType level, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
136 const std::string& identifier, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
137 DicomToJsonFormat format, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
138 bool retrieveMetadata) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
139 { |
5832 | 140 ResponseContentFlags responseContent = ResponseContentFlags_ExpandTrue; |
5829 | 141 |
142 if (retrieveMetadata) | |
143 { | |
144 responseContent = static_cast<ResponseContentFlags>(static_cast<uint32_t>(responseContent) | ResponseContentFlags_Metadata); | |
145 } | |
146 | |
147 ResourceFinder finder(level, responseContent); | |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
148 finder.SetOrthancId(level, identifier); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
149 finder.SetRetrieveMetadata(retrieveMetadata); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
150 |
5714
2b05428843d2
removed dangerous overload of ResourceFinder::Execute()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5713
diff
changeset
|
151 return finder.ExecuteOneResource(target, context, format, retrieveMetadata); |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
152 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
153 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
154 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 // List all the patients, studies, series or instances ---------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 template <enum ResourceType resourceType> |
974 | 158 static void ListResources(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 { |
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
|
160 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
|
161 { |
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
|
162 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
163 OrthancRestApi::DocumentRequestedTags(call); |
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
|
164 |
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
|
165 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
|
166 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
|
167 .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
|
168 .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
|
169 .SetDescription("List the Orthanc identifiers of all the available DICOM " + resources) |
4403 | 170 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) |
171 .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
|
172 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, |
4403 | 173 "If present, retrieve detailed information about the individual " + resources, false) |
4404 | 174 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " |
175 "about the reported " + resources + " (if `expand` argument is provided)") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
176 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/" + 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
|
177 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
|
178 } |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
179 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
180 // TODO-FIND: include the FindRequest options parsing in a method (parse from get-arguments and from post payload) |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
181 // TODO-FIND: support other values for expand like expand=MainDicomTags,Labels,Parent,SeriesStatus |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
182 const bool expand = (call.HasArgument("expand") && |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
183 call.GetBooleanArgument("expand", true)); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
184 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
185 std::set<DicomTag> requestedTags; |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
186 OrthancRestApi::GetRequestedTags(requestedTags, call); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
187 |
5833
58c549b881ae
merged find-refactoring -> find-refactoring-clean
Alain Mazy <am@orthanc.team>
diff
changeset
|
188 ResourceFinder finder(resourceType, (expand ? ResponseContentFlags_ExpandTrue : ResponseContentFlags_ID)); |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
189 finder.AddRequestedTags(requestedTags); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
190 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
191 if (call.HasArgument("limit") || |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
192 call.HasArgument("since")) |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
193 { |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
194 if (!call.HasArgument("limit")) |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
195 { |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
196 throw OrthancException(ErrorCode_BadRequest, |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
197 "Missing \"limit\" argument for GET request against: " + |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
198 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
|
199 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
200 |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
201 if (!call.HasArgument("since")) |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
202 { |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
203 throw OrthancException(ErrorCode_BadRequest, |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
204 "Missing \"since\" argument for GET request against: " + |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
205 call.FlattenUri()); |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
206 } |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
207 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
208 uint64_t since = boost::lexical_cast<uint64_t>(call.GetArgument("since", "")); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
209 uint64_t limit = boost::lexical_cast<uint64_t>(call.GetArgument("limit", "")); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
210 finder.SetLimitsSince(since); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
211 finder.SetLimitsCount(limit); |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
212 } |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
213 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
214 Json::Value answer; |
5715
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
215 finder.Execute(answer, OrthancRestApi::GetContext(call), |
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
216 OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human), false /* no "Metadata" field */); |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
217 call.GetOutput().AnswerJson(answer); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 |
4409 | 220 |
221 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 template <enum ResourceType resourceType> |
974 | 223 static void GetSingleResource(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 { |
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
|
225 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
|
226 { |
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
|
227 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
228 OrthancRestApi::DocumentRequestedTags(call); |
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 |
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
|
230 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
|
231 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
|
232 .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
|
233 .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
|
234 .SetDescription("Get detailed information about the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
4404 | 235 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
4409 | 236 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) |
237 .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
|
238 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
|
239 } |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
240 |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
241 std::set<DicomTag> requestedTags; |
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
242 OrthancRestApi::GetRequestedTags(requestedTags, call); |
4935
acd3f72e2a21
split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
243 |
5710
a786da7599d5
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
244 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human); |
a786da7599d5
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
245 |
5833
58c549b881ae
merged find-refactoring -> find-refactoring-clean
Alain Mazy <am@orthanc.team>
diff
changeset
|
246 ResourceFinder finder(resourceType, ResponseContentFlags_ExpandTrue); |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
247 finder.AddRequestedTags(requestedTags); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
248 finder.SetOrthancId(resourceType, call.GetUriComponent("id", "")); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
249 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
250 Json::Value json; |
5715
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
251 if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format, false /* no "Metadata" field */)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 { |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
253 call.GetOutput().AnswerJson(json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 template <enum ResourceType resourceType> |
974 | 258 static void DeleteSingleResource(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 { |
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
|
260 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
|
261 { |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
262 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
|
263 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
|
264 .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
|
265 .SetSummary("Delete some " + resource) |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
266 .SetDescription("Delete the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
4404 | 267 .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
|
268 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
|
269 } |
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
|
270 |
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
|
271 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
|
272 if (OrthancRestApi::GetContext(call).DeleteResource(remainingAncestor, call.GetUriComponent("id", ""), resourceType)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 { |
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
|
274 call.GetOutput().AnswerJson(remainingAncestor); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 // Get information about a single patient ----------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 |
974 | 281 static void IsProtectedPatient(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 { |
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
|
283 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
|
284 { |
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 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
|
286 .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
|
287 .SetSummary("Is the patient protected against recycling?") |
4404 | 288 .SetUriArgument("id", "Orthanc identifier of the patient of interest") |
4403 | 289 .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
|
290 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
|
291 } |
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
|
292 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
295 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 |
974 | 299 static void SetPatientProtection(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 { |
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
|
301 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
|
302 { |
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 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
|
304 .SetTag("Patients") |
5467
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5446
diff
changeset
|
305 .SetSummary("Protect/Unprotect a patient against recycling") |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5446
diff
changeset
|
306 .SetDescription("Protects a patient by sending `1` or `true` in the payload request. " |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5446
diff
changeset
|
307 "Unprotects a patient by sending `0` or `false` in the payload requests. " |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5446
diff
changeset
|
308 "More info: https://orthanc.uclouvain.be/book/faq/features.html#recycling-protection") |
4404 | 309 .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
|
310 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
|
311 } |
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
|
312 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 ServerContext& context = OrthancRestApi::GetContext(call); |
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 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 |
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
|
317 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
|
318 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 // Get information about a single instance ---------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 |
974 | 324 static void GetInstanceFile(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 { |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
326 static const char* const TRANSCODE = "transcode"; |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
327 |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
328 if (call.IsDocumentation()) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
329 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
330 call.GetDocumentation() |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
331 .SetTag("Instances") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
332 .SetSummary("Download DICOM") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
333 .SetDescription("Download one DICOM instance") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
334 .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
|
335 .SetHttpHeader("Accept", "This HTTP header can be set to retrieve the DICOM instance in DICOMweb format") |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
336 .SetHttpGetArgument(TRANSCODE, RestApiCallDocumentation::Type_String, |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
337 "If present, the DICOM file will be transcoded to the provided " |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
338 "transfer syntax: https://orthanc.uclouvain.be/book/faq/transcoding.html", false) |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
339 .AddAnswerType(MimeType_Dicom, "The DICOM instance") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
340 .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
|
341 .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
|
342 return; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
343 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
344 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 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
|
348 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4294
diff
changeset
|
349 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
|
350 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
|
351 { |
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 // 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
|
353 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
|
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 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
|
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 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
|
358 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
|
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 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
|
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 { |
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 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
|
364 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
|
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 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
|
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 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
|
370 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
|
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 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
|
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 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
|
375 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
|
376 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
|
377 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
378 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
379 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
|
380 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
381 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
382 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
|
383 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
384 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
385 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
386 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
387 if (call.HasArgument(TRANSCODE)) |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
388 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
389 std::string source; |
5427 | 390 std::string attachmentId; |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
391 std::string transcoded; |
5427 | 392 context.ReadDicom(source, attachmentId, publicId); |
393 | |
394 if (context.TranscodeWithCache(transcoded, source, publicId, attachmentId, GetTransferSyntax(call.GetArgument(TRANSCODE, "")))) | |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
395 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
396 call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom); |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
397 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
398 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
399 else |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
400 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
401 // return the attachment without any transcoding |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
402 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom); |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
403 } |
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 |
974 | 407 static void ExportInstanceFile(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 { |
4421 | 409 if (call.IsDocumentation()) |
410 { | |
411 call.GetDocumentation() | |
412 .SetTag("Instances") | |
413 .SetSummary("Write DICOM onto filesystem") | |
5200
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
414 .SetDescription("Write the DICOM file onto the filesystem where Orthanc is running. This is insecure for " |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
415 "Orthanc servers that are remotely accessible since one could overwrite any system file. " |
5275
8686476e9d12
fix inclusion of winsock.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5274
diff
changeset
|
416 "Since Orthanc 1.12.0, this route is disabled by default, but can be enabled using " |
8686476e9d12
fix inclusion of winsock.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5274
diff
changeset
|
417 "the `RestApiWriteToFileSystemEnabled` configuration option.") |
4421 | 418 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
419 .AddRequestType(MimeType_PlainText, "Target path on the filesystem"); | |
420 return; | |
421 } | |
422 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
423 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 |
5200
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
425 if (!context.IsRestApiWriteToFileSystemEnabled()) |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
426 { |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
427 LOG(ERROR) << "The URI /instances/../export is disallowed for security, " |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
428 << "check your configuration option `RestApiWriteToFileSystemEnabled`"; |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
429 call.GetOutput().SignalError(HttpStatus_403_Forbidden); |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
430 return; |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
431 } |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
432 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
433 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 std::string dicom; |
2124 | 436 context.ReadDicom(dicom, publicId); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
438 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
|
439 call.BodyToString(target); |
2140 | 440 SystemToolbox::WriteFile(dicom, target); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
442 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
446 template <DicomToJsonFormat format> |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
447 static void GetInstanceTagsInternal(RestApiGetCall& call, |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
448 bool whole) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
449 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
452 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
|
453 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
454 std::set<DicomTag> ignoreTagLength; |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
455 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
456 |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
457 if (whole) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 { |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
459 // This is new in Orthanc 1.12.4. Reference: |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
460 // https://discourse.orthanc-server.org/t/private-tags-with-group-7fe0-are-not-provided-via-rest-api/4744 |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
461 const DicomToJsonFlags flags = static_cast<DicomToJsonFlags>(DicomToJsonFlags_Default & ~DicomToJsonFlags_StopAfterPixelData); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
462 |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
463 Json::Value answer; |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
464 |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
465 { |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
466 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
467 locker.GetDicom().DatasetToJson(answer, format, flags, |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
468 ORTHANC_MAXIMUM_TAG_LENGTH, ignoreTagLength); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
469 } |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
470 |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
471 call.GetOutput().AnswerJson(answer); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
472 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
474 { |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
475 if (format != DicomToJsonFormat_Full || |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
476 !ignoreTagLength.empty()) |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
477 { |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
478 Json::Value full; |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
479 context.ReadDicomAsJson(full, publicId, ignoreTagLength); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
480 AnswerDicomAsJson(call, full, format); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
481 } |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
482 else |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
483 { |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
484 // This path allows one to avoid the JSON decoding if no |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
485 // simplification is asked, and if no "ignore-length" argument |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
486 // is present |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
487 Json::Value full; |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
488 context.ReadDicomAsJson(full, publicId); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
489 call.GetOutput().AnswerJson(full); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
490 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
491 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
492 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
494 |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
495 static void DocumentGetInstanceTags(RestApiGetCall& call) |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
496 { |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
497 call.GetDocumentation() |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
498 .SetTag("Instances") |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
499 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
500 .SetHttpGetArgument( |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
501 IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings, |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
502 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false) |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
503 .SetHttpGetArgument( |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
504 ARG_WHOLE, RestApiCallDocumentation::Type_Boolean, "Whether to read the whole DICOM file from the " |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
505 "storage area (new in Orthanc 1.12.4). If set to \"false\" (default value), the DICOM file is read " |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
506 "until the pixel data tag (7fe0,0010) to optimize access to storage. Setting the option " |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
507 "to \"true\" provides access to the DICOM tags stored after the pixel data tag.", false) |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
508 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value"); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
509 } |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
510 |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
511 |
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
|
512 static void GetInstanceTags(RestApiGetCall& call) |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
513 { |
4404 | 514 if (call.IsDocumentation()) |
515 { | |
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
|
516 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full); |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
517 DocumentGetInstanceTags(call); |
4404 | 518 call.GetDocumentation() |
519 .SetSummary("Get DICOM tags") | |
520 .SetDescription("Get the DICOM tags in the specified format. By default, the `full` format is used, which " | |
521 "combines hexadecimal tags with human-readable description.") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
522 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10); |
4404 | 523 return; |
524 } | |
525 | |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
526 const bool whole = call.GetBooleanArgument(ARG_WHOLE, false); |
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
527 |
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
|
528 switch (OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)) |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
529 { |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
530 case DicomToJsonFormat_Human: |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
531 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call, whole); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
532 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
533 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
534 case DicomToJsonFormat_Short: |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
535 GetInstanceTagsInternal<DicomToJsonFormat_Short>(call, whole); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
536 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
537 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
538 case DicomToJsonFormat_Full: |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
539 GetInstanceTagsInternal<DicomToJsonFormat_Full>(call, whole); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
540 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
541 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
542 default: |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
543 throw OrthancException(ErrorCode_InternalError); |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
544 } |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
545 } |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
546 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
547 |
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
|
548 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
|
549 { |
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
|
550 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
|
551 { |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
552 DocumentGetInstanceTags(call); |
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
|
553 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
|
554 .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
|
555 .SetDescription("Get the DICOM tags in human-readable format (same as the `/instances/{id}/tags?simplify` route)") |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
556 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", 10); |
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
|
557 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
|
558 } |
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
|
559 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
|
560 { |
5647
f048683aa619
added "?whole" option to "/instances/{id}/tags" to access tags stored after pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5640
diff
changeset
|
561 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call, call.GetBooleanArgument(ARG_WHOLE, false)); |
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
|
562 } |
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
|
563 } |
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
|
564 |
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
|
565 |
974 | 566 static void ListFrames(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
567 { |
4414 | 568 if (call.IsDocumentation()) |
569 { | |
570 call.GetDocumentation() | |
571 .SetTag("Instances") | |
572 .SetSummary("List available frames") | |
573 .SetDescription("List the frames that are available in the DICOM instance of interest") | |
574 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
575 .AddAnswerType(MimeType_Json, "The list of the indices of the available frames") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
576 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/frames", true); |
4414 | 577 return; |
578 } | |
579 | |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
580 std::string publicId = call.GetUriComponent("id", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
581 |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
582 unsigned int numberOfFrames; |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
583 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
584 { |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
585 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
|
586 numberOfFrames = locker.GetDicom().GetFramesCount(); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
587 } |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
588 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
589 Json::Value result = Json::arrayValue; |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
590 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
|
591 { |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
592 result.append(i); |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
593 } |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
594 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
595 call.GetOutput().AnswerJson(result); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
596 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
597 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
598 |
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
|
599 namespace |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
600 { |
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
|
601 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
|
602 { |
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
|
603 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
604 std::unique_ptr<ImageAccessor>& image_; |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
605 ImageExtractionMode mode_; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
606 bool invert_; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
607 MimeType format_; |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
608 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
|
609 |
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
|
610 public: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
611 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
|
612 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
613 bool invert) : |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
614 image_(image), |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
615 mode_(mode), |
4205 | 616 invert_(invert), |
617 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
|
618 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
619 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
620 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
621 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
|
622 { |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
623 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
|
624 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
625 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
626 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
|
627 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
628 format_ = MimeType_Png; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
629 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
|
630 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
631 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
632 void EncodeUsingPam() |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
633 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
634 format_ = MimeType_Pam; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
635 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
|
636 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
637 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
638 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
|
639 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
640 format_ = MimeType_Jpeg; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
641 DicomImageDecoder::ExtractJpegImage(answer_, image_, mode_, invert_, quality); |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1784
diff
changeset
|
642 } |
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
|
643 }; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
644 |
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
|
645 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
|
646 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
647 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
|
648 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
|
649 |
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
|
650 public: |
4205 | 651 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
|
652 { |
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
|
653 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
654 |
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
|
655 virtual void Handle(const std::string& type, |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
656 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
657 const HttpContentNegociation::Dictionary& parameters) 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
|
658 { |
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
|
659 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
|
660 assert(subtype == "png"); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
661 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
|
662 } |
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
|
663 }; |
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
|
664 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
665 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
|
666 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
667 private: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
668 ImageToEncode& image_; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
669 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
670 public: |
4205 | 671 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
|
672 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
673 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
674 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
675 virtual void Handle(const std::string& type, |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
676 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
677 const HttpContentNegociation::Dictionary& parameters) ORTHANC_OVERRIDE |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
678 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
679 assert(type == "image"); |
2780 | 680 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
|
681 image_.EncodeUsingPam(); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
682 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
683 }; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
684 |
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
|
685 class EncodeJpeg : public HttpContentNegociation::IHandler |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
686 { |
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
|
687 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
|
688 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
|
689 unsigned int quality_; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
690 |
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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 { |
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
|
696 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
|
697 bool ok = false; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
698 |
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
|
699 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
|
700 { |
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
|
701 quality_ = boost::lexical_cast<unsigned int>(v); |
1847 | 702 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
|
703 } |
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
|
704 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
|
705 { |
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
|
706 } |
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
|
707 |
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
|
708 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
|
709 { |
2955 | 710 throw OrthancException( |
711 ErrorCode_BadRequest, | |
712 "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
|
713 } |
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
|
714 } |
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
|
715 |
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
|
716 virtual void Handle(const std::string& type, |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
717 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
718 const HttpContentNegociation::Dictionary& parameters) 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
|
719 { |
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
|
720 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
|
721 assert(subtype == "jpeg"); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
722 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
|
723 } |
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
|
724 }; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
725 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
726 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
727 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
728 namespace |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
729 { |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
730 class IDecodedFrameHandler : public boost::noncopyable |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
731 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
732 public: |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
733 virtual ~IDecodedFrameHandler() |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
734 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
735 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
736 |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
737 // "dicom" is non-NULL iff. "RequiresDicomTags() == true" |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
738 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
|
739 std::unique_ptr<ImageAccessor>& decoded, |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
740 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
741 unsigned int frame) = 0; |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
742 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
743 virtual bool RequiresDicomTags() const = 0; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
744 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
745 static void Apply(RestApiGetCall& call, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
746 IDecodedFrameHandler& handler, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
747 ImageExtractionMode mode /* for generation of documentation */, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
748 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
|
749 { |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
750 if (call.IsDocumentation()) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
751 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
752 std::string m; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
753 if (!isRendered) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
754 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
755 switch (mode) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
756 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
757 case ImageExtractionMode_Preview: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
758 m = "preview"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
759 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
760 case ImageExtractionMode_UInt8: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
761 m = "uint8"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
762 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
763 case ImageExtractionMode_UInt16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
764 m = "uint16"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
765 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
766 case ImageExtractionMode_Int16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
767 m = "int16"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
768 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
769 default: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
770 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
771 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
772 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
773 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
774 std::string description; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
775 std::string verb = (isRendered ? "Render" : "Decode"); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
776 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
777 if (call.HasUriComponent("frame")) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
778 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
779 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
|
780 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
781 .SetSummary(verb + " a frame" + (m.empty() ? "" : " (" + m + ")")) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
782 .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
|
783 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
784 else |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
785 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
786 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
|
787 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
788 .SetSummary(verb + " an image" + (m.empty() ? "" : " (" + m + ")")); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
789 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
790 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
791 if (isRendered) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
792 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
793 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
|
794 "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
|
795 "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
|
796 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
797 .SetHttpGetArgument("window-center",RestApiCallDocumentation::Type_Number, "Windowing center", false) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
798 .SetHttpGetArgument("window-width",RestApiCallDocumentation::Type_Number, "Windowing width", false) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
799 .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
|
800 .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
|
801 .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
|
802 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
803 else |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
804 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
805 switch (mode) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
806 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
807 case ImageExtractionMode_Preview: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
808 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
|
809 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
810 case ImageExtractionMode_UInt8: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
811 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
|
812 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
813 case ImageExtractionMode_UInt16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
814 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
|
815 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
816 case ImageExtractionMode_Int16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
817 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
|
818 "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
|
819 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
820 default: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
821 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
822 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
823 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
824 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
825 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
826 .SetTag("Instances") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
827 .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
|
828 .SetHttpGetArgument("quality", RestApiCallDocumentation::Type_Number, "Quality for JPEG images (between 1 and 100, defaults to 90)", false) |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
829 .SetHttpGetArgument("returnUnsupportedImage", RestApiCallDocumentation::Type_Boolean, "Returns an unsupported.png placeholder image if unable to provide the image instead of returning a 415 HTTP error (defaults to false)", false) |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
830 .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
|
831 .AddAnswerType(MimeType_Png, "PNG image") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
832 .AddAnswerType(MimeType_Jpeg, "JPEG image") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
833 .AddAnswerType(MimeType_Pam, "PAM image (Portable Arbitrary Map)") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
834 .SetDescription(description); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
835 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
836 return; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
837 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
838 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
839 ServerContext& context = OrthancRestApi::GetContext(call); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
840 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
841 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
|
842 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
843 unsigned int frame; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
844 try |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
845 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
846 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
|
847 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
848 catch (boost::bad_lexical_cast&) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
849 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
850 return; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
851 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
852 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
853 std::unique_ptr<ImageAccessor> decoded; |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
854 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
855 try |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
856 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
857 std::string publicId = call.GetUriComponent("id", ""); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
858 |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
859 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
|
860 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
861 if (decoded.get() == NULL) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
862 { |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
863 throw OrthancException(ErrorCode_NotImplemented, |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
864 "Cannot decode DICOM instance with ID: " + publicId); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
865 } |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
866 |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
867 if (handler.RequiresDicomTags()) |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
868 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
869 /** |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
870 * Retrieve a summary of the DICOM tags, which is |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
871 * necessary to deal with MONOCHROME1 photometric |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
872 * interpretation, and with windowing parameters. |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
873 **/ |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
874 ServerContext::DicomCacheLocker locker(context, publicId); |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
875 handler.Handle(call, decoded, &locker.GetDicom(), frame); |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
876 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
877 else |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
878 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
879 handler.Handle(call, decoded, NULL, frame); |
3683
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 catch (OrthancException& e) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
883 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
884 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange || |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
885 e.GetErrorCode() == ErrorCode_UnknownResource) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
886 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
887 // 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
|
888 // instance, the resource is not existent |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
889 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
890 else |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
891 { |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
892 if (call.HasArgument("returnUnsupportedImage")) |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
893 { |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
894 std::string root = ""; |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
895 for (size_t i = 1; i < call.GetFullUri().size(); i++) |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
896 { |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
897 root += "../"; |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
898 } |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
899 |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
900 call.GetOutput().Redirect(root + "app/images/unsupported.png"); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
901 } |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
902 else |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
903 { |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
904 call.GetOutput().SignalError(HttpStatus_415_UnsupportedMediaType); |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
905 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
906 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
907 return; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
908 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
909 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
910 } |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
911 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
912 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
913 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
|
914 std::unique_ptr<ImageAccessor>& decoded, |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
915 ImageExtractionMode mode, |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
916 bool invert) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
917 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
918 ImageToEncode image(decoded, mode, invert); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
919 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
920 HttpContentNegociation negociation; |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
921 EncodePng png(image); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
922 negociation.Register(MIME_PNG, png); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
923 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
924 EncodeJpeg jpeg(image, call); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
925 negociation.Register(MIME_JPEG, jpeg); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
926 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
927 EncodePam pam(image); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
928 negociation.Register(MIME_PAM, pam); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
929 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
930 if (negociation.Apply(call.GetHttpHeaders())) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
931 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
932 image.Answer(call.GetOutput()); |
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 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
935 }; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
936 |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
937 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
938 class GetImageHandler : public IDecodedFrameHandler |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
939 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
940 private: |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
941 ImageExtractionMode mode_; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
942 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
943 public: |
4205 | 944 explicit GetImageHandler(ImageExtractionMode mode) : |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
945 mode_(mode) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
946 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
947 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
948 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
949 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
|
950 std::unique_ptr<ImageAccessor>& decoded, |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
951 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
952 unsigned int frame) ORTHANC_OVERRIDE |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
953 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
954 bool invert = false; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
955 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
956 if (mode_ == ImageExtractionMode_Preview) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
957 { |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
958 if (dicom == NULL) |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
959 { |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
960 throw OrthancException(ErrorCode_InternalError); |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
961 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
962 |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
963 DicomMap tags; |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
964 OrthancConfiguration::DefaultExtractDicomSummary(tags, *dicom); |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
965 |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
966 DicomImageInformation info(tags); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
967 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
968 } |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
969 |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
970 DefaultHandler(call, decoded, mode_, invert); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
971 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
972 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
973 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
974 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
975 return mode_ == ImageExtractionMode_Preview; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
976 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
977 }; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
978 |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
979 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
980 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
|
981 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
982 private: |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
983 static void GetUserArguments(double& windowWidth /* inout */, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
984 double& windowCenter /* inout */, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
985 unsigned int& argWidth, |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
986 unsigned int& argHeight, |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
987 bool& smooth, |
4205 | 988 const RestApiGetCall& call) |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
989 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
990 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
|
991 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
|
992 static const char* ARG_WIDTH = "width"; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
993 static const char* ARG_HEIGHT = "height"; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
994 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
|
995 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
996 if (call.HasArgument(ARG_WINDOW_WIDTH) && |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
997 !SerializationToolbox::ParseDouble(windowWidth, call.GetArgument(ARG_WINDOW_WIDTH, ""))) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
998 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
999 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1000 "Bad value for argument: " + std::string(ARG_WINDOW_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1001 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1002 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1003 if (call.HasArgument(ARG_WINDOW_CENTER) && |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1004 !SerializationToolbox::ParseDouble(windowCenter, call.GetArgument(ARG_WINDOW_CENTER, ""))) |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1005 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1006 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1007 "Bad value for argument: " + std::string(ARG_WINDOW_CENTER)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1008 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1009 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1010 argWidth = 0; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1011 argHeight = 0; |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1012 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1013 if (call.HasArgument(ARG_WIDTH)) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1014 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1015 try |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1016 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1017 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
|
1018 if (tmp < 0) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1019 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1020 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1021 "Argument cannot be negative: " + std::string(ARG_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1022 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1023 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1024 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1025 argWidth = static_cast<unsigned int>(tmp); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1026 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1027 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1028 catch (boost::bad_lexical_cast&) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1029 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1030 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1031 "Bad value for argument: " + std::string(ARG_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1032 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1033 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1034 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1035 if (call.HasArgument(ARG_HEIGHT)) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1036 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1037 try |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1038 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1039 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
|
1040 if (tmp < 0) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1041 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1042 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1043 "Argument cannot be negative: " + std::string(ARG_HEIGHT)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1044 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1045 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1046 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1047 argHeight = static_cast<unsigned int>(tmp); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1048 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1049 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1050 catch (boost::bad_lexical_cast&) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1051 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1052 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1053 "Bad value for argument: " + std::string(ARG_HEIGHT)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1054 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1055 } |
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 smooth = false; |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1058 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1059 if (call.HasArgument(ARG_SMOOTH)) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1060 { |
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
|
1061 smooth = RestApiCall::ParseBoolean(call.GetArgument(ARG_SMOOTH, "")); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1062 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1063 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1064 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1065 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1066 public: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1067 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
|
1068 std::unique_ptr<ImageAccessor>& decoded, |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1069 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1070 unsigned int frame) ORTHANC_OVERRIDE |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1071 { |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1072 if (dicom == NULL) |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1073 { |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1074 throw OrthancException(ErrorCode_InternalError); |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1075 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1076 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1077 PhotometricInterpretation photometric; |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1078 const bool invert = (dicom->LookupPhotometricInterpretation(photometric) && |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1079 photometric == PhotometricInterpretation_Monochrome1); |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1080 |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1081 double rescaleIntercept, rescaleSlope, windowCenter, windowWidth; |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1082 dicom->GetRescale(rescaleIntercept, rescaleSlope, frame); |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1083 dicom->GetDefaultWindowing(windowCenter, windowWidth, frame); |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1084 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1085 unsigned int argWidth, argHeight; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1086 bool smooth; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1087 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
|
1088 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1089 unsigned int targetWidth = decoded->GetWidth(); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1090 unsigned int targetHeight = decoded->GetHeight(); |
3686 | 1091 |
1092 if (decoded->GetWidth() != 0 && | |
1093 decoded->GetHeight() != 0) | |
1094 { | |
1095 float ratio = 1; | |
1096 | |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1097 if (argWidth != 0 && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1098 argHeight != 0) |
3686 | 1099 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1100 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
|
1101 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
|
1102 ratio = std::min(ratioX, ratioY); |
3686 | 1103 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1104 else if (argWidth != 0) |
3686 | 1105 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1106 ratio = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth()); |
3686 | 1107 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1108 else if (argHeight != 0) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1109 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1110 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
|
1111 } |
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 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
|
1114 targetHeight = boost::math::iround(ratio * static_cast<float>(decoded->GetHeight())); |
3686 | 1115 } |
1116 | |
5054
255b02c68908
Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents:
5048
diff
changeset
|
1117 if (decoded->GetFormat() == PixelFormat_RGB24 || decoded->GetFormat() == PixelFormat_RGB48) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1118 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1119 if (targetWidth == decoded->GetWidth() && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1120 targetHeight == decoded->GetHeight()) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1121 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1122 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1123 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1124 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1125 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1126 std::unique_ptr<ImageAccessor> resized( |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1127 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
|
1128 |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1129 if (smooth && |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1130 (targetWidth < decoded->GetWidth() || |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1131 targetHeight < decoded->GetHeight())) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1132 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
1133 ImageProcessing::SmoothGaussian5x5(*decoded, false /* be fast, don't round */); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1134 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1135 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1136 ImageProcessing::Resize(*resized, *decoded); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1137 DefaultHandler(call, resized, ImageExtractionMode_Preview, false); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1138 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1139 } |
3686 | 1140 else |
1141 { | |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1142 // 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
|
1143 // 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
|
1144 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1145 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
|
1146 ImageProcessing::Convert(converted, *decoded); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1147 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1148 // Avoid divisions by zero |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1149 if (windowWidth <= 1.0f) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1150 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1151 windowWidth = 1; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1152 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1153 |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1154 if (std::abs(rescaleSlope) <= 0.0001) |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1155 { |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1156 rescaleSlope = 0.0001; |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1157 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1158 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1159 const double scaling = 255.0 * rescaleSlope / windowWidth; |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1160 const double offset = (rescaleIntercept - windowCenter + windowWidth / 2.0) / rescaleSlope; |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1161 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1162 std::unique_ptr<ImageAccessor> rescaled(new Image(PixelFormat_Grayscale8, decoded->GetWidth(), decoded->GetHeight(), false)); |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1163 ImageProcessing::ShiftScale(*rescaled, converted, static_cast<float>(offset), static_cast<float>(scaling), false); |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1164 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1165 if (targetWidth == decoded->GetWidth() && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1166 targetHeight == decoded->GetHeight()) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1167 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1168 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1169 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1170 else |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1171 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1172 std::unique_ptr<ImageAccessor> resized( |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1173 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
|
1174 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1175 if (smooth && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1176 (targetWidth < decoded->GetWidth() || |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1177 targetHeight < decoded->GetHeight())) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1178 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
1179 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
|
1180 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1181 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1182 ImageProcessing::Resize(*resized, *rescaled); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1183 DefaultHandler(call, resized, ImageExtractionMode_UInt8, invert); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1184 } |
3686 | 1185 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1186 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1187 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1188 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1189 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1190 return true; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1191 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1192 }; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1193 } |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1194 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1195 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1196 template <enum ImageExtractionMode mode> |
974 | 1197 static void GetImage(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1198 { |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1199 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
|
1200 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1201 GetImageHandler handler(mode); |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1202 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
|
1203 } |
1906
d7c1cb559431
optimization for multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1902
diff
changeset
|
1204 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1205 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1206 static void GetRenderedFrame(RestApiGetCall& call) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1207 { |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1208 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
|
1209 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1210 RenderedFrameHandler handler; |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1211 IDecodedFrameHandler::Apply(call, handler, ImageExtractionMode_Preview /* arbitrary value */, true); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1212 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1213 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1214 |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1215 static void DocumentSharedNumpy(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1216 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1217 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1218 .SetUriArgument("id", "Orthanc identifier of the DICOM resource of interest") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1219 .SetHttpGetArgument("compress", RestApiCallDocumentation::Type_Boolean, "Compress the file as `.npz`", false) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1220 .SetHttpGetArgument("rescale", RestApiCallDocumentation::Type_Boolean, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1221 "On grayscale images, apply the rescaling and return floating-point values", false) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1222 .AddAnswerType(MimeType_PlainText, "Numpy file: https://numpy.org/devdocs/reference/generated/numpy.lib.format.html"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1223 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1224 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1225 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1226 namespace |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1227 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1228 class NumpyVisitor : public boost::noncopyable |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1229 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1230 private: |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1231 bool rescale_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1232 unsigned int depth_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1233 unsigned int currentDepth_; |
4858 | 1234 unsigned int width_; |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1235 unsigned int height_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1236 PixelFormat format_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1237 ChunkedBuffer buffer_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1238 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1239 public: |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1240 NumpyVisitor(unsigned int depth /* can be zero if 2D frame */, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1241 bool rescale) : |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1242 rescale_(rescale), |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1243 depth_(depth), |
4858 | 1244 currentDepth_(0), |
1245 width_(0), // dummy initialization | |
1246 height_(0), // dummy initialization | |
1247 format_(PixelFormat_Grayscale8) // dummy initialization | |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1248 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1249 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1250 |
4858 | 1251 void WriteFrame(const ParsedDicomFile& dicom, |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1252 unsigned int frame) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1253 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1254 std::unique_ptr<ImageAccessor> decoded(dicom.DecodeFrame(frame)); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1255 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1256 if (decoded.get() == NULL) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1257 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1258 throw OrthancException(ErrorCode_NotImplemented, "Cannot decode DICOM instance"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1259 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1260 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1261 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1262 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1263 width_ = decoded->GetWidth(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1264 height_ = decoded->GetHeight(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1265 format_ = decoded->GetFormat(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1266 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1267 else if (width_ != decoded->GetWidth() || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1268 height_ != decoded->GetHeight()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1269 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1270 throw OrthancException(ErrorCode_IncompatibleImageSize, "The size of the frames varies across the instance(s)"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1271 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1272 else if (format_ != decoded->GetFormat()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1273 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1274 throw OrthancException(ErrorCode_IncompatibleImageFormat, "The pixel format of the frames varies across the instance(s)"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1275 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1276 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1277 if (rescale_ && |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1278 decoded->GetFormat() != PixelFormat_RGB24) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1279 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1280 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1281 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1282 NumpyWriter::WriteHeader(buffer_, depth_, width_, height_, PixelFormat_Float32); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1283 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1284 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1285 double rescaleIntercept, rescaleSlope; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1286 dicom.GetRescale(rescaleIntercept, rescaleSlope, frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1287 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1288 Image converted(PixelFormat_Float32, decoded->GetWidth(), decoded->GetHeight(), false); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1289 ImageProcessing::Convert(converted, *decoded); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1290 ImageProcessing::ShiftScale2(converted, static_cast<float>(rescaleIntercept), static_cast<float>(rescaleSlope), false); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1291 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1292 NumpyWriter::WritePixels(buffer_, converted); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1293 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1294 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1295 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1296 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1297 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1298 NumpyWriter::WriteHeader(buffer_, depth_, width_, height_, format_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1299 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1300 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1301 NumpyWriter::WritePixels(buffer_, *decoded); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1302 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1303 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1304 currentDepth_ ++; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1305 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1306 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1307 void Answer(RestApiOutput& output, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1308 bool compress) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1309 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1310 if ((depth_ == 0 && currentDepth_ != 1) || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1311 (depth_ != 0 && currentDepth_ != depth_)) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1312 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1313 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1314 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1315 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1316 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1317 std::string answer; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1318 NumpyWriter::Finalize(answer, buffer_, compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1319 output.AnswerBuffer(answer, MimeType_Binary); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1320 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1321 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1322 }; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1323 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1324 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1325 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1326 static void GetNumpyFrame(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1327 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1328 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1329 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1330 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1331 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1332 .SetTag("Instances") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1333 .SetSummary("Decode frame for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1334 .SetDescription("Decode one frame of interest from the given DICOM instance, for use with numpy in Python. " |
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1335 "The numpy array has 3 dimensions: (height, width, color channel).") |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1336 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1337 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1338 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1339 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1340 const std::string instanceId = call.GetUriComponent("id", ""); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1341 const bool compress = call.GetBooleanArgument("compress", false); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1342 const bool rescale = call.GetBooleanArgument("rescale", true); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1343 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1344 uint32_t frame; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1345 if (!SerializationToolbox::ParseUnsignedInteger32(frame, call.GetUriComponent("frame", "0"))) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1346 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1347 throw OrthancException(ErrorCode_ParameterOutOfRange, "Expected an unsigned integer for the \"frame\" argument"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1348 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1349 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1350 NumpyVisitor visitor(0 /* no depth, 2D frame */, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1351 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1352 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1353 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1354 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), instanceId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1355 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1356 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1357 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1358 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1359 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1360 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1361 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1362 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1363 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1364 static void GetNumpyInstance(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1365 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1366 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1367 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1368 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1369 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1370 .SetTag("Instances") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1371 .SetSummary("Decode instance for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1372 .SetDescription("Decode the given DICOM instance, for use with numpy in Python. " |
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1373 "The numpy array has 4 dimensions: (frame, height, width, color channel)."); |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1374 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1375 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1376 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1377 const std::string instanceId = call.GetUriComponent("id", ""); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1378 const bool compress = call.GetBooleanArgument("compress", false); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1379 const bool rescale = call.GetBooleanArgument("rescale", true); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1380 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1381 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1382 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1383 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), instanceId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1384 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1385 const unsigned int depth = locker.GetDicom().GetFramesCount(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1386 if (depth == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1387 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1388 throw OrthancException(ErrorCode_BadFileFormat, "Empty DICOM instance"); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1389 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1390 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1391 NumpyVisitor visitor(depth, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1392 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1393 for (unsigned int frame = 0; frame < depth; frame++) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1394 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1395 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1396 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1397 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1398 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1399 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1400 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1401 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1402 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1403 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1404 static void GetNumpySeries(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1405 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1406 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1407 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1408 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1409 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1410 .SetTag("Series") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1411 .SetSummary("Decode series for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1412 .SetDescription("Decode the given DICOM series, for use with numpy in Python. " |
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1413 "The numpy array has 4 dimensions: (frame, height, width, color channel)."); |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1414 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1415 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1416 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1417 const std::string seriesId = call.GetUriComponent("id", ""); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1418 const bool compress = call.GetBooleanArgument("compress", false); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1419 const bool rescale = call.GetBooleanArgument("rescale", true); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1420 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1421 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1422 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1423 ServerIndex& index = OrthancRestApi::GetIndex(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1424 SliceOrdering ordering(index, seriesId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1425 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1426 unsigned int depth = 0; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1427 for (size_t i = 0; i < ordering.GetInstancesCount(); i++) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1428 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1429 depth += ordering.GetFramesCount(i); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1430 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1431 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1432 ServerContext& context = OrthancRestApi::GetContext(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1433 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1434 NumpyVisitor visitor(depth, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1435 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1436 for (size_t i = 0; i < ordering.GetInstancesCount(); i++) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1437 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1438 const std::string& instanceId = ordering.GetInstanceId(i); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1439 unsigned int framesCount = ordering.GetFramesCount(i); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1440 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1441 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1442 ServerContext::DicomCacheLocker locker(context, instanceId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1443 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1444 for (unsigned int frame = 0; frame < framesCount; frame++) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1445 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1446 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1447 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1448 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1449 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1450 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1451 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1452 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1453 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1454 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1455 |
974 | 1456 static void GetMatlabImage(RestApiGetCall& call) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1457 { |
4414 | 1458 if (call.IsDocumentation()) |
1459 { | |
1460 std::string description; | |
1461 | |
1462 if (call.HasUriComponent("frame")) | |
1463 { | |
1464 description = "Decode one frame of interest from the given DICOM instance"; | |
1465 call.GetDocumentation() | |
1466 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); | |
1467 } | |
1468 else | |
1469 { | |
1470 description = "Decode the first frame of the given DICOM instance."; | |
1471 } | |
1472 | |
1473 call.GetDocumentation() | |
1474 .SetTag("Instances") | |
1475 .SetSummary("Decode frame for Matlab") | |
1476 .SetDescription(description + ", and export this frame as a Octave/Matlab matrix to be imported with `eval()`: " | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
1477 "https://orthanc.uclouvain.be/book/faq/matlab.html") |
4414 | 1478 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
1479 .AddAnswerType(MimeType_PlainText, "Octave/Matlab matrix"); | |
1480 return; | |
1481 } | |
1482 | |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1483 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
|
1484 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1485 ServerContext& context = OrthancRestApi::GetContext(call); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1486 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1487 std::string frameId = call.GetUriComponent("frame", "0"); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1488 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1489 unsigned int frame; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1490 try |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1491 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1492 frame = boost::lexical_cast<unsigned int>(frameId); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1493 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2804
diff
changeset
|
1494 catch (boost::bad_lexical_cast&) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1495 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1496 return; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1497 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1498 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1499 std::string publicId = call.GetUriComponent("id", ""); |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1500 std::unique_ptr<ImageAccessor> decoded(context.DecodeDicomFrame(publicId, frame)); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1501 |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1502 if (decoded.get() == NULL) |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1503 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1504 throw OrthancException(ErrorCode_NotImplemented, |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1505 "Cannot decode DICOM instance with ID: " + publicId); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1506 } |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1507 else |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1508 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1509 std::string result; |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1510 decoded->ToMatlabString(result); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1511 call.GetOutput().AnswerBuffer(result, MimeType_PlainText); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1512 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1513 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1514 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1515 |
2408
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1516 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
|
1517 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
|
1518 { |
4408 | 1519 if (call.IsDocumentation()) |
1520 { | |
1521 call.GetDocumentation() | |
1522 .SetTag("Instances") | |
1523 .SetSummary("Access raw frame" + std::string(GzipCompression ? " (compressed)" : "")) | |
1524 .SetDescription("Access the raw content of one individual frame of the DICOM instance of interest, " | |
1525 "bypassing image decoding. This is notably useful to access the source files " | |
1526 "in compressed transfer syntaxes." + | |
1527 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
|
1528 .SetUriArgument("id", "Orthanc identifier of the instance of interest") |
4408 | 1529 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); |
1530 | |
1531 if (GzipCompression) | |
1532 { | |
1533 call.GetDocumentation().AddAnswerType(MimeType_Gzip, "The raw frame, compressed using gzip"); | |
1534 } | |
1535 else | |
1536 { | |
1537 call.GetDocumentation().AddAnswerType(MimeType_Binary, "The raw frame"); | |
1538 } | |
1539 return; | |
1540 } | |
1541 | |
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
|
1542 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
|
1543 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1544 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
|
1545 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
|
1546 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1547 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
|
1548 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2804
diff
changeset
|
1549 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
|
1550 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1551 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
|
1552 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1553 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1554 std::string publicId = call.GetUriComponent("id", ""); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
1555 std::string raw; |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
1556 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
|
1557 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1558 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1559 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
|
1560 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
|
1561 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1562 |
2408
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1563 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
|
1564 { |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1565 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
|
1566 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
|
1567 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
|
1568 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
|
1569 } |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1570 else |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1571 { |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1572 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
|
1573 } |
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
|
1574 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1575 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1576 |
974 | 1577 static void GetResourceStatistics(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1578 { |
4418 | 1579 if (call.IsDocumentation()) |
1580 { | |
1581 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1582 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1583 call.GetDocumentation() | |
1584 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1585 .SetSummary("Get " + r + " statistics") | |
1586 .SetDescription("Get statistics about the given " + r) | |
1587 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1588 .SetAnswerField("DiskSize", RestApiCallDocumentation::Type_String, | |
1589 "Size of the " + r + " on the disk in bytes, expressed as a string for 64bit compatibility with JSON") | |
1590 .SetAnswerField("DiskSizeMB", RestApiCallDocumentation::Type_Number, | |
1591 "Size of the " + r + " on the disk, expressed in megabytes (MB)") | |
1592 .SetAnswerField("UncompressedSize", RestApiCallDocumentation::Type_String, | |
1593 "Size of the " + r + " after decompression in bytes, expressed as a string for 64bit compatibility with JSON") | |
1594 .SetAnswerField("UncompressedSizeMB", RestApiCallDocumentation::Type_Number, | |
1595 "Size of the " + r + " after decompression, expressed in megabytes (MB). " | |
1596 "This is different from `DiskSizeMB` iff `StorageCompression` is `true`.") | |
1597 .SetAnswerField("DicomDiskSize", RestApiCallDocumentation::Type_String, | |
1598 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in bytes") | |
1599 .SetAnswerField("DicomDiskSizeMB", RestApiCallDocumentation::Type_Number, | |
1600 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in megabytes (MB)") | |
1601 .SetAnswerField("DicomUncompressedSize", RestApiCallDocumentation::Type_String, | |
1602 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in bytes") | |
1603 .SetAnswerField("DicomUncompressedSizeMB", RestApiCallDocumentation::Type_Number, | |
1604 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in megabytes (MB)") | |
1605 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/statistics", true); | |
1606 | |
1607 switch (t) | |
1608 { | |
1609 // Do NOT add "break" below this point! | |
1610 case ResourceType_Patient: | |
1611 call.GetDocumentation().SetAnswerField("CountStudies", RestApiCallDocumentation::Type_Number, | |
1612 "Number of child studies within this " + r); | |
1613 | |
1614 case ResourceType_Study: | |
1615 call.GetDocumentation().SetAnswerField("CountSeries", RestApiCallDocumentation::Type_Number, | |
1616 "Number of child series within this " + r); | |
1617 | |
1618 case ResourceType_Series: | |
1619 call.GetDocumentation().SetAnswerField("CountInstances", RestApiCallDocumentation::Type_Number, | |
1620 "Number of child instances within this " + r); | |
1621 | |
1622 case ResourceType_Instance: | |
1623 default: | |
1624 break; | |
1625 } | |
1626 | |
1627 return; | |
1628 } | |
1629 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1630 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
|
1631 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1632 std::string publicId = call.GetUriComponent("id", ""); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1633 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1634 ResourceType type; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1635 uint64_t diskSize, uncompressedSize, dicomDiskSize, dicomUncompressedSize; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1636 unsigned int countStudies, countSeries, countInstances; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1637 OrthancRestApi::GetIndex(call).GetResourceStatistics( |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1638 type, diskSize, uncompressedSize, countStudies, countSeries, |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1639 countInstances, dicomDiskSize, dicomUncompressedSize, publicId); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1640 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1641 Json::Value result = Json::objectValue; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1642 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
|
1643 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
|
1644 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
|
1645 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
|
1646 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1647 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
|
1648 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
|
1649 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
|
1650 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
|
1651 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1652 switch (type) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1653 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1654 // Do NOT add "break" below this point! |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1655 case ResourceType_Patient: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1656 result["CountStudies"] = countStudies; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1657 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1658 case ResourceType_Study: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1659 result["CountSeries"] = countSeries; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1660 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1661 case ResourceType_Series: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1662 result["CountInstances"] = countInstances; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1663 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1664 case ResourceType_Instance: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1665 default: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1666 break; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1667 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1668 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1669 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1670 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1671 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1672 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1673 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1674 // Handling of metadata ----------------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1675 |
4205 | 1676 static void CheckValidResourceType(const RestApiCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1677 { |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1678 assert(!call.GetFullUri().empty()); |
4409 | 1679 const std::string resourceType = call.GetFullUri() [0]; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1680 StringToResourceType(resourceType.c_str()); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1681 } |
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 |
974 | 1684 static void ListMetadata(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1685 { |
4414 | 1686 if (call.IsDocumentation()) |
1687 { | |
1688 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1689 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1690 call.GetDocumentation() | |
1691 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1692 .SetSummary("List metadata") | |
1693 .SetDescription("Get the list of metadata that are associated with the given " + r) | |
1694 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1695 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, | |
1696 "If present, also retrieve the value of the individual metadata", false) | |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1697 .SetHttpGetArgument("numeric", RestApiCallDocumentation::Type_String, |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1698 "If present, use the numeric identifier of the metadata instead of its symbolic name", false) |
4414 | 1699 .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, " |
1700 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") | |
1701 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); | |
1702 return; | |
1703 } | |
1704 | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1705 assert(!call.GetFullUri().empty()); |
4554 | 1706 const std::string publicId = call.GetUriComponent("id", ""); |
1707 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1708 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1709 typedef std::map<MetadataType, std::string> Metadata; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1710 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1711 Metadata metadata; |
4554 | 1712 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
|
1713 |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1714 Json::Value result; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1715 |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1716 bool isNumeric = call.HasArgument("numeric"); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1717 |
5405
62bb63346185
All 'expand' GET arguments now accepts expand=true and expand=false values + /studies/../instances now supports expand=false
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
1718 if (call.HasArgument("expand") && call.GetBooleanArgument("expand", true)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1719 { |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1720 result = Json::objectValue; |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1721 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1722 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
|
1723 { |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1724 std::string key; |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1725 if (isNumeric) |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1726 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1727 key = boost::lexical_cast<std::string>(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1728 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1729 else |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1730 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1731 key = EnumerationToString(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1732 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1733 |
3187
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
1734 result[key] = it->second; |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1735 } |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1736 } |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1737 else |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1738 { |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1739 result = Json::arrayValue; |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1740 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1741 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
|
1742 { |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1743 if (isNumeric) |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1744 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1745 result.append(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1746 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1747 else |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1748 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1749 result.append(EnumerationToString(it->first)); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1750 } |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1751 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1752 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1753 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1754 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1755 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1756 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1757 |
4657 | 1758 static void SetStringContentETag(const RestApiOutput& output, |
1759 int64_t revision, | |
1760 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
|
1761 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1762 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
|
1763 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
|
1764 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
|
1765 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
|
1766 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1767 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1768 |
4657 | 1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1774 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
|
1775 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
|
1776 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
|
1777 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
|
1778 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1779 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1780 |
4657 | 1781 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
|
1782 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
|
1783 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
|
1784 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1785 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
|
1786 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
|
1787 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
|
1788 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1789 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1790 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1791 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
|
1792 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1793 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
|
1794 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
|
1795 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
|
1796 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1797 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1798 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1799 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
|
1800 std::string& md5 /* out */, |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1801 const RestApiCall& call, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1802 const std::string& header) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1803 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1804 std::string lower; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1805 Toolbox::ToLowerCase(lower, header); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1806 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1807 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
|
1808 if (found == call.GetHttpHeaders().end()) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1809 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1810 return false; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1811 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1812 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1813 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1814 std::string value = Toolbox::StripSpaces(found->second); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1815 Toolbox::RemoveSurroundingQuotes(value); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1816 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1817 try |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1818 { |
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
|
1819 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
|
1820 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
|
1821 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1822 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
|
1823 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
|
1824 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
|
1825 } |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1826 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1827 catch (boost::bad_lexical_cast&) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1828 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1829 } |
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
|
1830 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1831 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
|
1832 "\" 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
|
1833 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1834 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1835 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1836 |
974 | 1837 static void GetMetadata(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1838 { |
4414 | 1839 if (call.IsDocumentation()) |
1840 { | |
1841 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1842 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1843 call.GetDocumentation() | |
1844 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1845 .SetSummary("Get metadata") | |
1846 .SetDescription("Get the value of a metadata that is associated with the given " + r) | |
1847 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1848 .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
|
1849 .AddAnswerType(MimeType_PlainText, "Value of the metadata") |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1850 .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
|
1851 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed"); |
4414 | 1852 return; |
1853 } | |
1854 | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1855 assert(!call.GetFullUri().empty()); |
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1856 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
|
1857 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
|
1858 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1859 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1860 MetadataType metadata = StringToMetadata(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1861 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1862 std::string value; |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1863 int64_t revision; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1864 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, revision, publicId, level, metadata)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1865 { |
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
|
1866 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
|
1867 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1868 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
|
1869 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
|
1870 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
|
1871 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
|
1872 userMD5 == GetMD5(value)) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1873 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1874 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1875 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1876 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1877 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1878 call.GetOutput().AnswerBuffer(value, MimeType_PlainText); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1879 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1880 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1881 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1882 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1883 |
974 | 1884 static void DeleteMetadata(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1885 { |
4414 | 1886 if (call.IsDocumentation()) |
1887 { | |
1888 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1889 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1890 call.GetDocumentation() | |
1891 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1892 .SetSummary("Delete metadata") | |
1893 .SetDescription("Delete some metadata associated with the given DICOM " + r + | |
1894 ". This call will fail if trying to delete a system metadata (i.e. whose index is < 1024).") | |
1895 .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
|
1896 .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
|
1897 .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
|
1898 "be deleted. This header is mandatory if `CheckRevisions` option is `true`."); |
4414 | 1899 return; |
1900 } | |
1901 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1902 CheckValidResourceType(call); |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1903 const std::string publicId = call.GetUriComponent("id", ""); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1904 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1905 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1906 MetadataType metadata = StringToMetadata(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1907 |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
1908 if (IsUserMetadata(metadata) || // It is forbidden to delete internal metadata... |
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
1909 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1910 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1911 bool found; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1912 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
|
1913 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
|
1914 if (GetRevisionHeader(revision, md5, call, "if-match")) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1915 { |
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
|
1916 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
|
1917 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1918 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1919 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1920 OrthancConfiguration::ReaderLock lock; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1921 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1922 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1923 throw OrthancException(ErrorCode_Revision, |
4661
b1d87d41874e
typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4657
diff
changeset
|
1924 "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
|
1925 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1926 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1927 { |
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
|
1928 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
|
1929 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1930 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1931 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1932 if (found) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1933 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1934 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1935 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1936 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1937 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1938 throw OrthancException(ErrorCode_UnknownResource); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1939 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1940 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
1941 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
1942 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
1943 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
|
1944 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1945 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1946 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1947 |
974 | 1948 static void SetMetadata(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1949 { |
4414 | 1950 if (call.IsDocumentation()) |
1951 { | |
1952 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1953 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1954 call.GetDocumentation() | |
1955 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1956 .SetSummary("Set metadata") | |
1957 .SetDescription("Set the value of some metadata in the given DICOM " + r + | |
1958 ". This call will fail if trying to modify a system metadata (i.e. whose index is < 1024).") | |
1959 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1960 .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
|
1961 .AddRequestType(MimeType_PlainText, "String value of the metadata") |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1962 .SetHttpHeader("If-Match", "Revision of the metadata, if this is not the first time this metadata is set."); |
4414 | 1963 return; |
1964 } | |
1965 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1966 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1967 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1968 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1969 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1970 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
|
1971 |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
1972 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
|
1973 call.BodyToString(value); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1974 |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
1975 if (IsUserMetadata(metadata) || // It is forbidden to modify internal metadata... |
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
1976 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1977 { |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1978 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
|
1979 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
|
1980 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
|
1981 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1982 if (!hasOldRevision) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1983 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1984 OrthancConfiguration::ReaderLock lock; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1985 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1986 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1987 // "StatelessDatabaseOperations::SetMetadata()" will ignore |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1988 // 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
|
1989 // inexistent as expected |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1990 hasOldRevision = true; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1991 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
|
1992 oldMD5.clear(); // dummy value |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1993 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1994 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1995 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1996 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
|
1997 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
|
1998 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
|
1999 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2000 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
|
2001 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2002 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2003 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2004 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2005 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
|
2006 } |
751
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 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2010 |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2011 // Handling of labels ------------------------------------------------------- |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2012 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2013 static void ListLabels(RestApiGetCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2014 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2015 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2016 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2017 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2018 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2019 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2020 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
5275
8686476e9d12
fix inclusion of winsock.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5274
diff
changeset
|
2021 .SetSummary("List labels") |
8686476e9d12
fix inclusion of winsock.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5274
diff
changeset
|
2022 .SetDescription("Get the labels that are associated with the given " + r + " (new in Orthanc 1.12.0)") |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2023 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2024 .AddAnswerType(MimeType_Json, "JSON array containing the names of the labels") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2025 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/labels", true); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2026 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2027 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2028 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2029 assert(!call.GetFullUri().empty()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2030 const std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2031 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2032 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2033 std::set<std::string> labels; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2034 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2035 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2036 Json::Value result = Json::arrayValue; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2037 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2038 for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2039 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2040 result.append(*it); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2041 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2042 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2043 call.GetOutput().AnswerJson(result); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2044 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2045 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2046 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2047 static void GetLabel(RestApiGetCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2048 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2049 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2050 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2051 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2052 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2053 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2054 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2055 .SetSummary("Test label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2056 .SetDescription("Test whether the " + r + " is associated with the given label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2057 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2058 .SetUriArgument("label", "The label of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2059 .AddAnswerType(MimeType_PlainText, "Empty string is returned in the case of presence, error 404 in the case of absence"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2060 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2061 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2062 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2063 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2064 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2065 assert(!call.GetFullUri().empty()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2066 const std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2067 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2068 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2069 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2070 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2071 std::set<std::string> labels; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2072 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2073 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2074 if (labels.find(label) != labels.end()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2075 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2076 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2077 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2078 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2079 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2080 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2081 static void AddLabel(RestApiPutCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2082 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2083 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2084 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2085 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2086 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2087 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2088 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2089 .SetSummary("Add label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2090 .SetDescription("Associate a label with a " + r) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2091 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2092 .SetUriArgument("label", "The label to be added"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2093 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2094 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2095 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2096 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2097 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2098 std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2099 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2100 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2101 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2102 OrthancRestApi::GetIndex(call).ModifyLabel(publicId, level, label, StatelessDatabaseOperations::LabelOperation_Add); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2103 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2104 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2105 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2106 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2107 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2108 static void RemoveLabel(RestApiDeleteCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2109 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2110 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2111 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2112 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2113 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2114 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2115 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2116 .SetSummary("Remove label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2117 .SetDescription("Remove a label associated with a " + r) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2118 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2119 .SetUriArgument("label", "The label to be removed"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2120 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2121 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2122 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2123 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2124 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2125 std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2126 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2127 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2128 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2129 OrthancRestApi::GetIndex(call).ModifyLabel(publicId, level, label, StatelessDatabaseOperations::LabelOperation_Remove); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2130 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2131 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2132 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2133 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2134 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2135 // Handling of attached files ----------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2136 |
974 | 2137 static void ListAttachments(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2138 { |
4409 | 2139 if (call.IsDocumentation()) |
2140 { | |
2141 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2142 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2143 call.GetDocumentation() | |
2144 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2145 .SetSummary("List attachments") | |
2146 .SetDescription("Get the list of attachments that are associated with the given " + r) | |
2147 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2148 .SetHttpGetArgument("full", RestApiCallDocumentation::Type_String, |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2149 "If present, retrieve the attachments list and their numerical ids", false) |
4409 | 2150 .AddAnswerType(MimeType_Json, "JSON array containing the names of the attachments") |
2151 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/attachments", true); | |
2152 return; | |
2153 } | |
2154 | |
2155 const std::string resourceType = call.GetFullUri() [0]; | |
2156 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
|
2157 std::set<FileContentType> attachments; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2158 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str())); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2159 |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2160 Json::Value result; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2161 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2162 if (call.HasArgument("full")) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2163 { |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2164 result = Json::objectValue; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2165 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2166 for (std::set<FileContentType>::const_iterator |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2167 it = attachments.begin(); it != attachments.end(); ++it) |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2168 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2169 std::string key = EnumerationToString(*it); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2170 result[key] = static_cast<uint16_t>(*it); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2171 } |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2172 } |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2173 else |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2174 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2175 result = Json::arrayValue; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2176 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2177 for (std::set<FileContentType>::const_iterator |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2178 it = attachments.begin(); it != attachments.end(); ++it) |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2179 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2180 result.append(EnumerationToString(*it)); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2181 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2182 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2183 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2184 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2185 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2186 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2187 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2188 static void AddAttachmentDocumentation(RestApiGetCall& call, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2189 const std::string& resourceType) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2190 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2191 call.GetDocumentation() |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2192 .SetUriArgument("id", "Orthanc identifier of the " + resourceType + " of interest") |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2193 .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
|
2194 .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
|
2195 .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
|
2196 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2197 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2198 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2199 static bool GetAttachmentInfo(FileInfo& info, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2200 RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2201 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2202 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2203 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2204 const std::string publicId = call.GetUriComponent("id", ""); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2205 const std::string name = call.GetUriComponent("name", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2206 FileContentType contentType = StringToContentType(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2207 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2208 int64_t revision; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2209 if (OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2210 { |
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
|
2211 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
|
2212 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2213 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
|
2214 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
|
2215 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
|
2216 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
|
2217 info.GetUncompressedMD5() == userMD5) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2218 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2219 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2220 return false; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2221 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2222 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2223 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2224 return true; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2225 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2226 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2227 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2228 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2229 throw OrthancException(ErrorCode_UnknownResource); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2230 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2231 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2232 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2233 |
974 | 2234 static void GetAttachmentOperations(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2235 { |
4409 | 2236 if (call.IsDocumentation()) |
2237 { | |
2238 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2239 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
|
2240 AddAttachmentDocumentation(call, r); |
4409 | 2241 call.GetDocumentation() |
2242 .SetTag("Other") | |
4414 | 2243 .SetSummary("List operations on attachments") |
2244 .SetDescription("Get the list of the operations that are available for attachments associated with the given " + r) | |
4409 | 2245 .AddAnswerType(MimeType_Json, "List of the available operations") |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
2246 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/6582b1c0-292ad5ab-ba0f088f-f7a1766f-9a29a54f/attachments/dicom", true); |
4409 | 2247 return; |
2248 } | |
2249 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2250 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2251 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2252 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2253 Json::Value operations = Json::arrayValue; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2254 |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2255 operations.append("compress"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2256 operations.append("compressed-data"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2257 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2258 if (info.GetCompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2259 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2260 operations.append("compressed-md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2261 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2262 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2263 operations.append("compressed-size"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2264 operations.append("data"); |
4883
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2265 operations.append("info"); |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2266 operations.append("is-compressed"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2267 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2268 if (info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2269 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2270 operations.append("md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2271 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2272 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2273 operations.append("size"); |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2274 operations.append("uncompress"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2275 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2276 if (info.GetCompressedMD5() != "" && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2277 info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2278 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2279 operations.append("verify-md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2280 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2281 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2282 call.GetOutput().AnswerJson(operations); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2283 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2284 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2285 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2286 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2287 template <int uncompress> |
974 | 2288 static void GetAttachmentData(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2289 { |
4409 | 2290 if (call.IsDocumentation()) |
2291 { | |
2292 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2293 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2294 call.GetDocumentation() | |
2295 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2296 .SetSummary("Get attachment" + std::string(uncompress ? "" : " (no decompression)")) | |
2297 .SetDescription("Get the (binary) content of one attachment associated with the given " + r + | |
4418 | 2298 std::string(uncompress ? "" : ". The attachment will not be decompressed if `StorageCompression` is `true`.")) |
4409 | 2299 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
4414 | 2300 .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
|
2301 .AddAnswerType(MimeType_Binary, "The attachment") |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2302 .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
|
2303 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed"); |
4409 | 2304 return; |
2305 } | |
2306 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2307 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2308 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2309 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2310 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2311 std::string publicId = call.GetUriComponent("id", ""); |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2312 FileContentType type = StringToContentType(call.GetUriComponent("name", "")); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2313 |
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
|
2314 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
|
2315 if (GetAttachmentInfo(info, call)) |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2316 { |
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
|
2317 // 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
|
2318 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2319 if (uncompress) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2320 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2321 context.AnswerAttachment(call.GetOutput(), publicId, type); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2322 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2323 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2324 { |
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
|
2325 // 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
|
2326 std::string content; |
5427 | 2327 std::string attachmentId; |
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
|
2328 int64_t revision; |
5427 | 2329 context.ReadAttachment(content, revision, attachmentId, publicId, type, false, true /* skipCache when you absolutely need the compressed data */); |
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
|
2330 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2331 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
|
2332 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
|
2333 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
|
2334 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
|
2335 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
|
2336 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2337 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
|
2338 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2339 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
|
2340 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2341 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
|
2342 } |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2343 } |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2344 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2345 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2346 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2347 |
974 | 2348 static void GetAttachmentSize(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2349 { |
4409 | 2350 if (call.IsDocumentation()) |
2351 { | |
2352 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2353 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
|
2354 AddAttachmentDocumentation(call, r); |
4409 | 2355 call.GetDocumentation() |
2356 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2357 .SetSummary("Get size of attachment") | |
2358 .SetDescription("Get the size of one attachment associated with the given " + r) | |
2359 .AddAnswerType(MimeType_PlainText, "The size of the attachment"); | |
2360 return; | |
2361 } | |
2362 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2363 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2364 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2365 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2366 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
|
2367 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2368 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2369 |
4883
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2370 static void GetAttachmentInfo(RestApiGetCall& call) |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2371 { |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2372 if (call.IsDocumentation()) |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2373 { |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2374 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2375 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2376 AddAttachmentDocumentation(call, r); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2377 call.GetDocumentation() |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2378 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2379 .SetSummary("Get info about the attachment") |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2380 .SetDescription("Get all the information about the attachment associated with the given " + r) |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2381 .AddAnswerType(MimeType_Json, "JSON object containing the information about the attachment") |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
2382 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/attachments/dicom/info", true); |
4883
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2383 return; |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2384 } |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2385 |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2386 FileInfo info; |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2387 if (GetAttachmentInfo(info, call)) |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2388 { |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2389 Json::Value result = Json::objectValue; |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2390 result["Uuid"] = info.GetUuid(); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2391 result["ContentType"] = info.GetContentType(); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2392 result["UncompressedSize"] = Json::Value::UInt64(info.GetUncompressedSize()); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2393 result["CompressedSize"] = Json::Value::UInt64(info.GetCompressedSize()); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2394 result["UncompressedMD5"] = info.GetUncompressedMD5(); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2395 result["CompressedMD5"] = info.GetCompressedMD5(); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2396 |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2397 call.GetOutput().AnswerJson(result); |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2398 } |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2399 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2400 |
974 | 2401 static void GetAttachmentCompressedSize(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2402 { |
4409 | 2403 if (call.IsDocumentation()) |
2404 { | |
2405 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2406 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
|
2407 AddAttachmentDocumentation(call, r); |
4409 | 2408 call.GetDocumentation() |
2409 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
4410 | 2410 .SetSummary("Get size of attachment on disk") |
4409 | 2411 .SetDescription("Get the size of one attachment associated with the given " + r + ", as stored on the disk. " |
4413 | 2412 "This is different from `.../size` iff `EnableStorage` is `true`.") |
4410 | 2413 .AddAnswerType(MimeType_PlainText, "The size of the attachment, as stored on the disk"); |
4409 | 2414 return; |
2415 } | |
2416 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2417 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2418 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2419 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2420 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
|
2421 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2422 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2423 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2424 |
974 | 2425 static void GetAttachmentMD5(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2426 { |
4410 | 2427 if (call.IsDocumentation()) |
2428 { | |
2429 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2430 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
|
2431 AddAttachmentDocumentation(call, r); |
4410 | 2432 call.GetDocumentation() |
2433 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2434 .SetSummary("Get MD5 of attachment") | |
2435 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r) | |
2436 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment"); | |
2437 return; | |
2438 } | |
2439 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2440 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2441 if (GetAttachmentInfo(info, call) && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2442 info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2443 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2444 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
|
2445 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2446 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2447 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2448 |
974 | 2449 static void GetAttachmentCompressedMD5(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2450 { |
4410 | 2451 if (call.IsDocumentation()) |
2452 { | |
2453 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2454 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
|
2455 AddAttachmentDocumentation(call, r); |
4410 | 2456 call.GetDocumentation() |
2457 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2458 .SetSummary("Get MD5 of attachment on disk") | |
2459 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r + ", as stored on the disk. " | |
4413 | 2460 "This is different from `.../md5` iff `EnableStorage` is `true`.") |
4410 | 2461 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment, as stored on the disk"); |
2462 return; | |
2463 } | |
2464 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2465 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2466 if (GetAttachmentInfo(info, call) && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2467 info.GetCompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2468 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2469 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
|
2470 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2471 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2472 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2473 |
974 | 2474 static void VerifyAttachment(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2475 { |
4410 | 2476 if (call.IsDocumentation()) |
2477 { | |
2478 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2479 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2480 call.GetDocumentation() | |
2481 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2482 .SetSummary("Verify attachment") | |
2483 .SetDescription("Verify that the attachment is not corrupted, by validating its MD5 hash") | |
2484 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4414 | 2485 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)") |
4410 | 2486 .AddAnswerType(MimeType_Json, "On success, a valid JSON object is returned"); |
2487 return; | |
2488 } | |
2489 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2490 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2491 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2492 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2493 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2494 std::string name = call.GetUriComponent("name", ""); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2495 FileContentType contentType = StringToContentType(name); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2496 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2497 FileInfo info; |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2498 int64_t revision; // Ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2499 if (!OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType) || |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2500 info.GetCompressedMD5() == "" || |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2501 info.GetUncompressedMD5() == "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2502 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2503 // Inexistent resource, or no MD5 available |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2504 return; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2505 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2506 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2507 bool ok = false; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2508 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2509 // 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
|
2510 std::string data; |
5427 | 2511 std::string attachmentId; |
2512 | |
2513 context.ReadAttachment(data, revision, attachmentId, publicId, StringToContentType(name), false, true /* skipCache when you absolutely need the compressed data */); | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2514 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2515 std::string actualMD5; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2516 Toolbox::ComputeMD5(actualMD5, data); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2517 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2518 if (actualMD5 == info.GetCompressedMD5()) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2519 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2520 // The compressed data is OK. If a compression algorithm was |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2521 // applied to it, now check the MD5 of the uncompressed data. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2522 if (info.GetCompressionType() == CompressionType_None) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2523 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2524 ok = true; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2525 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2526 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2527 { |
5427 | 2528 context.ReadAttachment(data, revision, attachmentId, publicId, StringToContentType(name), true, true /* skipCache when you absolutely need the compressed data */); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2529 Toolbox::ComputeMD5(actualMD5, data); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2530 ok = (actualMD5 == info.GetUncompressedMD5()); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2531 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2532 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2533 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2534 if (ok) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2535 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
2536 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
|
2537 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2538 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2539 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2540 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
2541 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
|
2542 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2543 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2544 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2545 |
974 | 2546 static void UploadAttachment(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2547 { |
4414 | 2548 if (call.IsDocumentation()) |
2549 { | |
2550 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2551 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2552 call.GetDocumentation() | |
2553 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2554 .SetSummary("Set attachment") | |
2555 .SetDescription("Attach a file to the given DICOM " + r + | |
2556 ". This call will fail if trying to modify a system attachment (i.e. whose index is < 1024).") | |
2557 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2558 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)") | |
2559 .AddRequestType(MimeType_Binary, "Binary data containing the attachment") | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2560 .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
|
2561 .SetHttpHeader("If-Match", "Revision of the attachment, if this is not the first time this attachment is set."); |
4414 | 2562 return; |
2563 } | |
2564 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2565 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2566 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2567 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2568 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2569 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2570 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2571 FileContentType contentType = StringToContentType(name); |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2572 if (IsUserContentType(contentType) || // It is forbidden to modify internal attachments... |
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2573 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2574 { |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2575 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
|
2576 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
|
2577 bool hasOldRevision = GetRevisionHeader(oldRevision, oldMD5, call, "if-match"); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2578 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2579 if (!hasOldRevision) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2580 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2581 OrthancConfiguration::ReaderLock lock; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2582 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2583 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2584 // "StatelessDatabaseOperations::AddAttachment()" will ignore |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2585 // the actual value of "oldRevision" if the metadata is |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2586 // inexistent as expected |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2587 hasOldRevision = true; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2588 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
|
2589 oldMD5.clear(); // dummy value |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2590 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2591 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2592 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2593 int64_t newRevision; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2594 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
|
2595 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
|
2596 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2597 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
|
2598 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2599 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2600 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2601 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2602 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
|
2603 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2604 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2605 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2606 |
974 | 2607 static void DeleteAttachment(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2608 { |
4413 | 2609 if (call.IsDocumentation()) |
2610 { | |
2611 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2612 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2613 call.GetDocumentation() | |
2614 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2615 .SetSummary("Delete attachment") | |
4414 | 2616 .SetDescription("Delete an attachment associated with the given DICOM " + r + |
2617 ". This call will fail if trying to delete a system attachment (i.e. whose index is < 1024).") | |
4413 | 2618 .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
|
2619 .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
|
2620 .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
|
2621 "be deleted. This header is mandatory if `CheckRevisions` option is `true`."); |
4413 | 2622 return; |
2623 } | |
2624 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2625 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2626 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2627 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2628 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2629 FileContentType contentType = StringToContentType(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2630 |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2631 bool allowed; |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2632 if (IsUserContentType(contentType) || // It is forbidden to delete internal attachments... |
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2633 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2634 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2635 allowed = true; |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2636 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2637 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2638 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2639 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2640 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2641 if (lock.GetConfiguration().GetBooleanParameter("StoreDicom", true) && |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2642 contentType == FileContentType_DicomAsJson) |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2643 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2644 allowed = true; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2645 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2646 else |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2647 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2648 // 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
|
2649 // 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
|
2650 // 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
|
2651 allowed = false; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2652 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2653 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2654 |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2655 if (allowed) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2656 { |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2657 bool found; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2658 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
|
2659 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
|
2660 if (GetRevisionHeader(revision, md5, call, "if-match")) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2661 { |
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
|
2662 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
|
2663 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2664 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2665 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2666 OrthancConfiguration::ReaderLock lock; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2667 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2668 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2669 throw OrthancException(ErrorCode_Revision, |
4661
b1d87d41874e
typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4657
diff
changeset
|
2670 "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
|
2671 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2672 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2673 { |
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
|
2674 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
|
2675 false, -1 /* dummy value */, "" /* dummy value */); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2676 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2677 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2678 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2679 if (found) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2680 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2681 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2682 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2683 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2684 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2685 throw OrthancException(ErrorCode_UnknownResource); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2686 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2687 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2688 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2689 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2690 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
|
2691 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2692 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2693 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2694 |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2695 template <enum CompressionType compression> |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2696 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
|
2697 { |
4413 | 2698 if (call.IsDocumentation()) |
2699 { | |
2700 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2701 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2702 call.GetDocumentation() | |
2703 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2704 .SetSummary(compression == CompressionType_None ? "Uncompress attachment" : "Compress attachment") | |
2705 .SetDescription("Change the compression scheme that is used to store an attachment.") | |
2706 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4414 | 2707 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)"); |
4413 | 2708 return; |
2709 } | |
2710 | |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2711 CheckValidResourceType(call); |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2712 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2713 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
|
2714 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
|
2715 FileContentType contentType = StringToContentType(name); |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2716 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2717 OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2718 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
|
2719 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2720 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2721 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2722 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
|
2723 { |
4413 | 2724 if (call.IsDocumentation()) |
2725 { | |
2726 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2727 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
|
2728 AddAttachmentDocumentation(call, r); |
4413 | 2729 call.GetDocumentation() |
2730 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2731 .SetSummary("Is attachment compressed?") | |
2732 .SetDescription("Test whether the attachment has been stored as a compressed file on the disk.") | |
2733 .AddAnswerType(MimeType_PlainText, "`0` if the attachment was stored uncompressed, `1` if it was compressed"); | |
2734 return; | |
2735 } | |
2736 | |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2737 FileInfo info; |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2738 if (GetAttachmentInfo(info, call)) |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2739 { |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2740 std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1"; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2741 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
|
2742 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2743 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2744 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2745 |
782 | 2746 // Raw access to the DICOM tags of an instance ------------------------------ |
2747 | |
974 | 2748 static void GetRawContent(RestApiGetCall& call) |
782 | 2749 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2750 if (call.IsDocumentation()) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2751 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2752 call.GetDocumentation() |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2753 .SetTag("Instances") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2754 .SetSummary("Get raw tag") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2755 .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
|
2756 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
5393
c5c00bee291a
in openapi generator: renamed '...' into 'path' since '...' is an invalid name
Alain Mazy <am@osimis.io>
parents:
5392
diff
changeset
|
2757 .SetUriArgument("path", "Path to the DICOM tag. This is the interleaving of one DICOM tag, possibly followed " |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2758 "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
|
2759 .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
|
2760 "(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
|
2761 "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
|
2762 return; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2763 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2764 |
782 | 2765 std::string id = call.GetUriComponent("id", ""); |
2766 | |
2767 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); | |
2768 | |
2769 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); | |
2770 } | |
2771 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2772 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2773 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2774 static bool ExtractSharedTags(Json::Value& shared, |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2775 ServerContext& context, |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2776 const std::string& publicId) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2777 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2778 // 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
|
2779 typedef std::list<std::string> Instances; |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2780 Instances instances; |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2781 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2782 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2783 // Loop over the instances |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2784 bool isFirst = true; |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2785 shared = Json::objectValue; |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2786 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2787 for (Instances::const_iterator it = instances.begin(); |
1303 | 2788 it != instances.end(); ++it) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2789 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2790 // 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
|
2791 Json::Value tags; |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2792 |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2793 try |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2794 { |
2124 | 2795 context.ReadDicomAsJson(tags, *it); |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2796 } |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2797 catch (OrthancException&) |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2798 { |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2799 // Race condition: This instance has been removed since |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2800 // (*). Ignore this instance. |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2801 continue; |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2802 } |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2803 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2804 if (tags.type() != Json::objectValue) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2805 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2806 return false; // Error |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2807 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2808 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2809 // 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
|
2810 Json::Value::Members members = tags.getMemberNames(); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2811 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
|
2812 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2813 const Json::Value& tag = tags[members[i]]; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2814 if (tag.type() != Json::objectValue || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2815 tag["Type"].type() != Json::stringValue || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2816 tag["Type"].asString() != "String") |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2817 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2818 tags.removeMember(members[i]); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2819 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2820 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2821 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2822 if (isFirst) |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2823 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2824 // 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
|
2825 shared = tags; |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2826 isFirst = false; |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2827 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2828 else |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2829 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2830 // 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
|
2831 // 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
|
2832 // value in the current instance, remove it. |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2833 members = shared.getMemberNames(); |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2834 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
|
2835 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2836 if (!tags.isMember(members[i]) || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2837 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
|
2838 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2839 shared.removeMember(members[i]); |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2840 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2841 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2842 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2843 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2844 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2845 return true; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2846 } |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2847 |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2848 |
974 | 2849 static void GetSharedTags(RestApiGetCall& call) |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2850 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2851 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2852 { |
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
|
2853 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
|
2854 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2855 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
|
2856 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
|
2857 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2858 .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
|
2859 .SetSummary("Get shared tags") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2860 .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
|
2861 "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
|
2862 .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
|
2863 .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
|
2864 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/shared-tags", 5); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2865 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2866 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2867 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2868 ServerContext& context = OrthancRestApi::GetContext(call); |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2869 std::string publicId = call.GetUriComponent("id", ""); |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2870 |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2871 Json::Value sharedTags; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2872 if (ExtractSharedTags(sharedTags, context, publicId)) |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2873 { |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2874 // 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
|
2875 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
|
2876 } |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2877 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2878 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2879 |
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
|
2880 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
|
2881 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
|
2882 static void GetModule(RestApiGetCall& call) |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2883 { |
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
|
2884 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
|
2885 { |
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
|
2886 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
|
2887 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
|
2888 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
|
2889 { |
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
|
2890 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
|
2891 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
|
2892 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
|
2893 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
|
2894 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
|
2895 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
|
2896 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
|
2897 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
|
2898 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
|
2899 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
|
2900 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
|
2901 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
|
2902 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
|
2903 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
|
2904 } |
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
|
2905 |
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
|
2906 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
|
2907 |
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
|
2908 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
|
2909 .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
|
2910 .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
|
2911 .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
|
2912 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
2913 .SetHttpGetArgument(IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings, |
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
|
2914 "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
|
2915 .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
|
2916 .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
|
2917 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
|
2918 } |
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
|
2919 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2920 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2921 (resourceType == ResourceType_Study && module == DicomModule_Patient) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2922 (resourceType == ResourceType_Study && module == DicomModule_Study) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2923 (resourceType == ResourceType_Series && module == DicomModule_Series) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2924 (resourceType == ResourceType_Instance && module == DicomModule_Instance) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2925 (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
|
2926 { |
1701dcb6f554
Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
2927 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
|
2928 } |
1701dcb6f554
Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
2929 |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2930 ServerContext& context = OrthancRestApi::GetContext(call); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2931 std::string publicId = call.GetUriComponent("id", ""); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2932 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
2933 std::set<DicomTag> ignoreTagLength; |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
2934 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
2935 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2936 typedef std::set<DicomTag> ModuleTags; |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2937 ModuleTags moduleTags; |
1368 | 2938 DicomTag::AddTagsForModule(moduleTags, module); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2939 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2940 Json::Value tags; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2941 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2942 if (resourceType != ResourceType_Instance) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2943 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2944 // Retrieve all the instances of this patient/study/series |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2945 typedef std::list<std::string> Instances; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2946 Instances instances; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2947 context.GetIndex().GetChildInstances(instances, publicId); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2948 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2949 if (instances.empty()) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2950 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2951 return; // Error: No instance (should never happen) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2952 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2953 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2954 // Select one child instance |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2955 publicId = instances.front(); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2956 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2957 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
2958 context.ReadDicomAsJson(tags, publicId, ignoreTagLength); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2959 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2960 // 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
|
2961 Json::Value result = Json::objectValue; |
1303 | 2962 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
|
2963 { |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2964 std::string s = tag->Format(); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2965 if (tags.isMember(s)) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2966 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2967 result[s] = tags[s]; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2968 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2969 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2970 |
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
|
2971 AnswerDicomAsJson(call, result, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2972 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2973 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2974 |
1722 | 2975 namespace |
2976 { | |
2977 typedef std::list< std::pair<ResourceType, std::string> > LookupResults; | |
2978 } | |
2979 | |
2980 | |
2981 static void AccumulateLookupResults(LookupResults& result, | |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2982 ServerIndex& index, |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2983 const DicomTag& tag, |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
2984 const std::string& value, |
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
2985 ResourceType level) |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2986 { |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
2987 std::vector<std::string> tmp; |
1728
4941494b5dd8
rename LookupIdentifier as LookupIdentifierExact
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1727
diff
changeset
|
2988 index.LookupIdentifierExact(tmp, level, tag, value); |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
2989 |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
2990 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
|
2991 { |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
2992 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
|
2993 } |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2994 } |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2995 |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2996 |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
2997 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
|
2998 { |
4422 | 2999 if (call.IsDocumentation()) |
3000 { | |
3001 call.GetDocumentation() | |
3002 .SetTag("System") | |
3003 .SetSummary("Look for DICOM identifiers") | |
3004 .SetDescription("This URI can be used to convert one DICOM identifier to a list of matching Orthanc resources") | |
3005 .AddRequestType(MimeType_PlainText, "The DICOM identifier of interest (i.e. the value of `PatientID`, " | |
3006 "`StudyInstanceUID`, `SeriesInstanceUID`, or `SOPInstanceUID`)") | |
3007 .AddAnswerType(MimeType_Json, "JSON array containing a list of matching Orthanc resources, each item in the " | |
3008 "list corresponding to a JSON object with the fields `Type`, `ID` and `Path` identifying one " | |
3009 "DICOM resource that is stored by Orthanc"); | |
3010 return; | |
3011 } | |
3012 | |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
3013 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
|
3014 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
|
3015 |
1722 | 3016 LookupResults resources; |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3017 ServerIndex& index = OrthancRestApi::GetIndex(call); |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
3018 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
|
3019 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
|
3020 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
|
3021 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
|
3022 |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3023 Json::Value result = Json::arrayValue; |
1722 | 3024 for (LookupResults::const_iterator |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3025 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
|
3026 { |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3027 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
|
3028 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
|
3029 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3030 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
|
3031 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
|
3032 item["ID"] = id; |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3033 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
|
3034 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3035 result.append(item); |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3036 } |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3037 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3038 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
|
3039 } |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3040 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3041 |
5837 | 3042 enum FindType |
3043 { | |
3044 FindType_Find, | |
3045 FindType_Count | |
3046 }; | |
3047 | |
3048 template <enum FindType requestType> | |
1354 | 3049 static void Find(RestApiPostCall& call) |
3050 { | |
2998 | 3051 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive"; |
3052 static const char* const KEY_EXPAND = "Expand"; | |
3053 static const char* const KEY_LEVEL = "Level"; | |
3054 static const char* const KEY_LIMIT = "Limit"; | |
3055 static const char* const KEY_QUERY = "Query"; | |
4935
acd3f72e2a21
split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
3056 static const char* const KEY_REQUESTED_TAGS = "RequestedTags"; |
2998 | 3057 static const char* const KEY_SINCE = "Since"; |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3058 static const char* const KEY_LABELS = "Labels"; // New in Orthanc 1.12.0 |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3059 static const char* const KEY_LABELS_CONSTRAINT = "LabelsConstraint"; // New in Orthanc 1.12.0 |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3060 static const char* const KEY_ORDER_BY = "OrderBy"; // New in Orthanc 1.12.5 |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3061 static const char* const KEY_ORDER_BY_KEY = "Key"; // New in Orthanc 1.12.5 |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3062 static const char* const KEY_ORDER_BY_TYPE = "Type"; // New in Orthanc 1.12.5 |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3063 static const char* const KEY_ORDER_BY_DIRECTION = "Direction"; // New in Orthanc 1.12.5 |
5826
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3064 static const char* const KEY_PARENT_PATIENT = "ParentPatient"; // New in Orthanc 1.12.5 |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3065 static const char* const KEY_PARENT_STUDY = "ParentStudy"; // New in Orthanc 1.12.5 |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3066 static const char* const KEY_PARENT_SERIES = "ParentSeries"; // New in Orthanc 1.12.5 |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3067 static const char* const KEY_METADATA_QUERY = "MetadataQuery"; // New in Orthanc 1.12.5 |
5829 | 3068 static const char* const KEY_RESPONSE_CONTENT = "ResponseContent"; // New in Orthanc 1.12.5 |
2998 | 3069 |
4421 | 3070 if (call.IsDocumentation()) |
3071 { | |
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
|
3072 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
|
3073 |
5837 | 3074 RestApiCallDocumentation& doc = call.GetDocumentation(); |
3075 | |
3076 doc.SetTag("System") | |
4421 | 3077 .SetRequestField(KEY_CASE_SENSITIVE, RestApiCallDocumentation::Type_Boolean, |
3078 "Enable case-sensitive search for PN value representations (defaults to configuration option `CaseSensitivePN`)", false) | |
3079 .SetRequestField(KEY_LEVEL, RestApiCallDocumentation::Type_String, | |
3080 "Level of the query (`Patient`, `Study`, `Series` or `Instance`)", true) | |
3081 .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject, | |
3082 "Associative array containing the filter on the values of the DICOM tags", true) | |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3083 .SetRequestField(KEY_LABELS, RestApiCallDocumentation::Type_JsonListOfStrings, |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3084 "List of strings specifying which labels to look for in the resources (new in Orthanc 1.12.0)", true) |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3085 .SetRequestField(KEY_LABELS_CONSTRAINT, RestApiCallDocumentation::Type_String, |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3086 "Constraint on the labels, can be `All`, `Any`, or `None` (defaults to `All`, new in Orthanc 1.12.0)", true) |
5826
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3087 .SetRequestField(KEY_PARENT_PATIENT, RestApiCallDocumentation::Type_String, |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3088 "Limit the reported resources to descendants of this patient (new in Orthanc 1.12.5)", true) |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3089 .SetRequestField(KEY_PARENT_STUDY, RestApiCallDocumentation::Type_String, |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3090 "Limit the reported resources to descendants of this study (new in Orthanc 1.12.5)", true) |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3091 .SetRequestField(KEY_PARENT_SERIES, RestApiCallDocumentation::Type_String, |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3092 "Limit the reported resources to descendants of this series (new in Orthanc 1.12.5)", true) |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3093 .SetRequestField(KEY_METADATA_QUERY, RestApiCallDocumentation::Type_JsonObject, |
5837 | 3094 "Associative array containing the filter on the values of the metadata (new in Orthanc 1.12.5)", true); |
3095 | |
3096 switch (requestType) | |
3097 { | |
3098 case FindType_Find: | |
3099 doc.SetSummary("Look for local resources") | |
3100 .SetDescription("This URI can be used to perform a search on the content of the local Orthanc server, " | |
3101 "in a way that is similar to querying remote DICOM modalities using C-FIND SCU: " | |
3102 "https://orthanc.uclouvain.be/book/users/rest.html#performing-finds-within-orthanc") | |
3103 .SetRequestField(KEY_EXPAND, RestApiCallDocumentation::Type_Boolean, | |
3104 "Also retrieve the content of the matching resources, not only their Orthanc identifiers", false) | |
3105 .SetRequestField(KEY_LIMIT, RestApiCallDocumentation::Type_Number, | |
3106 "Limit the number of reported resources", false) | |
3107 .SetRequestField(KEY_SINCE, RestApiCallDocumentation::Type_Number, | |
3108 "Show only the resources since the provided index (in conjunction with `Limit`)", false) | |
3109 .SetRequestField(KEY_REQUESTED_TAGS, RestApiCallDocumentation::Type_JsonListOfStrings, | |
3110 "A list of DICOM tags to include in the response (applicable only if \"Expand\" is set to true). " | |
3111 "The tags requested tags are returned in the 'RequestedTags' field in the response. " | |
3112 "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " | |
3113 "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " | |
3114 "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false) | |
3115 .SetRequestField(KEY_ORDER_BY, RestApiCallDocumentation::Type_JsonListOfObjects, | |
3116 "Array of associative arrays containing the requested ordering (new in Orthanc 1.12.5)", true) | |
3117 .SetRequestField(KEY_RESPONSE_CONTENT, RestApiCallDocumentation::Type_JsonListOfStrings, | |
3118 "Defines the content of response for each returned resource. Allowed values are `MainDicomTags`, " | |
3119 "`Metadata`, `Children`, `Parent`, `Labels`, `Status`, `IsStable`, `Attachments`. " | |
3120 "(new in Orthanc 1.12.5)", true) | |
3121 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " | |
3122 "about the reported resources (if `Expand` argument is `true`)"); | |
3123 break; | |
3124 case FindType_Count: | |
3125 doc.SetSummary("Count local resources") | |
3126 .SetDescription("This URI can be used to count the resources that are matching criterias on the content of the local Orthanc server, " | |
3127 "in a way that is similar to tools/find") | |
3128 .AddAnswerType(MimeType_Json, "A JSON object with the `Count` of matching resources"); | |
3129 break; | |
3130 default: | |
3131 throw OrthancException(ErrorCode_NotImplemented); | |
3132 } | |
3133 | |
4421 | 3134 return; |
3135 } | |
3136 | |
1358 | 3137 ServerContext& context = OrthancRestApi::GetContext(call); |
1354 | 3138 |
3139 Json::Value request; | |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3140 if (!call.ParseJsonRequest(request) || |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3141 request.type() != Json::objectValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3142 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3143 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3144 "The body must contain a JSON object"); |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3145 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3146 else if (!request.isMember(KEY_LEVEL) || |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3147 request[KEY_LEVEL].type() != Json::stringValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3148 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3149 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3150 "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
|
3151 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3152 else if (!request.isMember(KEY_QUERY) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3153 request[KEY_QUERY].type() != Json::objectValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3154 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3155 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3156 "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
|
3157 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3158 else if (request.isMember(KEY_CASE_SENSITIVE) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3159 request[KEY_CASE_SENSITIVE].type() != Json::booleanValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3160 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3161 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3162 "Field \"" + std::string(KEY_CASE_SENSITIVE) + "\" must be a Boolean"); |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3163 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3164 else if (request.isMember(KEY_LABELS) && |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3165 request[KEY_LABELS].type() != Json::arrayValue) |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3166 { |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3167 throw OrthancException(ErrorCode_BadRequest, |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3168 "Field \"" + std::string(KEY_LABELS) + "\" must be an array of strings"); |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3169 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3170 else if (request.isMember(KEY_LABELS_CONSTRAINT) && |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3171 request[KEY_LABELS_CONSTRAINT].type() != Json::stringValue) |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3172 { |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3173 throw OrthancException(ErrorCode_BadRequest, |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3174 "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be an array of strings"); |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3175 } |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3176 else if (request.isMember(KEY_METADATA_QUERY) && |
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3177 request[KEY_METADATA_QUERY].type() != Json::objectValue) |
5828 | 3178 { |
3179 throw OrthancException(ErrorCode_BadRequest, | |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3180 "Field \"" + std::string(KEY_METADATA_QUERY) + "\" must be an JSON object"); |
5828 | 3181 } |
5826
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3182 else if (request.isMember(KEY_PARENT_PATIENT) && |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3183 request[KEY_PARENT_PATIENT].type() != Json::stringValue) |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3184 { |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3185 throw OrthancException(ErrorCode_BadRequest, |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3186 "Field \"" + std::string(KEY_PARENT_PATIENT) + "\" must be a string"); |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3187 } |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3188 else if (request.isMember(KEY_PARENT_STUDY) && |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3189 request[KEY_PARENT_STUDY].type() != Json::stringValue) |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3190 { |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3191 throw OrthancException(ErrorCode_BadRequest, |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3192 "Field \"" + std::string(KEY_PARENT_STUDY) + "\" must be a string"); |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3193 } |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3194 else if (request.isMember(KEY_PARENT_SERIES) && |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3195 request[KEY_PARENT_SERIES].type() != Json::stringValue) |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3196 { |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3197 throw OrthancException(ErrorCode_BadRequest, |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3198 "Field \"" + std::string(KEY_PARENT_SERIES) + "\" must be a string"); |
d73dfb4548c6
tools/find: ParentPatient and co ..
Alain Mazy <am@orthanc.team>
parents:
5825
diff
changeset
|
3199 } |
5837 | 3200 else if (requestType == FindType_Find && request.isMember(KEY_LIMIT) && |
3201 request[KEY_LIMIT].type() != Json::intValue) | |
3202 { | |
3203 throw OrthancException(ErrorCode_BadRequest, | |
3204 "Field \"" + std::string(KEY_LIMIT) + "\" must be an integer"); | |
3205 } | |
3206 else if (requestType == FindType_Find && request.isMember(KEY_SINCE) && | |
3207 request[KEY_SINCE].type() != Json::intValue) | |
3208 { | |
3209 throw OrthancException(ErrorCode_BadRequest, | |
3210 "Field \"" + std::string(KEY_SINCE) + "\" must be an integer"); | |
3211 } | |
3212 else if (requestType == FindType_Find && request.isMember(KEY_REQUESTED_TAGS) && | |
3213 request[KEY_REQUESTED_TAGS].type() != Json::arrayValue) | |
3214 { | |
3215 throw OrthancException(ErrorCode_BadRequest, | |
3216 "Field \"" + std::string(KEY_REQUESTED_TAGS) + "\" must be an array"); | |
3217 } | |
3218 else if (requestType == FindType_Find && request.isMember(KEY_RESPONSE_CONTENT) && | |
3219 request[KEY_RESPONSE_CONTENT].type() != Json::arrayValue) | |
3220 { | |
3221 throw OrthancException(ErrorCode_BadRequest, | |
3222 "Field \"" + std::string(KEY_RESPONSE_CONTENT) + "\" must be an array"); | |
3223 } | |
3224 else if (requestType == FindType_Find && request.isMember(KEY_ORDER_BY) && | |
3225 request[KEY_ORDER_BY].type() != Json::arrayValue) | |
3226 { | |
3227 throw OrthancException(ErrorCode_BadRequest, | |
3228 "Field \"" + std::string(KEY_ORDER_BY) + "\" must be an array"); | |
3229 } | |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3230 else if (true) |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3231 { |
5829 | 3232 ResponseContentFlags responseContent = ResponseContentFlags_ID; |
3233 | |
5837 | 3234 if (requestType == FindType_Find) |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3235 { |
5837 | 3236 if (request.isMember(KEY_RESPONSE_CONTENT)) |
5829 | 3237 { |
5837 | 3238 responseContent = ResponseContentFlags_Default; |
3239 | |
3240 for (Json::ArrayIndex i = 0; i < request[KEY_RESPONSE_CONTENT].size(); ++i) | |
3241 { | |
3242 responseContent = static_cast<ResponseContentFlags>(static_cast<uint32_t>(responseContent) | StringToResponseContent(request[KEY_RESPONSE_CONTENT][i].asString())); | |
3243 } | |
3244 } | |
3245 else if (request.isMember(KEY_EXPAND) && request[KEY_EXPAND].asBool()) | |
3246 { | |
3247 responseContent = ResponseContentFlags_ExpandTrue; | |
5829 | 3248 } |
3249 } | |
5837 | 3250 else if (requestType == FindType_Count) |
5829 | 3251 { |
5837 | 3252 responseContent = ResponseContentFlags_INTERNAL_CountResources; |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3253 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3254 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3255 const ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3256 |
5829 | 3257 ResourceFinder finder(level, responseContent); |
5837 | 3258 |
5841
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3259 DatabaseLookup dicomTagLookup; |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3260 |
5837 | 3261 { // common query code |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3262 bool caseSensitive = false; |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3263 if (request.isMember(KEY_CASE_SENSITIVE)) |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3264 { |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3265 caseSensitive = request[KEY_CASE_SENSITIVE].asBool(); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3266 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3267 |
5828 | 3268 { // DICOM Tag query |
3269 | |
3270 Json::Value::Members members = request[KEY_QUERY].getMemberNames(); | |
3271 for (size_t i = 0; i < members.size(); i++) | |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3272 { |
5828 | 3273 if (request[KEY_QUERY][members[i]].type() != Json::stringValue) |
3274 { | |
3275 throw OrthancException(ErrorCode_BadRequest, | |
3276 "Tag \"" + members[i] + "\" must be associated with a string"); | |
3277 } | |
3278 | |
3279 const std::string value = request[KEY_QUERY][members[i]].asString(); | |
3280 | |
3281 if (!value.empty()) | |
3282 { | |
3283 // An empty string corresponds to an universal constraint, | |
3284 // so we ignore it. This mimics the behavior of class | |
3285 // "OrthancFindRequestHandler" | |
3286 dicomTagLookup.AddRestConstraint(FromDcmtkBridge::ParseTag(members[i]), | |
3287 value, caseSensitive, true); | |
3288 } | |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3289 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3290 |
5837 | 3291 if (requestType == FindType_Count && !dicomTagLookup.HasOnlyMainDicomTags()) |
3292 { | |
3293 throw OrthancException(ErrorCode_BadRequest, | |
3294 "Unable to count resources when querying tags that are not stored as MainDicomTags in the Database"); | |
3295 } | |
3296 | |
5828 | 3297 finder.SetDatabaseLookup(dicomTagLookup); |
3298 } | |
3299 | |
3300 { // Metadata query | |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3301 Json::Value::Members members = request[KEY_METADATA_QUERY].getMemberNames(); |
5828 | 3302 for (size_t i = 0; i < members.size(); i++) |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3303 { |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3304 if (request[KEY_METADATA_QUERY][members[i]].type() != Json::stringValue) |
5828 | 3305 { |
3306 throw OrthancException(ErrorCode_BadRequest, | |
3307 "Tag \"" + members[i] + "\" must be associated with a string"); | |
3308 } | |
3309 MetadataType metadata = StringToMetadata(members[i]); | |
3310 | |
5836
618d44e0e714
renamed QueryMetadata into MetadataQuery
Alain Mazy <am@orthanc.team>
parents:
5832
diff
changeset
|
3311 const std::string value = request[KEY_METADATA_QUERY][members[i]].asString(); |
5828 | 3312 |
3313 if (!value.empty()) | |
3314 { | |
3315 if (value.find('\\') != std::string::npos) | |
3316 { | |
3317 std::vector<std::string> items; | |
3318 Toolbox::TokenizeString(items, value, '\\'); | |
3319 | |
3320 finder.AddMetadataConstraint(new DatabaseMetadataConstraint(metadata, ConstraintType_List, items, caseSensitive)); | |
3321 } | |
3322 else if (value.find('*') != std::string::npos || value.find('?') != std::string::npos) | |
3323 { | |
3324 finder.AddMetadataConstraint(new DatabaseMetadataConstraint(metadata, ConstraintType_Wildcard, value, caseSensitive)); | |
3325 } | |
3326 else | |
3327 { | |
3328 finder.AddMetadataConstraint(new DatabaseMetadataConstraint(metadata, ConstraintType_Equal, value, caseSensitive)); | |
3329 } | |
3330 } | |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3331 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3332 } |
5837 | 3333 |
3334 { // labels query | |
3335 if (request.isMember(KEY_LABELS)) // New in Orthanc 1.12.0 | |
3336 { | |
3337 for (Json::Value::ArrayIndex i = 0; i < request[KEY_LABELS].size(); i++) | |
3338 { | |
3339 if (request[KEY_LABELS][i].type() != Json::stringValue) | |
3340 { | |
3341 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS) + "\" must contain strings"); | |
3342 } | |
3343 else | |
3344 { | |
3345 finder.AddLabel(request[KEY_LABELS][i].asString()); | |
3346 } | |
3347 } | |
3348 } | |
3349 | |
3350 finder.SetLabelsConstraint(LabelsConstraint_All); | |
3351 | |
3352 if (request.isMember(KEY_LABELS_CONSTRAINT)) | |
3353 { | |
3354 const std::string& s = request[KEY_LABELS_CONSTRAINT].asString(); | |
3355 if (s == "All") | |
3356 { | |
3357 finder.SetLabelsConstraint(LabelsConstraint_All); | |
3358 } | |
3359 else if (s == "Any") | |
3360 { | |
3361 finder.SetLabelsConstraint(LabelsConstraint_Any); | |
3362 } | |
3363 else if (s == "None") | |
3364 { | |
3365 finder.SetLabelsConstraint(LabelsConstraint_None); | |
3366 } | |
3367 else | |
3368 { | |
3369 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\""); | |
3370 } | |
3371 } | |
3372 } | |
3373 | |
3374 // parents query | |
3375 if (request.isMember(KEY_PARENT_PATIENT)) // New in Orthanc 1.12.5 | |
3376 { | |
3377 finder.SetOrthancId(ResourceType_Patient, request[KEY_PARENT_PATIENT].asString()); | |
3378 } | |
3379 else if (request.isMember(KEY_PARENT_STUDY)) | |
3380 { | |
3381 finder.SetOrthancId(ResourceType_Study, request[KEY_PARENT_STUDY].asString()); | |
3382 } | |
3383 else if (request.isMember(KEY_PARENT_SERIES)) | |
3384 { | |
3385 finder.SetOrthancId(ResourceType_Series, request[KEY_PARENT_SERIES].asString()); | |
3386 } | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3387 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3388 |
5837 | 3389 // response |
3390 if (requestType == FindType_Find) | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3391 { |
5837 | 3392 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); |
3393 | |
3394 finder.SetDatabaseLimits(context.GetDatabaseLimits(level)); | |
3395 | |
5841
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3396 if ((request.isMember(KEY_LIMIT) || request.isMember(KEY_SINCE)) && |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3397 !dicomTagLookup.HasOnlyMainDicomTags()) |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3398 { |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3399 throw OrthancException(ErrorCode_BadRequest, |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3400 "Unable to use " + std::string(KEY_LIMIT) + " or " + std::string(KEY_SINCE) + " in tools/find when querying tags that are not stored as MainDicomTags in the Database"); |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3401 } |
57ab63fe9108
tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
Alain Mazy <am@orthanc.team>
parents:
5837
diff
changeset
|
3402 |
5837 | 3403 if (request.isMember(KEY_LIMIT)) |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3404 { |
5837 | 3405 int64_t tmp = request[KEY_LIMIT].asInt64(); |
3406 if (tmp < 0) | |
3407 { | |
3408 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
3409 "Field \"" + std::string(KEY_LIMIT) + "\" must be a positive integer"); | |
3410 } | |
3411 else if (tmp != 0) // This is for compatibility with Orthanc 1.12.4 | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3412 { |
5837 | 3413 finder.SetLimitsCount(static_cast<uint64_t>(tmp)); |
3414 } | |
3415 } | |
3416 | |
3417 if (request.isMember(KEY_SINCE)) | |
3418 { | |
3419 int64_t tmp = request[KEY_SINCE].asInt64(); | |
3420 if (tmp < 0) | |
3421 { | |
3422 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
3423 "Field \"" + std::string(KEY_SINCE) + "\" must be a positive integer"); | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3424 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3425 else |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3426 { |
5837 | 3427 finder.SetLimitsSince(static_cast<uint64_t>(tmp)); |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3428 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3429 } |
5837 | 3430 |
3431 if (request.isMember(KEY_REQUESTED_TAGS)) | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3432 { |
5837 | 3433 std::set<DicomTag> requestedTags; |
3434 FromDcmtkBridge::ParseListOfTags(requestedTags, request[KEY_REQUESTED_TAGS]); | |
3435 finder.AddRequestedTags(requestedTags); | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3436 } |
5837 | 3437 |
3438 if (request.isMember(KEY_ORDER_BY)) // New in Orthanc 1.12.5 | |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3439 { |
5837 | 3440 for (Json::Value::ArrayIndex i = 0; i < request[KEY_ORDER_BY].size(); i++) |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3441 { |
5837 | 3442 if (request[KEY_ORDER_BY][i].type() != Json::objectValue) |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3443 { |
5837 | 3444 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY) + "\" must contain objects"); |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3445 } |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3446 else |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3447 { |
5837 | 3448 const Json::Value& order = request[KEY_ORDER_BY][i]; |
3449 FindRequest::OrderingDirection direction; | |
3450 std::string directionString; | |
3451 std::string typeString; | |
3452 | |
3453 if (!order.isMember(KEY_ORDER_BY_KEY) || order[KEY_ORDER_BY_KEY].type() != Json::stringValue) | |
3454 { | |
3455 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_KEY) + "\" must be a string"); | |
3456 } | |
3457 | |
3458 if (!order.isMember(KEY_ORDER_BY_DIRECTION) || order[KEY_ORDER_BY_DIRECTION].type() != Json::stringValue) | |
3459 { | |
3460 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_DIRECTION) + "\" must be \"ASC\" or \"DESC\""); | |
3461 } | |
3462 | |
3463 Toolbox::ToLowerCase(directionString, order[KEY_ORDER_BY_DIRECTION].asString()); | |
3464 if (directionString == "asc") | |
3465 { | |
3466 direction = FindRequest::OrderingDirection_Ascending; | |
3467 } | |
3468 else if (directionString == "desc") | |
3469 { | |
3470 direction = FindRequest::OrderingDirection_Descending; | |
3471 } | |
3472 else | |
3473 { | |
3474 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_DIRECTION) + "\" must be \"ASC\" or \"DESC\""); | |
3475 } | |
3476 | |
3477 if (!order.isMember(KEY_ORDER_BY_TYPE) || order[KEY_ORDER_BY_TYPE].type() != Json::stringValue) | |
3478 { | |
3479 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_TYPE) + "\" must be \"DicomTag\" or \"Metadata\""); | |
3480 } | |
3481 | |
3482 Toolbox::ToLowerCase(typeString, order[KEY_ORDER_BY_TYPE].asString()); | |
3483 if (typeString == "dicomtag") | |
3484 { | |
3485 DicomTag tag = FromDcmtkBridge::ParseTag(order[KEY_ORDER_BY_KEY].asString()); | |
3486 finder.AddOrdering(tag, direction); | |
3487 } | |
3488 else if (typeString == "metadata") | |
3489 { | |
3490 MetadataType metadata = StringToMetadata(order[KEY_ORDER_BY_KEY].asString()); | |
3491 finder.AddOrdering(metadata, direction); | |
3492 } | |
3493 else | |
3494 { | |
3495 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_ORDER_BY_TYPE) + "\" must be \"DicomTag\" or \"Metadata\""); | |
3496 } | |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3497 } |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3498 } |
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3499 } |
5837 | 3500 |
3501 Json::Value answer; | |
3502 finder.Execute(answer, context, format, false /* no "Metadata" field */); | |
3503 call.GetOutput().AnswerJson(answer); | |
5825
881cd0965146
added OrderBy support in SQLite
Alain Mazy <am@orthanc.team>
parents:
5817
diff
changeset
|
3504 } |
5837 | 3505 else if (requestType == FindType_Count) |
3506 { | |
3507 uint64_t count = finder.Count(context); | |
3508 Json::Value answer; | |
3509 answer["Count"] = Json::Value::UInt64(count); | |
3510 call.GetOutput().AnswerJson(answer); | |
3511 } | |
3512 | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3513 } |
1354 | 3514 } |
3515 | |
3516 | |
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
|
3517 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
|
3518 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
|
3519 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
|
3520 { |
4415 | 3521 if (call.IsDocumentation()) |
3522 { | |
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
|
3523 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3524 OrthancRestApi::DocumentRequestedTags(call); |
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
|
3525 |
4415 | 3526 const std::string children = GetResourceTypeText(end, true /* plural */, false /* lower case */); |
3527 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */); | |
3528 call.GetDocumentation() | |
3529 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */)) | |
3530 .SetSummary("Get child " + children) | |
3531 .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
|
3532 resource + " whose Orthanc identifier is provided in the URL") |
4415 | 3533 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
5405
62bb63346185
All 'expand' GET arguments now accepts expand=true and expand=false values + /studies/../instances now supports expand=false
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
3534 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, |
62bb63346185
All 'expand' GET arguments now accepts expand=true and expand=false values + /studies/../instances now supports expand=false
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
3535 "If false or missing, only retrieve the list of child " + children, false) |
4415 | 3536 .AddAnswerType(MimeType_Json, "JSON array containing information about the child DICOM " + children) |
3537 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + children, 5); | |
3538 return; | |
3539 } | |
3540 | |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3541 const bool expand = (!call.HasArgument("expand") || |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3542 // this "expand" is the only one to have a false default value to keep backward compatibility |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3543 call.GetBooleanArgument("expand", false)); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3544 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3545 |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3546 std::set<DicomTag> requestedTags; |
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3547 OrthancRestApi::GetRequestedTags(requestedTags, call); |
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3548 |
5833
58c549b881ae
merged find-refactoring -> find-refactoring-clean
Alain Mazy <am@orthanc.team>
diff
changeset
|
3549 ResourceFinder finder(end, (expand ? ResponseContentFlags_ExpandTrue : ResponseContentFlags_ID)); |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3550 finder.SetOrthancId(start, call.GetUriComponent("id", "")); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3551 finder.AddRequestedTags(requestedTags); |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3552 |
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3553 Json::Value answer; |
5715
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
3554 finder.Execute(answer, OrthancRestApi::GetContext(call), format, false /* no "Metadata" field */); |
5704
0c2f0d72d143
only keep experimental versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3555 call.GetOutput().AnswerJson(answer); |
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
|
3556 } |
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
|
3557 |
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
|
3558 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3559 static void GetChildInstancesTags(RestApiGetCall& call) |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3560 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3561 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3562 { |
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
|
3563 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
|
3564 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3565 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
|
3566 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
|
3567 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3568 .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
|
3569 .SetSummary("Get tags of instances") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3570 .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
|
3571 " 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
|
3572 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
3573 .SetHttpGetArgument(IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings, |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3574 "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
|
3575 .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
|
3576 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/instances-tags", 5); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3577 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3578 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3579 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3580 ServerContext& context = OrthancRestApi::GetContext(call); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3581 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
|
3582 DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full); |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3583 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3584 std::set<DicomTag> ignoreTagLength; |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
3585 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3586 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3587 // Retrieve all the instances of this patient/study/series |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3588 typedef std::list<std::string> Instances; |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3589 Instances instances; |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3590 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3591 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3592 |
1201
09aa7c126be9
URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1172
diff
changeset
|
3593 Json::Value result = Json::objectValue; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3594 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3595 for (Instances::const_iterator it = instances.begin(); |
1303 | 3596 it != instances.end(); ++it) |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3597 { |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3598 Json::Value full; |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3599 context.ReadDicomAsJson(full, *it, ignoreTagLength); |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3600 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
3601 if (format != DicomToJsonFormat_Full) |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3602 { |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3603 Json::Value simplified; |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
3604 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
|
3605 result[*it] = simplified; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3606 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3607 else |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3608 { |
1201
09aa7c126be9
URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1172
diff
changeset
|
3609 result[*it] = full; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3610 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3611 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3612 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3613 call.GetOutput().AnswerJson(result); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3614 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3615 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3616 |
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
|
3617 |
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
|
3618 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
|
3619 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
|
3620 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
|
3621 { |
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
|
3622 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
|
3623 |
4415 | 3624 if (call.IsDocumentation()) |
3625 { | |
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
|
3626 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human); |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3627 OrthancRestApi::DocumentRequestedTags(call); |
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
|
3628 |
4415 | 3629 const std::string parent = GetResourceTypeText(end, false /* plural */, false /* lower case */); |
3630 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */); | |
3631 call.GetDocumentation() | |
3632 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */)) | |
3633 .SetSummary("Get parent " + parent) | |
3634 .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
|
3635 resource + " whose Orthanc identifier is provided in the URL") |
4415 | 3636 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
3637 .AddAnswerType(MimeType_Json, "Information about the parent DICOM " + parent) | |
3638 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + parent, 10); | |
3639 return; | |
3640 } | |
3641 | |
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
|
3642 ServerIndex& index = OrthancRestApi::GetIndex(call); |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3643 |
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3644 std::set<DicomTag> requestedTags; |
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3645 OrthancRestApi::GetRequestedTags(requestedTags, call); |
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3646 |
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
|
3647 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
|
3648 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
|
3649 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
|
3650 { |
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
|
3651 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
|
3652 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
|
3653 { |
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
|
3654 // 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
|
3655 // 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
|
3656 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
|
3657 } |
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
|
3658 |
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
|
3659 current = parent; |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
3660 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
|
3661 } |
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
|
3662 |
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
|
3663 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
|
3664 |
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
|
3665 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
|
3666 |
4554 | 3667 Json::Value resource; |
5715
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
3668 if (ExpandResource(resource, OrthancRestApi::GetContext(call), currentType, current, format, false)) |
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
|
3669 { |
4554 | 3670 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
|
3671 } |
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
|
3672 } |
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
|
3673 |
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
|
3674 |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3675 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
|
3676 { |
4407 | 3677 if (call.IsDocumentation()) |
3678 { | |
3679 call.GetDocumentation() | |
3680 .SetTag("Instances") | |
3681 .SetSummary("Get embedded PDF") | |
3682 .SetDescription("Get the PDF file that is embedded in one DICOM instance. " | |
3683 "If the DICOM instance doesn't contain the `EncapsulatedDocument` tag or if the " | |
3684 "`MIMETypeOfEncapsulatedDocument` tag doesn't correspond to the PDF type, a `404` HTTP error is raised.") | |
3685 .SetUriArgument("id", "Orthanc identifier of the instance interest") | |
3686 .AddAnswerType(MimeType_Pdf, "PDF file"); | |
3687 return; | |
3688 } | |
3689 | |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3690 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
|
3691 std::string pdf; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3692 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
|
3693 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3694 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
|
3695 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3696 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
|
3697 return; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3698 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3699 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3700 |
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
|
3701 |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3702 static void OrderSlices(RestApiGetCall& call) |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3703 { |
4421 | 3704 if (call.IsDocumentation()) |
3705 { | |
3706 call.GetDocumentation() | |
3707 .SetDeprecated() | |
3708 .SetTag("Series") | |
3709 .SetSummary("Order the slices") | |
3710 .SetDescription("Sort the instances and frames (slices) of the DICOM series whose Orthanc identifier is provided in the URL. " | |
3711 "This URI is essentially used by the Orthanc Web viewer and by the Osimis Web viewer.") | |
3712 .SetUriArgument("id", "Orthanc identifier of the series of interest") | |
3713 .SetAnswerField("Dicom", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3714 "Ordered list of paths to DICOM instances") | |
3715 .SetAnswerField("Slices", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3716 "Ordered list of paths to frames. It is recommended to use this field, as it is also valid " | |
3717 "in the case of multiframe images.") | |
3718 .SetAnswerField("SlicesShort", RestApiCallDocumentation::Type_JsonListOfObjects, | |
3719 "Same information as the `Slices` field, but in a compact form") | |
3720 .SetAnswerField("Type", RestApiCallDocumentation::Type_String, | |
3721 "Can be `Volume` (for 3D volumes) or `Sequence` (notably for cine images)") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
3722 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/series/1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0/ordered-slices", 10); |
4421 | 3723 return; |
3724 } | |
3725 | |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3726 const std::string id = call.GetUriComponent("id", ""); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3727 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3728 ServerIndex& index = OrthancRestApi::GetIndex(call); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3729 SliceOrdering ordering(index, id); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3730 |
1703
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3731 Json::Value result; |
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3732 ordering.Format(result); |
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3733 call.GetOutput().AnswerJson(result); |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3734 } |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3735 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3736 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3737 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
|
3738 { |
4404 | 3739 if (call.IsDocumentation()) |
3740 { | |
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
|
3741 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full); |
4404 | 3742 call.GetDocumentation() |
3743 .SetTag("Instances") | |
3744 .SetSummary("Get DICOM meta-header") | |
3745 .SetDescription("Get the DICOM tags in the meta-header of the DICOM instance. By default, the `full` format is used, which " | |
3746 "combines hexadecimal tags with human-readable description.") | |
3747 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
3748 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
3749 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/header", true); |
4404 | 3750 return; |
3751 } | |
3752 | |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3753 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
|
3754 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3755 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
|
3756 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3757 std::string dicomContent; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
3758 context.ReadDicomForHeader(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
|
3759 |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3760 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to |
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3761 // speed up things here |
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3762 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3763 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
|
3764 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3765 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
|
3766 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
|
3767 |
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
|
3768 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
|
3769 } |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3770 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3771 |
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
|
3772 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
|
3773 { |
4420 | 3774 if (call.IsDocumentation()) |
3775 { | |
3776 call.GetDocumentation() | |
3777 .SetTag("System") | |
3778 .SetSummary("Invalidate DICOM-as-JSON summaries") | |
3779 .SetDescription("Remove all the attachments of the type \"DICOM-as-JSON\" that are associated will all the " | |
3780 "DICOM instances stored in Orthanc. These summaries will be automatically re-created on the next access. " | |
3781 "This is notably useful after changes to the `Dictionary` configuration option. " | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
3782 "https://orthanc.uclouvain.be/book/faq/orthanc-storage.html#storage-area"); |
4420 | 3783 return; |
3784 } | |
3785 | |
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
|
3786 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
|
3787 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3788 // 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
|
3789 // 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
|
3790 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
|
3791 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
|
3792 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3793 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
|
3794 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
|
3795 { |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3796 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
|
3797 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
|
3798 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3799 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
|
3800 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
|
3801 { |
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
|
3802 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
|
3803 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
|
3804 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3805 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3806 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3807 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
|
3808 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3809 |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3810 void DocumentReconstructFilesField(RestApiPostCall& call, bool documentLimitField) |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3811 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3812 call.GetDocumentation() |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3813 .SetRequestField(RECONSTRUCT_FILES, RestApiCallDocumentation::Type_Boolean, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3814 "Also reconstruct the files of the resources (e.g: apply IngestTranscoding, StorageCompression). " |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3815 "'false' by default. (New in Orthanc 1.11.0)", false); |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3816 if (documentLimitField) |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3817 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3818 call.GetDocumentation() |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3819 .SetRequestField(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS, RestApiCallDocumentation::Type_Boolean, |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3820 "Only reconstruct this level MainDicomTags by re-reading them from a random child instance of the resource. " |
5655 | 3821 "This option is much faster than a full reconstruct and is useful e.g. if you have modified the " |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3822 "'ExtraMainDicomTags' at the Study level to optimize the speed of some C-Find. " |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3823 "'false' by default. (New in Orthanc 1.12.4)", false); |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3824 } |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3825 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3826 |
4994 | 3827 bool GetReconstructFilesField(const RestApiPostCall& call) |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3828 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3829 bool reconstructFiles = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3830 Json::Value request; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3831 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3832 if (call.GetBodySize() > 0 && call.ParseJsonRequest(request) && request.isMember(RECONSTRUCT_FILES)) // allow "" payload to keep backward compatibility |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3833 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3834 if (!request[RECONSTRUCT_FILES].isBool()) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3835 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3836 throw OrthancException(ErrorCode_BadFileFormat, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3837 "The field " + std::string(RECONSTRUCT_FILES) + " must contain a Boolean"); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3838 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3839 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3840 reconstructFiles = request[RECONSTRUCT_FILES].asBool(); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3841 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3842 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3843 return reconstructFiles; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3844 } |
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
|
3845 |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3846 bool GetLimitToThisLevelMainDicomTags(const RestApiPostCall& call) |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3847 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3848 bool limitToThisLevel = false; |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3849 Json::Value request; |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3850 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3851 if (call.GetBodySize() > 0 && call.ParseJsonRequest(request) && request.isMember(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS)) |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3852 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3853 if (!request[LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS].isBool()) |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3854 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3855 throw OrthancException(ErrorCode_BadFileFormat, |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3856 "The field " + std::string(LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS) + " must contain a Boolean"); |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3857 } |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3858 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3859 limitToThisLevel = request[LIMIT_TO_THIS_LEVEL_MAIN_DICOM_TAGS].asBool(); |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3860 } |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3861 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3862 return limitToThisLevel; |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3863 } |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3864 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3865 |
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
|
3866 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
|
3867 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
|
3868 { |
4420 | 3869 if (call.IsDocumentation()) |
3870 { | |
3871 const std::string resource = GetResourceTypeText(type, false /* plural */, false /* lower case */); | |
3872 call.GetDocumentation() | |
3873 .SetTag(GetResourceTypeText(type, true /* plural */, true /* upper case */)) | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3874 .SetSummary("Reconstruct tags & optionally files of " + resource) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3875 .SetDescription("Reconstruct the main DICOM tags in DB of the " + resource + " whose Orthanc identifier is provided " |
4420 | 3876 "in the URL. This is useful if child studies/series/instances have inconsistent values for " |
3877 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. " | |
3878 "Beware that this is a time-consuming operation, as all the children DICOM instances will be " | |
3879 "parsed again, and the Orthanc index will be updated accordingly.") | |
3880 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); | |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3881 DocumentReconstructFilesField(call, true); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3882 |
4420 | 3883 return; |
3884 } | |
3885 | |
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
|
3886 ServerContext& context = OrthancRestApi::GetContext(call); |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3887 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""), GetReconstructFilesField(call), GetLimitToThisLevelMainDicomTags(call), type); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3888 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
|
3889 } |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
3890 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
3891 |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3892 static void ReconstructAllResources(RestApiPostCall& call) |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3893 { |
4420 | 3894 if (call.IsDocumentation()) |
3895 { | |
3896 call.GetDocumentation() | |
3897 .SetTag("System") | |
3898 .SetSummary("Reconstruct all the index") | |
3899 .SetDescription("Reconstruct the index of all the tags of all the DICOM instances that are stored in Orthanc. " | |
3900 "This is notably useful after the deletion of resources whose children resources have inconsistent " | |
3901 "values with their sibling resources. Beware that this is a highly time-consuming operation, " | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3902 "as all the DICOM instances will be parsed again, and as all the Orthanc index will be regenerated. " |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3903 "If you have a large database to process, it is advised to use the Housekeeper plugin to perform " |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3904 "this action resource by resource"); |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3905 DocumentReconstructFilesField(call, false); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3906 |
4420 | 3907 return; |
3908 } | |
3909 | |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3910 ServerContext& context = OrthancRestApi::GetContext(call); |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3911 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3912 std::list<std::string> studies; |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3913 context.GetIndex().GetAllUuids(studies, ResourceType_Study); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3914 bool reconstructFiles = GetReconstructFilesField(call); |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3915 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3916 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
|
3917 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
|
3918 { |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3919 ServerToolbox::ReconstructResource(context, *study, reconstructFiles, false, ResourceType_Study /* dummy */); |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3920 } |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3921 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3922 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
|
3923 } |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3924 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3925 |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3926 static void GetBulkChildren(std::set<std::string>& target, |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3927 ServerIndex& index, |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3928 const std::set<std::string>& source) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3929 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3930 target.clear(); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3931 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3932 for (std::set<std::string>::const_iterator |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3933 it = source.begin(); it != source.end(); ++it) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3934 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3935 std::list<std::string> children; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3936 index.GetChildren(children, *it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3937 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3938 for (std::list<std::string>::const_iterator |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3939 child = children.begin(); child != children.end(); ++child) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3940 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3941 target.insert(*child); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3942 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3943 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3944 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3945 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3946 |
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
|
3947 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
|
3948 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3949 static const char* const LEVEL = "Level"; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3950 static const char* const METADATA = "Metadata"; |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3951 |
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
|
3952 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
|
3953 { |
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
|
3954 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
|
3955 |
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
|
3956 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
|
3957 .SetTag("System") |
4879 | 3958 .SetSummary("Describe a set of resources") |
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
|
3959 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3960 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true) |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3961 .SetRequestField(LEVEL, RestApiCallDocumentation::Type_String, |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3962 "This optional argument specifies the level of interest (can be `Patient`, `Study`, `Series` or " |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
3963 "`Instance`). Orthanc will loop over the items inside `Resources`, and explore upward or " |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3964 "downward in the DICOM hierarchy in order to find the level of interest.", false) |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3965 .SetRequestField(METADATA, RestApiCallDocumentation::Type_Boolean, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3966 "If set to `true` (default value), the metadata associated with the resources will also be retrieved.", 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
|
3967 .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
|
3968 "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
|
3969 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
|
3970 } |
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
|
3971 |
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
|
3972 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
|
3973 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
|
3974 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
|
3975 { |
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
|
3976 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
|
3977 "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
|
3978 } |
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
|
3979 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
|
3980 { |
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
|
3981 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
|
3982 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3983 bool metadata = true; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3984 if (request.isMember(METADATA)) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3985 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3986 metadata = SerializationToolbox::ReadBoolean(request, METADATA); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3987 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3988 |
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
|
3989 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
|
3990 |
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
|
3991 Json::Value answer = Json::arrayValue; |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3992 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3993 if (request.isMember(LEVEL)) |
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
|
3994 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3995 // Complex case: Need to explore the DICOM hierarchy |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3996 ResourceType level = StringToResourceType(SerializationToolbox::ReadString(request, LEVEL).c_str()); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3997 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3998 std::set<std::string> resources; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3999 SerializationToolbox::ReadSetOfStrings(resources, request, "Resources"); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4000 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4001 std::set<std::string> interest; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4002 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4003 assert(ResourceType_Patient < ResourceType_Study && |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4004 ResourceType_Study < ResourceType_Series && |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4005 ResourceType_Series < ResourceType_Instance); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4006 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4007 for (std::set<std::string>::const_iterator |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4008 it = resources.begin(); it != resources.end(); ++it) |
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
|
4009 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4010 ResourceType type; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4011 if (index.LookupResourceType(type, *it)) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4012 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4013 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4014 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4015 // This resource is already from the level of interest |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4016 interest.insert(*it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4017 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4018 else if (type < level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4019 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4020 // Need to explore children |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4021 std::set<std::string> current; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4022 current.insert(*it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4023 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4024 for (;;) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4025 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4026 std::set<std::string> children; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4027 GetBulkChildren(children, index, current); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4028 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4029 type = GetChildResourceType(type); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4030 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4031 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4032 for (std::set<std::string>::const_iterator |
4716 | 4033 it2 = children.begin(); it2 != children.end(); ++it2) |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4034 { |
4716 | 4035 interest.insert(*it2); |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4036 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4037 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4038 break; // done |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4039 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4040 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4041 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4042 current.swap(children); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4043 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4044 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4045 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4046 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4047 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4048 // Need to explore parents |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4049 std::string current = *it; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4050 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4051 for (;;) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4052 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4053 std::string parent; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4054 if (index.LookupParent(parent, current)) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4055 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4056 type = GetParentResourceType(type); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4057 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4058 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4059 interest.insert(parent); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4060 break; // done |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4061 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4062 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4063 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4064 current = parent; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4065 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4066 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4067 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4068 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4069 break; // The resource has been deleted during the exploration |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4070 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4071 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4072 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4073 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4074 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4075 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4076 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4077 } |
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
|
4078 } |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4079 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4080 for (std::set<std::string>::const_iterator |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4081 it = interest.begin(); it != interest.end(); ++it) |
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
|
4082 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4083 Json::Value item; |
5715
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
4084 if (ExpandResource(item, OrthancRestApi::GetContext(call), level, *it, format, metadata)) |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4085 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4086 answer.append(item); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4087 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4088 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4089 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4090 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4091 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4092 // Simple case: We return the queried resources as such |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4093 std::list<std::string> resources; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4094 SerializationToolbox::ReadListOfStrings(resources, request, "Resources"); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4095 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4096 for (std::list<std::string>::const_iterator |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4097 it = resources.begin(); it != resources.end(); ++it) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4098 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4099 ResourceType level; |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4100 Json::Value item; |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
4101 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4102 if (index.LookupResourceType(level, *it) && |
5715
593e110de3d8
integration find-refactoring->find-refactoring-clean
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
4103 ExpandResource(item, OrthancRestApi::GetContext(call), level, *it, format, metadata)) |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4104 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4105 answer.append(item); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4106 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4107 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4108 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4109 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4110 } |
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
|
4111 } |
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
|
4112 } |
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
|
4113 |
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
|
4114 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
|
4115 } |
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
|
4116 } |
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
|
4117 |
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
|
4118 |
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
|
4119 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
|
4120 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4121 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
|
4122 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4123 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
|
4124 .SetTag("System") |
4879 | 4125 .SetSummary("Delete a set of resources") |
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
|
4126 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4127 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true) |
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
|
4128 .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
|
4129 "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
|
4130 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
|
4131 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4132 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4133 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
|
4134 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4135 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
|
4136 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
|
4137 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
|
4138 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4139 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
|
4140 "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
|
4141 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4142 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
|
4143 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4144 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
|
4145 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
|
4146 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4147 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
|
4148 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
|
4149 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4150 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
|
4151 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
|
4152 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4153 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
|
4154 !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
|
4155 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4156 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
|
4157 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4158 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4159 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4160 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
|
4161 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4162 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4163 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4164 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4165 void OrthancRestApi::RegisterResources() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4166 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4167 Register("/instances", ListResources<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4168 Register("/patients", ListResources<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4169 Register("/series", ListResources<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4170 Register("/studies", ListResources<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4171 |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4172 if (!context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4173 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4174 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4175 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4176 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4177 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4178 |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4179 Register("/tools/bulk-delete", BulkDelete); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4180 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4181 else |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4182 { |
5817 | 4183 LOG(WARNING) << "READ-ONLY SYSTEM: deactivating DELETE routes"; |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4184 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4185 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4186 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4187 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4188 Register("/series/{id}", GetSingleResource<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4189 Register("/studies/{id}", GetSingleResource<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4190 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4191 Register("/instances/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4192 Register("/patients/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4193 Register("/studies/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4194 Register("/series/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4195 |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4196 Register("/patients/{id}/shared-tags", GetSharedTags); |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4197 Register("/series/{id}/shared-tags", GetSharedTags); |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4198 Register("/studies/{id}/shared-tags", GetSharedTags); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
4199 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4200 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4201 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4202 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4203 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4204 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
|
4205 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4206 Register("/instances/{id}/file", GetInstanceFile); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4207 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
|
4208 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
|
4209 Register("/instances/{id}/simplified-tags", GetInstanceSimplifiedTags); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4210 Register("/instances/{id}/frames", ListFrames); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4211 |
4424
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4422
diff
changeset
|
4212 Register("/instances/{id}/frames/{frame}", RestApi::AutoListChildren); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4213 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
|
4214 Register("/instances/{id}/frames/{frame}/rendered", GetRenderedFrame); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4215 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4216 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4217 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
|
4218 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
|
4219 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
|
4220 Register("/instances/{id}/frames/{frame}/raw.gz", GetRawFrame<true>); |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
4221 Register("/instances/{id}/frames/{frame}/numpy", GetNumpyFrame); // New in Orthanc 1.10.0 |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
4222 Register("/instances/{id}/pdf", ExtractPdf); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4223 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
|
4224 Register("/instances/{id}/rendered", GetRenderedFrame); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4225 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4226 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4227 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
4228 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
|
4229 Register("/instances/{id}/header", GetInstanceHeader); |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
4230 Register("/instances/{id}/numpy", GetNumpyInstance); // New in Orthanc 1.10.0 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4231 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4232 Register("/patients/{id}/protected", IsProtectedPatient); |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4233 |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4234 if (!context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4235 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4236 Register("/patients/{id}/protected", SetPatientProtection); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4237 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4238 else |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4239 { |
5817 | 4240 LOG(WARNING) << "READ-ONLY SYSTEM: deactivating PUT /patients/{id}/protected route"; |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4241 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4242 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4243 |
4409 | 4244 std::vector<std::string> resourceTypes; |
4245 resourceTypes.push_back("patients"); | |
4246 resourceTypes.push_back("studies"); | |
4247 resourceTypes.push_back("series"); | |
4248 resourceTypes.push_back("instances"); | |
4249 | |
4250 for (size_t i = 0; i < resourceTypes.size(); i++) | |
4251 { | |
4252 Register("/" + resourceTypes[i] + "/{id}/metadata", ListMetadata); | |
4253 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", DeleteMetadata); | |
4254 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", GetMetadata); | |
4255 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", SetMetadata); | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4256 |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4257 // New in Orthanc 1.12.0 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4258 Register("/" + resourceTypes[i] + "/{id}/labels", ListLabels); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4259 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", GetLabel); |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4260 |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4261 if (!context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4262 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4263 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", RemoveLabel); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4264 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", AddLabel); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4265 } |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4266 |
4409 | 4267 Register("/" + resourceTypes[i] + "/{id}/attachments", ListAttachments); |
4268 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", GetAttachmentOperations); | |
4269 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>); | |
4270 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5); | |
4271 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize); | |
4272 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/data", GetAttachmentData<1>); | |
4273 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed); | |
4274 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5); | |
4275 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize); | |
4883
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
4276 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/info", GetAttachmentInfo); |
4409 | 4277 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment); |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4278 |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4279 if (!context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4280 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4281 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", DeleteAttachment); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4282 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", UploadAttachment); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4283 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4284 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4285 } |
4409 | 4286 } |
782 | 4287 |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4288 if (context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4289 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4290 LOG(WARNING) << "READ-ONLY SYSTEM: deactivating PUT, POST and DELETE attachments routes"; |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4291 LOG(WARNING) << "READ-ONLY SYSTEM: deactivating PUT and DELETE labels routes"; |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4292 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4293 |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4294 if (!context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4295 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4296 Register("/tools/invalidate-tags", InvalidateTags); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4297 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4298 |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
4299 Register("/tools/lookup", Lookup); |
5837 | 4300 Register("/tools/find", Find<FindType_Find>); |
4301 if (context_.GetIndex().HasFindSupport()) | |
4302 { | |
4303 Register("/tools/count-resources", Find<FindType_Count>); | |
4304 } | |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
4305 |
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
|
4306 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
|
4307 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
|
4308 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
|
4309 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
|
4310 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
|
4311 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
|
4312 |
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
|
4313 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
|
4314 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
|
4315 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
|
4316 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
|
4317 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
|
4318 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
|
4319 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4320 Register("/patients/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4321 Register("/studies/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4322 Register("/series/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4323 |
782 | 4324 Register("/instances/{id}/content/*", GetRawContent); |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
4325 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
4326 Register("/series/{id}/ordered-slices", OrderSlices); |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
4327 Register("/series/{id}/numpy", GetNumpySeries); // New in Orthanc 1.10.0 |
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
|
4328 |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4329 if (!context_.IsReadOnly()) |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4330 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4331 Register("/patients/{id}/reconstruct", ReconstructResource<ResourceType_Patient>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4332 Register("/studies/{id}/reconstruct", ReconstructResource<ResourceType_Study>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4333 Register("/series/{id}/reconstruct", ReconstructResource<ResourceType_Series>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4334 Register("/instances/{id}/reconstruct", ReconstructResource<ResourceType_Instance>); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4335 Register("/tools/reconstruct", ReconstructAllResources); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4336 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4337 else |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4338 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4339 LOG(WARNING) << "READ-ONLY SYSTEM: deactivating /reconstruct routes"; |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5714
diff
changeset
|
4340 } |
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
|
4341 |
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
|
4342 Register("/tools/bulk-content", BulkContent); |
5804
25df40a274fd
/changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents:
5783
diff
changeset
|
4343 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4344 } |