Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5709:476b1db52110 find-refactoring
removed the "format_" member from ResourceFinder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Jul 2024 18:41:44 +0200 |
parents | 1891a8c2dbb4 |
children | a786da7599d5 d851a54e49b7 |
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" |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1385
diff
changeset
|
44 #include "../ServerContext.h" |
2131 | 45 #include "../ServerToolbox.h" |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
46 #include "../SliceOrdering.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
3687 | 48 // This "include" is mandatory for Release builds using Linux Standard Base |
49 #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
|
50 #include <boost/shared_ptr.hpp> |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
52 /** |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
53 * 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
|
54 * 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
|
55 * 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
|
56 **/ |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
57 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
|
58 |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
59 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
60 static const std::string CHECK_REVISIONS = "CheckRevisions"; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
61 |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
67 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 { |
4415 | 70 static std::string GetDocumentationSampleResource(ResourceType type) |
71 { | |
72 switch (type) | |
73 { | |
74 case Orthanc::ResourceType_Instance: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
75 return "https://orthanc.uclouvain.be/demo/instances/6582b1c0-292ad5ab-ba0f088f-f7a1766f-9a29a54f"; |
4415 | 76 break; |
77 | |
78 case Orthanc::ResourceType_Series: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
79 return "https://orthanc.uclouvain.be/demo/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52"; |
4415 | 80 break; |
81 | |
82 case Orthanc::ResourceType_Study: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
83 return "https://orthanc.uclouvain.be/demo/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988"; |
4415 | 84 break; |
85 | |
86 case Orthanc::ResourceType_Patient: | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
87 return "https://orthanc.uclouvain.be/demo/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382"; |
4415 | 88 break; |
89 | |
90 default: | |
91 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
92 } | |
93 } | |
94 | |
95 | |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
96 static void AnswerDicomAsJson(RestApiCall& call, |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
97 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
|
98 DicomToJsonFormat mode) |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
99 { |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
100 if (mode != DicomToJsonFormat_Full) |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
101 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
102 Json::Value simplified; |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
103 Toolbox::SimplifyDicomAsJson(simplified, dicom, mode); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
104 call.GetOutput().AnswerJson(simplified); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
105 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
106 else |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
107 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
108 call.GetOutput().AnswerJson(dicom); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
109 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
110 } |
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 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
|
114 const RestApiGetCall& call, |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
115 const std::string& argument) |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
116 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
117 target.clear(); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
118 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
119 if (call.HasArgument(argument)) |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
120 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
121 std::vector<std::string> tags; |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
122 Toolbox::TokenizeString(tags, call.GetArgument(argument, ""), ','); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
123 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
124 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
|
125 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
126 target.insert(FromDcmtkBridge::ParseTag(tags[i])); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
127 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
128 } |
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 |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
132 static bool ExpandResource(Json::Value& target, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
133 ServerIndex& index, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
134 ResourceType level, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
135 const std::string& identifier, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
136 DicomToJsonFormat format, |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
137 bool retrieveMetadata) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
138 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
139 ResourceFinder finder(level, true /* expand */); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
140 finder.SetOrthancId(level, identifier); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
141 finder.SetRetrieveMetadata(retrieveMetadata); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
142 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
143 FindResponse response; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
144 finder.Execute(response, index); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
145 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
146 if (response.GetSize() != 1) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
147 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
148 return false; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
149 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
150 else |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
151 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
152 const FindResponse::Resource& resource = response.GetResourceByIndex(0); |
5709
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
153 finder.Expand(target, resource, index, format); |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
154 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
155 if (retrieveMetadata) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
156 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
157 const std::map<MetadataType, std::string>& metadata = resource.GetMetadata(level); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
158 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
159 Json::Value tmp; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
160 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
161 for (std::map<MetadataType, std::string>::const_iterator |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
162 it = metadata.begin(); it != metadata.end(); ++it) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
163 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
164 tmp[EnumerationToString(it->first)] = it->second; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
165 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
166 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
167 target["Metadata"] = tmp; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
168 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
169 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
170 return true; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
171 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
172 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
173 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
174 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 // List all the patients, studies, series or instances ---------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
177 static void AnswerListOfResources1(RestApiOutput& output, |
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
|
178 ServerContext& context, |
1354 | 179 const std::list<std::string>& resources, |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
180 const std::map<std::string, std::string>& instancesIds, // optional: the id of an instance for each found resource. |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
181 const std::map<std::string, boost::shared_ptr<DicomMap> >& resourcesMainDicomTags, // optional: all tags read from DB for a resource (current level and upper levels) |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
182 const std::map<std::string, boost::shared_ptr<Json::Value> >& resourcesDicomAsJson, // optional: the dicom-as-json for each resource |
1354 | 183 ResourceType level, |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
184 bool expand, |
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
|
185 DicomToJsonFormat format, |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
186 const std::set<DicomTag>& requestedTags, |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
187 bool allowStorageAccess) |
1354 | 188 { |
189 Json::Value answer = Json::arrayValue; | |
190 | |
191 for (std::list<std::string>::const_iterator | |
1384 | 192 resource = resources.begin(); resource != resources.end(); ++resource) |
1354 | 193 { |
194 if (expand) | |
195 { | |
4554 | 196 Json::Value expanded; |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
197 |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
198 std::map<std::string, std::string>::const_iterator instanceId = instancesIds.find(*resource); |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
199 if (instanceId != instancesIds.end()) // if it is found in instancesIds, it is also in resourcesDicomAsJson and mainDicomTags |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
200 { |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
201 // reuse data already collected before (e.g during lookup) |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
202 std::map<std::string, boost::shared_ptr<DicomMap> >::const_iterator mainDicomTags = resourcesMainDicomTags.find(*resource); |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
203 std::map<std::string, boost::shared_ptr<Json::Value> >::const_iterator dicomAsJson = resourcesDicomAsJson.find(*resource); |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
204 |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
205 context.ExpandResource(expanded, *resource, |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
206 *(mainDicomTags->second.get()), |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
207 instanceId->second, |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
208 dicomAsJson->second.get(), |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
209 level, format, requestedTags, allowStorageAccess); |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
210 } |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
211 else |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
212 { |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
213 context.ExpandResource(expanded, *resource, level, format, requestedTags, allowStorageAccess); |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
214 } |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
215 |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
216 if (expanded.type() == Json::objectValue) |
1354 | 217 { |
4554 | 218 answer.append(expanded); |
1354 | 219 } |
220 } | |
221 else | |
222 { | |
223 answer.append(*resource); | |
224 } | |
225 } | |
226 | |
227 output.AnswerJson(answer); | |
228 } | |
229 | |
230 | |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
231 static void AnswerListOfResources2(RestApiOutput& output, |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
232 ServerContext& context, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
233 const std::list<std::string>& resources, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
234 ResourceType level, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
235 bool expand, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
236 DicomToJsonFormat format, |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
237 const std::set<DicomTag>& requestedTags, |
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
238 bool allowStorageAccess) |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
239 { |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
240 std::map<std::string, std::string> unusedInstancesIds; |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
241 std::map<std::string, boost::shared_ptr<DicomMap> > unusedResourcesMainDicomTags; |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
242 std::map<std::string, boost::shared_ptr<Json::Value> > unusedResourcesDicomAsJson; |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
243 |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
244 AnswerListOfResources1(output, context, resources, unusedInstancesIds, unusedResourcesMainDicomTags, unusedResourcesDicomAsJson, level, expand, format, requestedTags, allowStorageAccess); |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
245 } |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
246 |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
247 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 template <enum ResourceType resourceType> |
974 | 249 static void ListResources(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 { |
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
|
251 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
|
252 { |
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
|
253 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
|
254 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
|
255 |
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
|
256 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
|
257 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
|
258 .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
|
259 .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
|
260 .SetDescription("List the Orthanc identifiers of all the available DICOM " + resources) |
4403 | 261 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) |
262 .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
|
263 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, |
4403 | 264 "If present, retrieve detailed information about the individual " + resources, false) |
4404 | 265 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " |
266 "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
|
267 .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
|
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 |
1342
9ec7ac03152d
"?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1303
diff
changeset
|
271 ServerIndex& index = OrthancRestApi::GetIndex(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
|
272 ServerContext& context = OrthancRestApi::GetContext(call); |
1342
9ec7ac03152d
"?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1303
diff
changeset
|
273 |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
274 if (true) |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
275 { |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
276 /** |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
277 * EXPERIMENTAL VERSION |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
278 **/ |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
279 |
5574
5a13483d12c5
find-refactoring: attachments
Alain Mazy <am@orthanc.team>
parents:
5569
diff
changeset
|
280 // TODO-FIND: include the FindRequest options parsing in a method (parse from get-arguments and from post payload) |
5a13483d12c5
find-refactoring: attachments
Alain Mazy <am@orthanc.team>
parents:
5569
diff
changeset
|
281 // TODO-FIND: support other values for expand like expand=MainDicomTags,Labels,Parent,SeriesStatus |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
282 const bool expand = (call.HasArgument("expand") && |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
283 call.GetBooleanArgument("expand", true)); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
284 |
5574
5a13483d12c5
find-refactoring: attachments
Alain Mazy <am@orthanc.team>
parents:
5569
diff
changeset
|
285 std::set<DicomTag> requestedTags; |
5a13483d12c5
find-refactoring: attachments
Alain Mazy <am@orthanc.team>
parents:
5569
diff
changeset
|
286 OrthancRestApi::GetRequestedTags(requestedTags, call); |
5a13483d12c5
find-refactoring: attachments
Alain Mazy <am@orthanc.team>
parents:
5569
diff
changeset
|
287 |
5600
8796c100aaf8
introduction of ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5596
diff
changeset
|
288 ResourceFinder finder(resourceType, expand); |
5609
4690a0d2b01e
preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5608
diff
changeset
|
289 finder.AddRequestedTags(requestedTags); |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
290 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
291 if (call.HasArgument("limit") || |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
292 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
|
293 { |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
294 if (!call.HasArgument("limit")) |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
295 { |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
296 throw OrthancException(ErrorCode_BadRequest, |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
297 "Missing \"limit\" argument for GET request against: " + |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
298 call.FlattenUri()); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
299 } |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
300 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
301 if (!call.HasArgument("since")) |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
302 { |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
303 throw OrthancException(ErrorCode_BadRequest, |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
304 "Missing \"since\" argument for GET request against: " + |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
305 call.FlattenUri()); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
306 } |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
307 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
308 uint64_t since = boost::lexical_cast<uint64_t>(call.GetArgument("since", "")); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
309 uint64_t limit = boost::lexical_cast<uint64_t>(call.GetArgument("limit", "")); |
5693 | 310 finder.SetLimitsSince(since); |
311 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
|
312 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
313 |
5600
8796c100aaf8
introduction of ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5596
diff
changeset
|
314 Json::Value answer; |
5709
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
315 finder.Execute(answer, context, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human)); |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
316 call.GetOutput().AnswerJson(answer); |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
317 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
318 else |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
319 { |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
320 /** |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
321 * VERSION IN ORTHANC <= 1.12.4 |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
322 **/ |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
323 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
324 std::list<std::string> result; |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
325 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
326 std::set<DicomTag> requestedTags; |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
327 OrthancRestApi::GetRequestedTags(requestedTags, call); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
328 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
329 if (call.HasArgument("limit") || |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
330 call.HasArgument("since")) |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
331 { |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
332 if (!call.HasArgument("limit")) |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
333 { |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
334 throw OrthancException(ErrorCode_BadRequest, |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
335 "Missing \"limit\" argument for GET request against: " + |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
336 call.FlattenUri()); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
337 } |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
338 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
339 if (!call.HasArgument("since")) |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
340 { |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
341 throw OrthancException(ErrorCode_BadRequest, |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
342 "Missing \"since\" argument for GET request against: " + |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
343 call.FlattenUri()); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
344 } |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
345 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
346 size_t since = boost::lexical_cast<size_t>(call.GetArgument("since", "")); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
347 size_t limit = boost::lexical_cast<size_t>(call.GetArgument("limit", "")); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
348 index.GetAllUuids(result, resourceType, since, limit); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
349 } |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
350 else |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
351 { |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
352 index.GetAllUuids(result, resourceType); |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
353 } |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
354 |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
355 AnswerListOfResources2(call.GetOutput(), context, result, resourceType, call.HasArgument("expand") && call.GetBooleanArgument("expand", true), |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
356 OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human), |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
357 requestedTags, |
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
358 true /* allowStorageAccess */); |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
359 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 |
4409 | 362 |
363 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 template <enum ResourceType resourceType> |
974 | 365 static void GetSingleResource(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 { |
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
|
367 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
|
368 { |
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
|
369 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
|
370 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
|
371 |
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
|
372 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
|
373 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
|
374 .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
|
375 .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
|
376 .SetDescription("Get detailed information about the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
4404 | 377 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
4409 | 378 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) |
379 .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
|
380 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
|
381 } |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
382 |
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
|
383 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
|
384 |
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
|
385 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
|
386 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
|
387 |
5615
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
388 if (true) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 { |
5615
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
390 /** |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
391 * EXPERIMENTAL VERSION |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
392 **/ |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
393 |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
394 ResourceFinder finder(resourceType, true /* expand */); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
395 finder.AddRequestedTags(requestedTags); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
396 finder.SetOrthancId(resourceType, call.GetUriComponent("id", "")); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
397 |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
398 Json::Value json; |
5709
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
399 if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format)) |
5615
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
400 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
401 call.GetOutput().AnswerJson(json); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
402 } |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
403 } |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
404 else |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
405 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
406 /** |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
407 * VERSION IN ORTHANC <= 1.12.4 |
5615
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
408 **/ |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
409 |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
410 Json::Value json; |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
411 if (OrthancRestApi::GetContext(call).ExpandResource( |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
412 json, call.GetUriComponent("id", ""), resourceType, format, requestedTags, true /* allowStorageAccess */)) |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
413 { |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
414 call.GetOutput().AnswerJson(json); |
a10978a5e65c
expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5609
diff
changeset
|
415 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 template <enum ResourceType resourceType> |
974 | 420 static void DeleteSingleResource(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 { |
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
|
422 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
|
423 { |
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
|
424 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
|
425 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
|
426 .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
|
427 .SetSummary("Delete some " + resource) |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
428 .SetDescription("Delete the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
4404 | 429 .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
|
430 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
|
431 } |
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
|
432 |
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
|
433 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
|
434 if (OrthancRestApi::GetContext(call).DeleteResource(remainingAncestor, call.GetUriComponent("id", ""), resourceType)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 { |
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
|
436 call.GetOutput().AnswerJson(remainingAncestor); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
439 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
440 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 // Get information about a single patient ----------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 |
974 | 443 static void IsProtectedPatient(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 { |
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
|
445 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
|
446 { |
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
|
447 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
|
448 .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
|
449 .SetSummary("Is the patient protected against recycling?") |
4404 | 450 .SetUriArgument("id", "Orthanc identifier of the patient of interest") |
4403 | 451 .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
|
452 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
|
453 } |
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
|
454 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
455 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
456 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
457 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
459 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
460 |
974 | 461 static void SetPatientProtection(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
462 { |
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
|
463 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
|
464 { |
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
|
465 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
|
466 .SetTag("Patients") |
5467
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5446
diff
changeset
|
467 .SetSummary("Protect/Unprotect a patient against recycling") |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5446
diff
changeset
|
468 .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
|
469 "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
|
470 "More info: https://orthanc.uclouvain.be/book/faq/features.html#recycling-protection") |
4404 | 471 .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
|
472 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
|
473 } |
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
|
474 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
476 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
477 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
478 |
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
|
479 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
|
480 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
481 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
482 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
483 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
484 // Get information about a single instance ---------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
485 |
974 | 486 static void GetInstanceFile(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 { |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
488 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
|
489 |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
490 if (call.IsDocumentation()) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
491 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
492 call.GetDocumentation() |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
493 .SetTag("Instances") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
494 .SetSummary("Download DICOM") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
495 .SetDescription("Download one DICOM instance") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
496 .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
|
497 .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
|
498 .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
|
499 "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
|
500 "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
|
501 .AddAnswerType(MimeType_Dicom, "The DICOM instance") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
502 .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
|
503 .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
|
504 return; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
505 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
506 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
507 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
508 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
509 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
|
510 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4294
diff
changeset
|
511 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
|
512 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
|
513 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
514 // 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
|
515 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
|
516 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
517 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
|
518 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
519 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
|
520 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
|
521 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
522 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
|
523 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
524 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
525 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
|
526 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
|
527 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
528 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
529 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
|
530 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
531 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
|
532 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
|
533 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
534 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
|
535 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
540 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
541 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
|
542 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
543 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
544 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
|
545 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
546 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
547 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
548 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
549 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
|
550 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
551 std::string source; |
5427 | 552 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
|
553 std::string transcoded; |
5427 | 554 context.ReadDicom(source, attachmentId, publicId); |
555 | |
556 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
|
557 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
558 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
|
559 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
560 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
561 else |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
562 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
563 // 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
|
564 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
|
565 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
566 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
567 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
568 |
974 | 569 static void ExportInstanceFile(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
570 { |
4421 | 571 if (call.IsDocumentation()) |
572 { | |
573 call.GetDocumentation() | |
574 .SetTag("Instances") | |
575 .SetSummary("Write DICOM onto filesystem") | |
5200
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
576 .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
|
577 "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
|
578 "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
|
579 "the `RestApiWriteToFileSystemEnabled` configuration option.") |
4421 | 580 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
581 .AddRequestType(MimeType_PlainText, "Target path on the filesystem"); | |
582 return; | |
583 } | |
584 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
585 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
586 |
5200
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
587 if (!context.IsRestApiWriteToFileSystemEnabled()) |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
588 { |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
589 LOG(ERROR) << "The URI /instances/../export is disallowed for security, " |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
590 << "check your configuration option `RestApiWriteToFileSystemEnabled`"; |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
591 call.GetOutput().SignalError(HttpStatus_403_Forbidden); |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
592 return; |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
593 } |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
594 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
595 std::string publicId = call.GetUriComponent("id", ""); |
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 std::string dicom; |
2124 | 598 context.ReadDicom(dicom, publicId); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
599 |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
600 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
|
601 call.BodyToString(target); |
2140 | 602 SystemToolbox::WriteFile(dicom, target); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
603 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
604 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
605 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
606 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
607 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
608 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
|
609 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
|
610 bool whole) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
611 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
612 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
613 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
614 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
|
615 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
616 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
|
617 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
|
618 |
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
|
619 if (whole) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
620 { |
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
|
621 // 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
|
622 // 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
|
623 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
|
624 |
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
|
625 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
|
626 |
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
|
627 { |
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
|
628 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
|
629 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
|
630 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
|
631 } |
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
|
632 |
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
|
633 call.GetOutput().AnswerJson(answer); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
634 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
635 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
636 { |
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
|
637 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
|
638 !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
|
639 { |
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
|
640 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
|
641 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
|
642 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
|
643 } |
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
|
644 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
|
645 { |
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
|
646 // 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
|
647 // 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
|
648 // 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
|
649 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
|
650 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
|
651 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
|
652 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
653 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
654 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
655 |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
656 |
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
|
657 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
|
658 { |
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
|
659 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
|
660 .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
|
661 .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
|
662 .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
|
663 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
|
664 "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
|
665 .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
|
666 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
|
667 "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
|
668 "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
|
669 "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
|
670 .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
|
671 } |
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
|
672 |
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
|
673 |
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
|
674 static void GetInstanceTags(RestApiGetCall& call) |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
675 { |
4404 | 676 if (call.IsDocumentation()) |
677 { | |
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
|
678 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
|
679 DocumentGetInstanceTags(call); |
4404 | 680 call.GetDocumentation() |
681 .SetSummary("Get DICOM tags") | |
682 .SetDescription("Get the DICOM tags in the specified format. By default, the `full` format is used, which " | |
683 "combines hexadecimal tags with human-readable description.") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
684 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10); |
4404 | 685 return; |
686 } | |
687 | |
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
|
688 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
|
689 |
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
|
690 switch (OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)) |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
691 { |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
692 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
|
693 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
|
694 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
695 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
696 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
|
697 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
|
698 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
699 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
700 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
|
701 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
|
702 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
703 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
704 default: |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
705 throw OrthancException(ErrorCode_InternalError); |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
706 } |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
707 } |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
708 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
709 |
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
|
710 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
|
711 { |
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
|
712 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
|
713 { |
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
|
714 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
|
715 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
|
716 .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
|
717 .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
|
718 .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
|
719 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
|
720 } |
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
|
721 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
|
722 { |
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
|
723 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
|
724 } |
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
|
725 } |
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
|
726 |
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
|
727 |
974 | 728 static void ListFrames(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
729 { |
4414 | 730 if (call.IsDocumentation()) |
731 { | |
732 call.GetDocumentation() | |
733 .SetTag("Instances") | |
734 .SetSummary("List available frames") | |
735 .SetDescription("List the frames that are available in the DICOM instance of interest") | |
736 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
737 .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
|
738 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/frames", true); |
4414 | 739 return; |
740 } | |
741 | |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
742 std::string publicId = call.GetUriComponent("id", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
743 |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
744 unsigned int numberOfFrames; |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
745 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
746 { |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
747 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
|
748 numberOfFrames = locker.GetDicom().GetFramesCount(); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
749 } |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
750 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
751 Json::Value result = Json::arrayValue; |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
752 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
|
753 { |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
754 result.append(i); |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
755 } |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
756 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
757 call.GetOutput().AnswerJson(result); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
758 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
759 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
760 |
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
|
761 namespace |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
762 { |
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
|
763 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
|
764 { |
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
|
765 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
766 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
|
767 ImageExtractionMode mode_; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
768 bool invert_; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
769 MimeType format_; |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
770 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
|
771 |
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
|
772 public: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
773 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
|
774 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
775 bool invert) : |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
776 image_(image), |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
777 mode_(mode), |
4205 | 778 invert_(invert), |
779 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
|
780 { |
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
|
781 } |
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
|
782 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
783 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
|
784 { |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
785 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
|
786 } |
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
|
787 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
788 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
|
789 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
790 format_ = MimeType_Png; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
791 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
|
792 } |
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
|
793 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
794 void EncodeUsingPam() |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
795 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
796 format_ = MimeType_Pam; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
797 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
|
798 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
799 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
800 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
|
801 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
802 format_ = MimeType_Jpeg; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
803 DicomImageDecoder::ExtractJpegImage(answer_, image_, mode_, invert_, quality); |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1784
diff
changeset
|
804 } |
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
|
805 }; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
806 |
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
|
807 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
|
808 { |
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
|
809 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
|
810 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
|
811 |
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
|
812 public: |
4205 | 813 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
|
814 { |
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
|
815 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
816 |
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
|
817 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
|
818 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
819 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
|
820 { |
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
|
821 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
|
822 assert(subtype == "png"); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
823 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
|
824 } |
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
|
825 }; |
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
|
826 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
827 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
|
828 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
829 private: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
830 ImageToEncode& image_; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
831 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
832 public: |
4205 | 833 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
|
834 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
835 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
836 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
837 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
|
838 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
839 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
|
840 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
841 assert(type == "image"); |
2780 | 842 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
|
843 image_.EncodeUsingPam(); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
844 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
845 }; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
846 |
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
|
847 class EncodeJpeg : public HttpContentNegociation::IHandler |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
848 { |
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
|
849 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
|
850 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
|
851 unsigned int quality_; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
852 |
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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 { |
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
|
858 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
|
859 bool ok = false; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
860 |
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
|
861 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
|
862 { |
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
|
863 quality_ = boost::lexical_cast<unsigned int>(v); |
1847 | 864 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
|
865 } |
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
|
866 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
|
867 { |
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
|
868 } |
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
|
869 |
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
|
870 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
|
871 { |
2955 | 872 throw OrthancException( |
873 ErrorCode_BadRequest, | |
874 "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
|
875 } |
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
|
876 } |
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
|
877 |
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
|
878 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
|
879 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
880 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
|
881 { |
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
|
882 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
|
883 assert(subtype == "jpeg"); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
884 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
|
885 } |
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
|
886 }; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
887 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
888 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
889 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
890 namespace |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
891 { |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
892 class IDecodedFrameHandler : public boost::noncopyable |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
893 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
894 public: |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
895 virtual ~IDecodedFrameHandler() |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
896 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
897 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
898 |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
899 // "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
|
900 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
|
901 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
|
902 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
903 unsigned int frame) = 0; |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
904 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
905 virtual bool RequiresDicomTags() const = 0; |
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 static void Apply(RestApiGetCall& call, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
908 IDecodedFrameHandler& handler, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
909 ImageExtractionMode mode /* for generation of documentation */, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
910 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
|
911 { |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
912 if (call.IsDocumentation()) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
913 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
914 std::string m; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
915 if (!isRendered) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
916 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
917 switch (mode) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
918 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
919 case ImageExtractionMode_Preview: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
920 m = "preview"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
921 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
922 case ImageExtractionMode_UInt8: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
923 m = "uint8"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
924 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
925 case ImageExtractionMode_UInt16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
926 m = "uint16"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
927 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
928 case ImageExtractionMode_Int16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
929 m = "int16"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
930 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
931 default: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
932 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
933 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
934 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
935 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
936 std::string description; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
937 std::string verb = (isRendered ? "Render" : "Decode"); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
938 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
939 if (call.HasUriComponent("frame")) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
940 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
941 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
|
942 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
943 .SetSummary(verb + " a frame" + (m.empty() ? "" : " (" + m + ")")) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
944 .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
|
945 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
946 else |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
947 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
948 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
|
949 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
950 .SetSummary(verb + " an image" + (m.empty() ? "" : " (" + m + ")")); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
951 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
952 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
953 if (isRendered) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
954 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
955 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
|
956 "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
|
957 "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
|
958 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
959 .SetHttpGetArgument("window-center",RestApiCallDocumentation::Type_Number, "Windowing center", false) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
960 .SetHttpGetArgument("window-width",RestApiCallDocumentation::Type_Number, "Windowing width", false) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
961 .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
|
962 .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
|
963 .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
|
964 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
965 else |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
966 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
967 switch (mode) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
968 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
969 case ImageExtractionMode_Preview: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
970 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
|
971 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
972 case ImageExtractionMode_UInt8: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
973 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
|
974 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
975 case ImageExtractionMode_UInt16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
976 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
|
977 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
978 case ImageExtractionMode_Int16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
979 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
|
980 "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
|
981 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
982 default: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
983 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
984 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
985 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
986 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
987 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
988 .SetTag("Instances") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
989 .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
|
990 .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
|
991 .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
|
992 .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
|
993 .AddAnswerType(MimeType_Png, "PNG image") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
994 .AddAnswerType(MimeType_Jpeg, "JPEG image") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
995 .AddAnswerType(MimeType_Pam, "PAM image (Portable Arbitrary Map)") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
996 .SetDescription(description); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
997 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
998 return; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
999 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1000 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1001 ServerContext& context = OrthancRestApi::GetContext(call); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1002 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1003 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
|
1004 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1005 unsigned int frame; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1006 try |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1007 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1008 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
|
1009 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1010 catch (boost::bad_lexical_cast&) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1011 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1012 return; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1013 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1014 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1015 std::unique_ptr<ImageAccessor> decoded; |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1016 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1017 try |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1018 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1019 std::string publicId = call.GetUriComponent("id", ""); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1020 |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1021 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
|
1022 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1023 if (decoded.get() == NULL) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1024 { |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1025 throw OrthancException(ErrorCode_NotImplemented, |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1026 "Cannot decode DICOM instance with ID: " + publicId); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1027 } |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1028 |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1029 if (handler.RequiresDicomTags()) |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1030 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1031 /** |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1032 * Retrieve a summary of the DICOM tags, which is |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1033 * necessary to deal with MONOCHROME1 photometric |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1034 * interpretation, and with windowing parameters. |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1035 **/ |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1036 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
|
1037 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
|
1038 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1039 else |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1040 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1041 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
|
1042 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1043 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1044 catch (OrthancException& e) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1045 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1046 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange || |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1047 e.GetErrorCode() == ErrorCode_UnknownResource) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1048 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1049 // 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
|
1050 // instance, the resource is not existent |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1051 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1052 else |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1053 { |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1054 if (call.HasArgument("returnUnsupportedImage")) |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1055 { |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1056 std::string root = ""; |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1057 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
|
1058 { |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1059 root += "../"; |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1060 } |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1061 |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1062 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
|
1063 } |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1064 else |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1065 { |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1066 call.GetOutput().SignalError(HttpStatus_415_UnsupportedMediaType); |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
1067 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1068 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1069 return; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1070 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1071 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1072 } |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1073 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1074 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1075 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
|
1076 std::unique_ptr<ImageAccessor>& decoded, |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1077 ImageExtractionMode mode, |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1078 bool invert) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1079 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1080 ImageToEncode image(decoded, mode, invert); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1081 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1082 HttpContentNegociation negociation; |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1083 EncodePng png(image); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1084 negociation.Register(MIME_PNG, png); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1085 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1086 EncodeJpeg jpeg(image, call); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1087 negociation.Register(MIME_JPEG, jpeg); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1088 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1089 EncodePam pam(image); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1090 negociation.Register(MIME_PAM, pam); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1091 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1092 if (negociation.Apply(call.GetHttpHeaders())) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1093 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1094 image.Answer(call.GetOutput()); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1095 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1096 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1097 }; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1098 |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1099 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1100 class GetImageHandler : public IDecodedFrameHandler |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1101 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1102 private: |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1103 ImageExtractionMode mode_; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1104 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1105 public: |
4205 | 1106 explicit GetImageHandler(ImageExtractionMode mode) : |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1107 mode_(mode) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1108 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1109 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1110 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1111 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
|
1112 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
|
1113 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1114 unsigned int frame) ORTHANC_OVERRIDE |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1115 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1116 bool invert = false; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1117 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1118 if (mode_ == ImageExtractionMode_Preview) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1119 { |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1120 if (dicom == NULL) |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1121 { |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1122 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
|
1123 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1124 |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1125 DicomMap tags; |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1126 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
|
1127 |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1128 DicomImageInformation info(tags); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1129 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1130 } |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1131 |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1132 DefaultHandler(call, decoded, mode_, invert); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1133 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1134 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1135 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1136 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1137 return mode_ == ImageExtractionMode_Preview; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1138 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1139 }; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1140 |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1141 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1142 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
|
1143 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1144 private: |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1145 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
|
1146 double& windowCenter /* inout */, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1147 unsigned int& argWidth, |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1148 unsigned int& argHeight, |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1149 bool& smooth, |
4205 | 1150 const RestApiGetCall& call) |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1151 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1152 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
|
1153 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
|
1154 static const char* ARG_WIDTH = "width"; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1155 static const char* ARG_HEIGHT = "height"; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1156 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
|
1157 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1158 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
|
1159 !SerializationToolbox::ParseDouble(windowWidth, call.GetArgument(ARG_WINDOW_WIDTH, ""))) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1160 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1161 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
|
1162 "Bad value for argument: " + std::string(ARG_WINDOW_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1163 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1164 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1165 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
|
1166 !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
|
1167 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1168 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
|
1169 "Bad value for argument: " + std::string(ARG_WINDOW_CENTER)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1170 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1171 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1172 argWidth = 0; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1173 argHeight = 0; |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1174 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1175 if (call.HasArgument(ARG_WIDTH)) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1176 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1177 try |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1178 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1179 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
|
1180 if (tmp < 0) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1181 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1182 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1183 "Argument cannot be negative: " + std::string(ARG_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1184 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1185 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1186 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1187 argWidth = static_cast<unsigned int>(tmp); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1188 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1189 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1190 catch (boost::bad_lexical_cast&) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1191 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1192 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1193 "Bad value for argument: " + std::string(ARG_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1194 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1195 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1196 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1197 if (call.HasArgument(ARG_HEIGHT)) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1198 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1199 try |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1200 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1201 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
|
1202 if (tmp < 0) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1203 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1204 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1205 "Argument cannot be negative: " + std::string(ARG_HEIGHT)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1206 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1207 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1208 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1209 argHeight = static_cast<unsigned int>(tmp); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1210 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1211 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1212 catch (boost::bad_lexical_cast&) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1213 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1214 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1215 "Bad value for argument: " + std::string(ARG_HEIGHT)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1216 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1217 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1218 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1219 smooth = false; |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1220 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1221 if (call.HasArgument(ARG_SMOOTH)) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1222 { |
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
|
1223 smooth = RestApiCall::ParseBoolean(call.GetArgument(ARG_SMOOTH, "")); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1224 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1225 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1226 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1227 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1228 public: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1229 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
|
1230 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
|
1231 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1232 unsigned int frame) ORTHANC_OVERRIDE |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1233 { |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1234 if (dicom == NULL) |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1235 { |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1236 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
|
1237 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1238 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1239 PhotometricInterpretation photometric; |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1240 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
|
1241 photometric == PhotometricInterpretation_Monochrome1); |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1242 |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1243 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
|
1244 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
|
1245 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
|
1246 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1247 unsigned int argWidth, argHeight; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1248 bool smooth; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1249 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
|
1250 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1251 unsigned int targetWidth = decoded->GetWidth(); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1252 unsigned int targetHeight = decoded->GetHeight(); |
3686 | 1253 |
1254 if (decoded->GetWidth() != 0 && | |
1255 decoded->GetHeight() != 0) | |
1256 { | |
1257 float ratio = 1; | |
1258 | |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1259 if (argWidth != 0 && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1260 argHeight != 0) |
3686 | 1261 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1262 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
|
1263 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
|
1264 ratio = std::min(ratioX, ratioY); |
3686 | 1265 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1266 else if (argWidth != 0) |
3686 | 1267 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1268 ratio = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth()); |
3686 | 1269 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1270 else if (argHeight != 0) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1271 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1272 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
|
1273 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1274 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1275 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
|
1276 targetHeight = boost::math::iround(ratio * static_cast<float>(decoded->GetHeight())); |
3686 | 1277 } |
1278 | |
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
|
1279 if (decoded->GetFormat() == PixelFormat_RGB24 || decoded->GetFormat() == PixelFormat_RGB48) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1280 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1281 if (targetWidth == decoded->GetWidth() && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1282 targetHeight == decoded->GetHeight()) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1283 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1284 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1285 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1286 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1287 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1288 std::unique_ptr<ImageAccessor> resized( |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1289 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
|
1290 |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1291 if (smooth && |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1292 (targetWidth < decoded->GetWidth() || |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1293 targetHeight < decoded->GetHeight())) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1294 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
1295 ImageProcessing::SmoothGaussian5x5(*decoded, false /* be fast, don't round */); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1296 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1297 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1298 ImageProcessing::Resize(*resized, *decoded); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1299 DefaultHandler(call, resized, ImageExtractionMode_Preview, false); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1300 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1301 } |
3686 | 1302 else |
1303 { | |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1304 // 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
|
1305 // 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
|
1306 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1307 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
|
1308 ImageProcessing::Convert(converted, *decoded); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1309 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1310 // Avoid divisions by zero |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1311 if (windowWidth <= 1.0f) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1312 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1313 windowWidth = 1; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1314 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1315 |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1316 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
|
1317 { |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1318 rescaleSlope = 0.0001; |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1319 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1320 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1321 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
|
1322 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
|
1323 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1324 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
|
1325 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
|
1326 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1327 if (targetWidth == decoded->GetWidth() && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1328 targetHeight == decoded->GetHeight()) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1329 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1330 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1331 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1332 else |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1333 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1334 std::unique_ptr<ImageAccessor> resized( |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1335 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
|
1336 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1337 if (smooth && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1338 (targetWidth < decoded->GetWidth() || |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1339 targetHeight < decoded->GetHeight())) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1340 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
1341 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
|
1342 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1343 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1344 ImageProcessing::Resize(*resized, *rescaled); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1345 DefaultHandler(call, resized, ImageExtractionMode_UInt8, invert); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1346 } |
3686 | 1347 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1348 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1349 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1350 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1351 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1352 return true; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1353 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1354 }; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1355 } |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1356 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1357 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1358 template <enum ImageExtractionMode mode> |
974 | 1359 static void GetImage(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1360 { |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1361 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
|
1362 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1363 GetImageHandler handler(mode); |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1364 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
|
1365 } |
1906
d7c1cb559431
optimization for multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1902
diff
changeset
|
1366 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1367 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1368 static void GetRenderedFrame(RestApiGetCall& call) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1369 { |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1370 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
|
1371 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1372 RenderedFrameHandler handler; |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1373 IDecodedFrameHandler::Apply(call, handler, ImageExtractionMode_Preview /* arbitrary value */, true); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1374 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1375 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1376 |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1377 static void DocumentSharedNumpy(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1378 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1379 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1380 .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
|
1381 .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
|
1382 .SetHttpGetArgument("rescale", RestApiCallDocumentation::Type_Boolean, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1383 "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
|
1384 .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
|
1385 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1386 |
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 namespace |
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 class NumpyVisitor : public boost::noncopyable |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1391 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1392 private: |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1393 bool rescale_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1394 unsigned int depth_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1395 unsigned int currentDepth_; |
4858 | 1396 unsigned int width_; |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1397 unsigned int height_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1398 PixelFormat format_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1399 ChunkedBuffer buffer_; |
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 public: |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1402 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
|
1403 bool rescale) : |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1404 rescale_(rescale), |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1405 depth_(depth), |
4858 | 1406 currentDepth_(0), |
1407 width_(0), // dummy initialization | |
1408 height_(0), // dummy initialization | |
1409 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
|
1410 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1411 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1412 |
4858 | 1413 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
|
1414 unsigned int frame) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1415 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1416 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
|
1417 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1418 if (decoded.get() == NULL) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1419 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1420 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
|
1421 } |
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 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1424 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1425 width_ = decoded->GetWidth(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1426 height_ = decoded->GetHeight(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1427 format_ = decoded->GetFormat(); |
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 else if (width_ != decoded->GetWidth() || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1430 height_ != decoded->GetHeight()) |
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 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
|
1433 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1434 else if (format_ != decoded->GetFormat()) |
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 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
|
1437 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1438 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1439 if (rescale_ && |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1440 decoded->GetFormat() != PixelFormat_RGB24) |
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 if (currentDepth_ == 0) |
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 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
|
1445 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1446 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1447 double rescaleIntercept, rescaleSlope; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1448 dicom.GetRescale(rescaleIntercept, rescaleSlope, frame); |
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 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
|
1451 ImageProcessing::Convert(converted, *decoded); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1452 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
|
1453 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1454 NumpyWriter::WritePixels(buffer_, converted); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1455 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1456 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1457 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1458 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1459 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1460 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
|
1461 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1462 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1463 NumpyWriter::WritePixels(buffer_, *decoded); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1464 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1465 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1466 currentDepth_ ++; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1467 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1468 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1469 void Answer(RestApiOutput& output, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1470 bool compress) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1471 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1472 if ((depth_ == 0 && currentDepth_ != 1) || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1473 (depth_ != 0 && currentDepth_ != depth_)) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1474 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1475 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1476 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1477 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1478 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1479 std::string answer; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1480 NumpyWriter::Finalize(answer, buffer_, compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1481 output.AnswerBuffer(answer, MimeType_Binary); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1482 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1483 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1484 }; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1485 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1486 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1487 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1488 static void GetNumpyFrame(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1489 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1490 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1491 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1492 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1493 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1494 .SetTag("Instances") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1495 .SetSummary("Decode frame for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1496 .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
|
1497 "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
|
1498 .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
|
1499 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1500 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1501 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1502 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
|
1503 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
|
1504 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
|
1505 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1506 uint32_t frame; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1507 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
|
1508 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1509 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
|
1510 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1511 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1512 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
|
1513 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1514 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1515 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1516 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
|
1517 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1518 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1519 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1520 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1521 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1522 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1523 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1524 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1525 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1526 static void GetNumpyInstance(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1527 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1528 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1529 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1530 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1531 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1532 .SetTag("Instances") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1533 .SetSummary("Decode instance for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1534 .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
|
1535 "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
|
1536 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1537 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1538 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1539 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
|
1540 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
|
1541 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
|
1542 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1543 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1544 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1545 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
|
1546 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1547 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
|
1548 if (depth == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1549 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1550 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
|
1551 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1552 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1553 NumpyVisitor visitor(depth, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1554 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1555 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
|
1556 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1557 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1558 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1559 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1560 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1561 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1562 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1563 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1564 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1565 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1566 static void GetNumpySeries(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1567 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1568 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1569 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1570 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1571 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1572 .SetTag("Series") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1573 .SetSummary("Decode series for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1574 .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
|
1575 "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
|
1576 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1577 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1578 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1579 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
|
1580 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
|
1581 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
|
1582 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1583 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1584 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1585 ServerIndex& index = OrthancRestApi::GetIndex(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1586 SliceOrdering ordering(index, seriesId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1587 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1588 unsigned int depth = 0; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1589 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
|
1590 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1591 depth += ordering.GetFramesCount(i); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1592 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1593 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1594 ServerContext& context = OrthancRestApi::GetContext(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1595 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1596 NumpyVisitor visitor(depth, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1597 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1598 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
|
1599 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1600 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
|
1601 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
|
1602 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1603 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1604 ServerContext::DicomCacheLocker locker(context, instanceId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1605 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1606 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
|
1607 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1608 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1609 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1610 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1611 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1612 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1613 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1614 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1615 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1616 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1617 |
974 | 1618 static void GetMatlabImage(RestApiGetCall& call) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1619 { |
4414 | 1620 if (call.IsDocumentation()) |
1621 { | |
1622 std::string description; | |
1623 | |
1624 if (call.HasUriComponent("frame")) | |
1625 { | |
1626 description = "Decode one frame of interest from the given DICOM instance"; | |
1627 call.GetDocumentation() | |
1628 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); | |
1629 } | |
1630 else | |
1631 { | |
1632 description = "Decode the first frame of the given DICOM instance."; | |
1633 } | |
1634 | |
1635 call.GetDocumentation() | |
1636 .SetTag("Instances") | |
1637 .SetSummary("Decode frame for Matlab") | |
1638 .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
|
1639 "https://orthanc.uclouvain.be/book/faq/matlab.html") |
4414 | 1640 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
1641 .AddAnswerType(MimeType_PlainText, "Octave/Matlab matrix"); | |
1642 return; | |
1643 } | |
1644 | |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1645 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
|
1646 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1647 ServerContext& context = OrthancRestApi::GetContext(call); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1648 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1649 std::string frameId = call.GetUriComponent("frame", "0"); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1650 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1651 unsigned int frame; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1652 try |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1653 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1654 frame = boost::lexical_cast<unsigned int>(frameId); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1655 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2804
diff
changeset
|
1656 catch (boost::bad_lexical_cast&) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1657 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1658 return; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1659 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1660 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1661 std::string publicId = call.GetUriComponent("id", ""); |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1662 std::unique_ptr<ImageAccessor> decoded(context.DecodeDicomFrame(publicId, frame)); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1663 |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1664 if (decoded.get() == NULL) |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1665 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1666 throw OrthancException(ErrorCode_NotImplemented, |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1667 "Cannot decode DICOM instance with ID: " + publicId); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1668 } |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1669 else |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1670 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1671 std::string result; |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1672 decoded->ToMatlabString(result); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1673 call.GetOutput().AnswerBuffer(result, MimeType_PlainText); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1674 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1675 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1676 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1677 |
2408
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1678 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
|
1679 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
|
1680 { |
4408 | 1681 if (call.IsDocumentation()) |
1682 { | |
1683 call.GetDocumentation() | |
1684 .SetTag("Instances") | |
1685 .SetSummary("Access raw frame" + std::string(GzipCompression ? " (compressed)" : "")) | |
1686 .SetDescription("Access the raw content of one individual frame of the DICOM instance of interest, " | |
1687 "bypassing image decoding. This is notably useful to access the source files " | |
1688 "in compressed transfer syntaxes." + | |
1689 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
|
1690 .SetUriArgument("id", "Orthanc identifier of the instance of interest") |
4408 | 1691 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); |
1692 | |
1693 if (GzipCompression) | |
1694 { | |
1695 call.GetDocumentation().AddAnswerType(MimeType_Gzip, "The raw frame, compressed using gzip"); | |
1696 } | |
1697 else | |
1698 { | |
1699 call.GetDocumentation().AddAnswerType(MimeType_Binary, "The raw frame"); | |
1700 } | |
1701 return; | |
1702 } | |
1703 | |
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
|
1704 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
|
1705 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1706 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
|
1707 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
|
1708 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1709 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
|
1710 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2804
diff
changeset
|
1711 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
|
1712 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1713 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
|
1714 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1715 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1716 std::string publicId = call.GetUriComponent("id", ""); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
1717 std::string raw; |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
1718 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
|
1719 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1720 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1721 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
|
1722 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
|
1723 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1724 |
2408
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1725 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
|
1726 { |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1727 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
|
1728 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
|
1729 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
|
1730 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
|
1731 } |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1732 else |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1733 { |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1734 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
|
1735 } |
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
|
1736 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1737 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1738 |
974 | 1739 static void GetResourceStatistics(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1740 { |
4418 | 1741 if (call.IsDocumentation()) |
1742 { | |
1743 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1744 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1745 call.GetDocumentation() | |
1746 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1747 .SetSummary("Get " + r + " statistics") | |
1748 .SetDescription("Get statistics about the given " + r) | |
1749 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1750 .SetAnswerField("DiskSize", RestApiCallDocumentation::Type_String, | |
1751 "Size of the " + r + " on the disk in bytes, expressed as a string for 64bit compatibility with JSON") | |
1752 .SetAnswerField("DiskSizeMB", RestApiCallDocumentation::Type_Number, | |
1753 "Size of the " + r + " on the disk, expressed in megabytes (MB)") | |
1754 .SetAnswerField("UncompressedSize", RestApiCallDocumentation::Type_String, | |
1755 "Size of the " + r + " after decompression in bytes, expressed as a string for 64bit compatibility with JSON") | |
1756 .SetAnswerField("UncompressedSizeMB", RestApiCallDocumentation::Type_Number, | |
1757 "Size of the " + r + " after decompression, expressed in megabytes (MB). " | |
1758 "This is different from `DiskSizeMB` iff `StorageCompression` is `true`.") | |
1759 .SetAnswerField("DicomDiskSize", RestApiCallDocumentation::Type_String, | |
1760 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in bytes") | |
1761 .SetAnswerField("DicomDiskSizeMB", RestApiCallDocumentation::Type_Number, | |
1762 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in megabytes (MB)") | |
1763 .SetAnswerField("DicomUncompressedSize", RestApiCallDocumentation::Type_String, | |
1764 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in bytes") | |
1765 .SetAnswerField("DicomUncompressedSizeMB", RestApiCallDocumentation::Type_Number, | |
1766 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in megabytes (MB)") | |
1767 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/statistics", true); | |
1768 | |
1769 switch (t) | |
1770 { | |
1771 // Do NOT add "break" below this point! | |
1772 case ResourceType_Patient: | |
1773 call.GetDocumentation().SetAnswerField("CountStudies", RestApiCallDocumentation::Type_Number, | |
1774 "Number of child studies within this " + r); | |
1775 | |
1776 case ResourceType_Study: | |
1777 call.GetDocumentation().SetAnswerField("CountSeries", RestApiCallDocumentation::Type_Number, | |
1778 "Number of child series within this " + r); | |
1779 | |
1780 case ResourceType_Series: | |
1781 call.GetDocumentation().SetAnswerField("CountInstances", RestApiCallDocumentation::Type_Number, | |
1782 "Number of child instances within this " + r); | |
1783 | |
1784 case ResourceType_Instance: | |
1785 default: | |
1786 break; | |
1787 } | |
1788 | |
1789 return; | |
1790 } | |
1791 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1792 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
|
1793 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1794 std::string publicId = call.GetUriComponent("id", ""); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1795 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1796 ResourceType type; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1797 uint64_t diskSize, uncompressedSize, dicomDiskSize, dicomUncompressedSize; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1798 unsigned int countStudies, countSeries, countInstances; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1799 OrthancRestApi::GetIndex(call).GetResourceStatistics( |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1800 type, diskSize, uncompressedSize, countStudies, countSeries, |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1801 countInstances, dicomDiskSize, dicomUncompressedSize, publicId); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1802 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1803 Json::Value result = Json::objectValue; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1804 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
|
1805 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
|
1806 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
|
1807 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
|
1808 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1809 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
|
1810 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
|
1811 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
|
1812 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
|
1813 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1814 switch (type) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1815 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1816 // Do NOT add "break" below this point! |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1817 case ResourceType_Patient: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1818 result["CountStudies"] = countStudies; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1819 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1820 case ResourceType_Study: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1821 result["CountSeries"] = countSeries; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1822 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1823 case ResourceType_Series: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1824 result["CountInstances"] = countInstances; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1825 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1826 case ResourceType_Instance: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1827 default: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1828 break; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1829 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1830 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1831 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1832 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1833 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1834 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1835 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1836 // Handling of metadata ----------------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1837 |
4205 | 1838 static void CheckValidResourceType(const RestApiCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1839 { |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1840 assert(!call.GetFullUri().empty()); |
4409 | 1841 const std::string resourceType = call.GetFullUri() [0]; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1842 StringToResourceType(resourceType.c_str()); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1843 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1844 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1845 |
974 | 1846 static void ListMetadata(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1847 { |
4414 | 1848 if (call.IsDocumentation()) |
1849 { | |
1850 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1851 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1852 call.GetDocumentation() | |
1853 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1854 .SetSummary("List metadata") | |
1855 .SetDescription("Get the list of metadata that are associated with the given " + r) | |
1856 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1857 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, | |
1858 "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
|
1859 .SetHttpGetArgument("numeric", RestApiCallDocumentation::Type_String, |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1860 "If present, use the numeric identifier of the metadata instead of its symbolic name", false) |
4414 | 1861 .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, " |
1862 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") | |
1863 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); | |
1864 return; | |
1865 } | |
1866 | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1867 assert(!call.GetFullUri().empty()); |
4554 | 1868 const std::string publicId = call.GetUriComponent("id", ""); |
1869 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1870 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1871 typedef std::map<MetadataType, std::string> Metadata; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1872 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1873 Metadata metadata; |
4554 | 1874 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
|
1875 |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1876 Json::Value result; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1877 |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1878 bool isNumeric = call.HasArgument("numeric"); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1879 |
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
|
1880 if (call.HasArgument("expand") && call.GetBooleanArgument("expand", true)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1881 { |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1882 result = Json::objectValue; |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1883 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1884 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
|
1885 { |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1886 std::string key; |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1887 if (isNumeric) |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1888 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1889 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
|
1890 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1891 else |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1892 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1893 key = EnumerationToString(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1894 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1895 |
3187
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
1896 result[key] = it->second; |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1897 } |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1898 } |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1899 else |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1900 { |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1901 result = Json::arrayValue; |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1902 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1903 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
|
1904 { |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1905 if (isNumeric) |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1906 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1907 result.append(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1908 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1909 else |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1910 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1911 result.append(EnumerationToString(it->first)); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1912 } |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1913 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1914 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1915 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1916 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1917 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1918 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1919 |
4657 | 1920 static void SetStringContentETag(const RestApiOutput& output, |
1921 int64_t revision, | |
1922 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
|
1923 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1924 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
|
1925 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
|
1926 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
|
1927 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
|
1928 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1929 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1930 |
4657 | 1931 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
|
1932 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
|
1933 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
|
1934 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
|
1935 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1936 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
|
1937 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
|
1938 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
|
1939 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
|
1940 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1941 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1942 |
4657 | 1943 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
|
1944 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
|
1945 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
|
1946 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1947 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
|
1948 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
|
1949 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
|
1950 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1951 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1952 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1953 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
|
1954 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1955 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
|
1956 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
|
1957 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
|
1958 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1959 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1960 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1961 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
|
1962 std::string& md5 /* out */, |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1963 const RestApiCall& call, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1964 const std::string& header) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1965 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1966 std::string lower; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1967 Toolbox::ToLowerCase(lower, header); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1968 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1969 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
|
1970 if (found == call.GetHttpHeaders().end()) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1971 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1972 return false; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1973 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1974 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1975 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1976 std::string value = Toolbox::StripSpaces(found->second); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1977 Toolbox::RemoveSurroundingQuotes(value); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1978 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1979 try |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1980 { |
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
|
1981 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
|
1982 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
|
1983 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1984 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
|
1985 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
|
1986 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
|
1987 } |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1988 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1989 catch (boost::bad_lexical_cast&) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1990 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1991 } |
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 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1993 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
|
1994 "\" 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
|
1995 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1996 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1997 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1998 |
974 | 1999 static void GetMetadata(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2000 { |
4414 | 2001 if (call.IsDocumentation()) |
2002 { | |
2003 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2004 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2005 call.GetDocumentation() | |
2006 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2007 .SetSummary("Get metadata") | |
2008 .SetDescription("Get the value of a metadata that is associated with the given " + r) | |
2009 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2010 .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
|
2011 .AddAnswerType(MimeType_PlainText, "Value of the metadata") |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2012 .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
|
2013 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed"); |
4414 | 2014 return; |
2015 } | |
2016 | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
2017 assert(!call.GetFullUri().empty()); |
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
2018 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
|
2019 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
|
2020 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2021 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2022 MetadataType metadata = StringToMetadata(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2023 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2024 std::string value; |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2025 int64_t revision; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2026 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, revision, publicId, level, metadata)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2027 { |
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
|
2028 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
|
2029 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2030 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
|
2031 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
|
2032 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
|
2033 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
|
2034 userMD5 == GetMD5(value)) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2035 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2036 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2037 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2038 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2039 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2040 call.GetOutput().AnswerBuffer(value, MimeType_PlainText); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2041 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2042 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2043 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2044 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2045 |
974 | 2046 static void DeleteMetadata(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2047 { |
4414 | 2048 if (call.IsDocumentation()) |
2049 { | |
2050 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2051 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2052 call.GetDocumentation() | |
2053 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2054 .SetSummary("Delete metadata") | |
2055 .SetDescription("Delete some metadata associated with the given DICOM " + r + | |
2056 ". This call will fail if trying to delete a system metadata (i.e. whose index is < 1024).") | |
2057 .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
|
2058 .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
|
2059 .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
|
2060 "be deleted. This header is mandatory if `CheckRevisions` option is `true`."); |
4414 | 2061 return; |
2062 } | |
2063 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2064 CheckValidResourceType(call); |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2065 const std::string publicId = call.GetUriComponent("id", ""); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2066 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2067 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2068 MetadataType metadata = StringToMetadata(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2069 |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2070 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
|
2071 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2072 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2073 bool found; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2074 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
|
2075 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
|
2076 if (GetRevisionHeader(revision, md5, call, "if-match")) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2077 { |
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
|
2078 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
|
2079 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2080 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2081 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2082 OrthancConfiguration::ReaderLock lock; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2083 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2084 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2085 throw OrthancException(ErrorCode_Revision, |
4661
b1d87d41874e
typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4657
diff
changeset
|
2086 "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
|
2087 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2088 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2089 { |
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
|
2090 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
|
2091 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2092 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2093 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2094 if (found) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2095 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2096 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2097 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2098 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2099 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2100 throw OrthancException(ErrorCode_UnknownResource); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2101 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2102 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2103 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2104 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2105 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
|
2106 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2107 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2108 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2109 |
974 | 2110 static void SetMetadata(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2111 { |
4414 | 2112 if (call.IsDocumentation()) |
2113 { | |
2114 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2115 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2116 call.GetDocumentation() | |
2117 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2118 .SetSummary("Set metadata") | |
2119 .SetDescription("Set the value of some metadata in the given DICOM " + r + | |
2120 ". This call will fail if trying to modify a system metadata (i.e. whose index is < 1024).") | |
2121 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2122 .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
|
2123 .AddRequestType(MimeType_PlainText, "String value of the metadata") |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2124 .SetHttpHeader("If-Match", "Revision of the metadata, if this is not the first time this metadata is set."); |
4414 | 2125 return; |
2126 } | |
2127 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2128 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2129 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2130 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2131 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2132 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
|
2133 |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
2134 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
|
2135 call.BodyToString(value); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2136 |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2137 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
|
2138 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2139 { |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2140 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
|
2141 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
|
2142 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
|
2143 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2144 if (!hasOldRevision) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2145 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2146 OrthancConfiguration::ReaderLock lock; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2147 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2148 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2149 // "StatelessDatabaseOperations::SetMetadata()" will ignore |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2150 // 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
|
2151 // inexistent as expected |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2152 hasOldRevision = true; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2153 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
|
2154 oldMD5.clear(); // dummy value |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2155 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2156 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2157 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2158 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
|
2159 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
|
2160 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
|
2161 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2162 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
|
2163 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2164 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2165 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2166 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2167 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
|
2168 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2169 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2170 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2171 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2172 |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2173 // Handling of labels ------------------------------------------------------- |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2174 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2175 static void ListLabels(RestApiGetCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2176 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2177 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2178 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2179 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2180 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
|
2181 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2182 .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
|
2183 .SetSummary("List labels") |
8686476e9d12
fix inclusion of winsock.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5274
diff
changeset
|
2184 .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
|
2185 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2186 .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
|
2187 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/labels", true); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2188 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2189 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2190 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2191 assert(!call.GetFullUri().empty()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2192 const std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2193 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2194 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2195 std::set<std::string> labels; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2196 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2197 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2198 Json::Value result = Json::arrayValue; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2199 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2200 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
|
2201 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2202 result.append(*it); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2203 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2204 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2205 call.GetOutput().AnswerJson(result); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2206 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2207 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2208 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2209 static void GetLabel(RestApiGetCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2210 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2211 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2212 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2213 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2214 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
|
2215 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2216 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2217 .SetSummary("Test label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2218 .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
|
2219 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2220 .SetUriArgument("label", "The label of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2221 .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
|
2222 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2223 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2224 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2225 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2226 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2227 assert(!call.GetFullUri().empty()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2228 const std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2229 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2230 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2231 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2232 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2233 std::set<std::string> labels; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2234 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2235 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2236 if (labels.find(label) != labels.end()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2237 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2238 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2239 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2240 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2241 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2242 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2243 static void AddLabel(RestApiPutCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2244 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2245 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2246 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2247 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2248 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
|
2249 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2250 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2251 .SetSummary("Add label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2252 .SetDescription("Associate a label with a " + r) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2253 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2254 .SetUriArgument("label", "The label to be added"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2255 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2256 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2257 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2258 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2259 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2260 std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2261 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2262 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2263 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2264 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
|
2265 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2266 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2267 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2268 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2269 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2270 static void RemoveLabel(RestApiDeleteCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2271 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2272 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2273 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2274 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2275 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
|
2276 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2277 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2278 .SetSummary("Remove label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2279 .SetDescription("Remove a label associated with a " + r) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2280 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2281 .SetUriArgument("label", "The label to be removed"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2282 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2283 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2284 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2285 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2286 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2287 std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2288 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2289 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2290 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2291 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
|
2292 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2293 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2294 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2295 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2296 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2297 // Handling of attached files ----------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2298 |
974 | 2299 static void ListAttachments(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2300 { |
4409 | 2301 if (call.IsDocumentation()) |
2302 { | |
2303 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2304 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2305 call.GetDocumentation() | |
2306 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2307 .SetSummary("List attachments") | |
2308 .SetDescription("Get the list of attachments that are associated with the given " + r) | |
2309 .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
|
2310 .SetHttpGetArgument("full", RestApiCallDocumentation::Type_String, |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2311 "If present, retrieve the attachments list and their numerical ids", false) |
4409 | 2312 .AddAnswerType(MimeType_Json, "JSON array containing the names of the attachments") |
2313 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/attachments", true); | |
2314 return; | |
2315 } | |
2316 | |
2317 const std::string resourceType = call.GetFullUri() [0]; | |
2318 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
|
2319 std::set<FileContentType> attachments; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2320 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str())); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2321 |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2322 Json::Value result; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2323 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2324 if (call.HasArgument("full")) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2325 { |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2326 result = Json::objectValue; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2327 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2328 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
|
2329 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
|
2330 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2331 std::string key = EnumerationToString(*it); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2332 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
|
2333 } |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2334 } |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2335 else |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2336 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2337 result = Json::arrayValue; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2338 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2339 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
|
2340 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
|
2341 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2342 result.append(EnumerationToString(*it)); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2343 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2344 } |
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 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2347 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2348 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2349 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2350 static void AddAttachmentDocumentation(RestApiGetCall& call, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2351 const std::string& resourceType) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2352 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2353 call.GetDocumentation() |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2354 .SetUriArgument("id", "Orthanc identifier of the " + resourceType + " of interest") |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2355 .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
|
2356 .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
|
2357 .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
|
2358 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2359 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2360 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2361 static bool GetAttachmentInfo(FileInfo& info, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2362 RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2363 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2364 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2365 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2366 const std::string publicId = call.GetUriComponent("id", ""); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2367 const std::string name = call.GetUriComponent("name", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2368 FileContentType contentType = StringToContentType(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2369 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2370 int64_t revision; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2371 if (OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2372 { |
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
|
2373 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
|
2374 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2375 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
|
2376 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
|
2377 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
|
2378 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
|
2379 info.GetUncompressedMD5() == userMD5) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2380 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2381 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2382 return false; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2383 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2384 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2385 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2386 return true; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2387 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2388 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2389 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2390 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2391 throw OrthancException(ErrorCode_UnknownResource); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2392 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2393 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2394 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2395 |
974 | 2396 static void GetAttachmentOperations(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2397 { |
4409 | 2398 if (call.IsDocumentation()) |
2399 { | |
2400 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2401 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
|
2402 AddAttachmentDocumentation(call, r); |
4409 | 2403 call.GetDocumentation() |
2404 .SetTag("Other") | |
4414 | 2405 .SetSummary("List operations on attachments") |
2406 .SetDescription("Get the list of the operations that are available for attachments associated with the given " + r) | |
4409 | 2407 .AddAnswerType(MimeType_Json, "List of the available operations") |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
2408 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/6582b1c0-292ad5ab-ba0f088f-f7a1766f-9a29a54f/attachments/dicom", true); |
4409 | 2409 return; |
2410 } | |
2411 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2412 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2413 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2414 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2415 Json::Value operations = Json::arrayValue; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2416 |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2417 operations.append("compress"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2418 operations.append("compressed-data"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2419 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2420 if (info.GetCompressedMD5() != "") |
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 operations.append("compressed-md5"); |
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 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2425 operations.append("compressed-size"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2426 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
|
2427 operations.append("info"); |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2428 operations.append("is-compressed"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2429 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2430 if (info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2431 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2432 operations.append("md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2433 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2434 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2435 operations.append("size"); |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2436 operations.append("uncompress"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2437 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2438 if (info.GetCompressedMD5() != "" && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2439 info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2440 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2441 operations.append("verify-md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2442 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2443 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2444 call.GetOutput().AnswerJson(operations); |
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 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2449 template <int uncompress> |
974 | 2450 static void GetAttachmentData(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2451 { |
4409 | 2452 if (call.IsDocumentation()) |
2453 { | |
2454 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2455 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2456 call.GetDocumentation() | |
2457 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2458 .SetSummary("Get attachment" + std::string(uncompress ? "" : " (no decompression)")) | |
2459 .SetDescription("Get the (binary) content of one attachment associated with the given " + r + | |
4418 | 2460 std::string(uncompress ? "" : ". The attachment will not be decompressed if `StorageCompression` is `true`.")) |
4409 | 2461 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
4414 | 2462 .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
|
2463 .AddAnswerType(MimeType_Binary, "The attachment") |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2464 .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
|
2465 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed"); |
4409 | 2466 return; |
2467 } | |
2468 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2469 ServerContext& context = OrthancRestApi::GetContext(call); |
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 CheckValidResourceType(call); |
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 std::string publicId = call.GetUriComponent("id", ""); |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2474 FileContentType type = StringToContentType(call.GetUriComponent("name", "")); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2475 |
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
|
2476 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
|
2477 if (GetAttachmentInfo(info, call)) |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2478 { |
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
|
2479 // 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
|
2480 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2481 if (uncompress) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2482 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2483 context.AnswerAttachment(call.GetOutput(), publicId, type); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2484 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2485 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2486 { |
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
|
2487 // 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
|
2488 std::string content; |
5427 | 2489 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
|
2490 int64_t revision; |
5427 | 2491 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
|
2492 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2493 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
|
2494 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
|
2495 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
|
2496 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
|
2497 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
|
2498 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2499 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
|
2500 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2501 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
|
2502 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2503 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
|
2504 } |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2505 } |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2506 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2507 } |
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 |
974 | 2510 static void GetAttachmentSize(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2511 { |
4409 | 2512 if (call.IsDocumentation()) |
2513 { | |
2514 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2515 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
|
2516 AddAttachmentDocumentation(call, r); |
4409 | 2517 call.GetDocumentation() |
2518 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2519 .SetSummary("Get size of attachment") | |
2520 .SetDescription("Get the size of one attachment associated with the given " + r) | |
2521 .AddAnswerType(MimeType_PlainText, "The size of the attachment"); | |
2522 return; | |
2523 } | |
2524 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2525 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2526 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2527 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2528 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
|
2529 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2530 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2531 |
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
|
2532 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
|
2533 { |
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
|
2534 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
|
2535 { |
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
|
2536 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
|
2537 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
|
2538 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
|
2539 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
|
2540 .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
|
2541 .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
|
2542 .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
|
2543 .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
|
2544 .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
|
2545 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
|
2546 } |
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
|
2547 |
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
|
2548 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
|
2549 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
|
2550 { |
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
|
2551 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
|
2552 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
|
2553 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
|
2554 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
|
2555 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
|
2556 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
|
2557 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
|
2558 |
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
|
2559 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
|
2560 } |
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
|
2561 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2562 |
974 | 2563 static void GetAttachmentCompressedSize(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2564 { |
4409 | 2565 if (call.IsDocumentation()) |
2566 { | |
2567 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2568 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
|
2569 AddAttachmentDocumentation(call, r); |
4409 | 2570 call.GetDocumentation() |
2571 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
4410 | 2572 .SetSummary("Get size of attachment on disk") |
4409 | 2573 .SetDescription("Get the size of one attachment associated with the given " + r + ", as stored on the disk. " |
4413 | 2574 "This is different from `.../size` iff `EnableStorage` is `true`.") |
4410 | 2575 .AddAnswerType(MimeType_PlainText, "The size of the attachment, as stored on the disk"); |
4409 | 2576 return; |
2577 } | |
2578 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2579 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2580 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2581 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2582 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
|
2583 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2584 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2585 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2586 |
974 | 2587 static void GetAttachmentMD5(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2588 { |
4410 | 2589 if (call.IsDocumentation()) |
2590 { | |
2591 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2592 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
|
2593 AddAttachmentDocumentation(call, r); |
4410 | 2594 call.GetDocumentation() |
2595 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2596 .SetSummary("Get MD5 of attachment") | |
2597 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r) | |
2598 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment"); | |
2599 return; | |
2600 } | |
2601 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2602 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2603 if (GetAttachmentInfo(info, call) && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2604 info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2605 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2606 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
|
2607 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2608 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2609 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2610 |
974 | 2611 static void GetAttachmentCompressedMD5(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2612 { |
4410 | 2613 if (call.IsDocumentation()) |
2614 { | |
2615 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2616 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
|
2617 AddAttachmentDocumentation(call, r); |
4410 | 2618 call.GetDocumentation() |
2619 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2620 .SetSummary("Get MD5 of attachment on disk") | |
2621 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r + ", as stored on the disk. " | |
4413 | 2622 "This is different from `.../md5` iff `EnableStorage` is `true`.") |
4410 | 2623 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment, as stored on the disk"); |
2624 return; | |
2625 } | |
2626 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2627 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2628 if (GetAttachmentInfo(info, call) && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2629 info.GetCompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2630 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2631 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
|
2632 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2633 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2634 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2635 |
974 | 2636 static void VerifyAttachment(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2637 { |
4410 | 2638 if (call.IsDocumentation()) |
2639 { | |
2640 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2641 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2642 call.GetDocumentation() | |
2643 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2644 .SetSummary("Verify attachment") | |
2645 .SetDescription("Verify that the attachment is not corrupted, by validating its MD5 hash") | |
2646 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4414 | 2647 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)") |
4410 | 2648 .AddAnswerType(MimeType_Json, "On success, a valid JSON object is returned"); |
2649 return; | |
2650 } | |
2651 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2652 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2653 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2654 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2655 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2656 std::string name = call.GetUriComponent("name", ""); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2657 FileContentType contentType = StringToContentType(name); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2658 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2659 FileInfo info; |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2660 int64_t revision; // Ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2661 if (!OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType) || |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2662 info.GetCompressedMD5() == "" || |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2663 info.GetUncompressedMD5() == "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2664 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2665 // Inexistent resource, or no MD5 available |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2666 return; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2667 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2668 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2669 bool ok = false; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2670 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2671 // 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
|
2672 std::string data; |
5427 | 2673 std::string attachmentId; |
2674 | |
2675 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
|
2676 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2677 std::string actualMD5; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2678 Toolbox::ComputeMD5(actualMD5, data); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2679 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2680 if (actualMD5 == info.GetCompressedMD5()) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2681 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2682 // The compressed data is OK. If a compression algorithm was |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2683 // applied to it, now check the MD5 of the uncompressed data. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2684 if (info.GetCompressionType() == CompressionType_None) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2685 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2686 ok = true; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2687 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2688 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2689 { |
5427 | 2690 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
|
2691 Toolbox::ComputeMD5(actualMD5, data); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2692 ok = (actualMD5 == info.GetUncompressedMD5()); |
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 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2695 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2696 if (ok) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2697 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
2698 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
|
2699 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2700 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2701 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2702 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
2703 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
|
2704 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2705 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2706 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2707 |
974 | 2708 static void UploadAttachment(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2709 { |
4414 | 2710 if (call.IsDocumentation()) |
2711 { | |
2712 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2713 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2714 call.GetDocumentation() | |
2715 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2716 .SetSummary("Set attachment") | |
2717 .SetDescription("Attach a file to the given DICOM " + r + | |
2718 ". This call will fail if trying to modify a system attachment (i.e. whose index is < 1024).") | |
2719 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2720 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)") | |
2721 .AddRequestType(MimeType_Binary, "Binary data containing the attachment") | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2722 .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
|
2723 .SetHttpHeader("If-Match", "Revision of the attachment, if this is not the first time this attachment is set."); |
4414 | 2724 return; |
2725 } | |
2726 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2727 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2728 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2729 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2730 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2731 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2732 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2733 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
|
2734 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
|
2735 call.GetRequestOrigin() == RequestOrigin_Plugins) // ...except for plugins |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2736 { |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2737 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
|
2738 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
|
2739 bool hasOldRevision = GetRevisionHeader(oldRevision, oldMD5, call, "if-match"); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2740 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2741 if (!hasOldRevision) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2742 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2743 OrthancConfiguration::ReaderLock lock; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2744 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2745 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2746 // "StatelessDatabaseOperations::AddAttachment()" will ignore |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2747 // the actual value of "oldRevision" if the metadata is |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2748 // inexistent as expected |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2749 hasOldRevision = true; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2750 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
|
2751 oldMD5.clear(); // dummy value |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2752 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2753 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2754 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2755 int64_t newRevision; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2756 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
|
2757 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
|
2758 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2759 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
|
2760 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2761 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2762 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2763 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2764 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
|
2765 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2766 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2767 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2768 |
974 | 2769 static void DeleteAttachment(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2770 { |
4413 | 2771 if (call.IsDocumentation()) |
2772 { | |
2773 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2774 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2775 call.GetDocumentation() | |
2776 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2777 .SetSummary("Delete attachment") | |
4414 | 2778 .SetDescription("Delete an attachment associated with the given DICOM " + r + |
2779 ". This call will fail if trying to delete a system attachment (i.e. whose index is < 1024).") | |
4413 | 2780 .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
|
2781 .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
|
2782 .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
|
2783 "be deleted. This header is mandatory if `CheckRevisions` option is `true`."); |
4413 | 2784 return; |
2785 } | |
2786 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2787 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2788 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2789 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2790 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2791 FileContentType contentType = StringToContentType(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2792 |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2793 bool allowed; |
5446
912565317b9a
plugins are now allowed to modify/delete private metadata/attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
2794 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
|
2795 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
|
2796 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2797 allowed = true; |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2798 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2799 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2800 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2801 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2802 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2803 if (lock.GetConfiguration().GetBooleanParameter("StoreDicom", true) && |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2804 contentType == FileContentType_DicomAsJson) |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2805 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2806 allowed = true; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2807 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2808 else |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2809 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2810 // 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
|
2811 // 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
|
2812 // 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
|
2813 allowed = false; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2814 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2815 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2816 |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2817 if (allowed) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2818 { |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2819 bool found; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2820 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
|
2821 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
|
2822 if (GetRevisionHeader(revision, md5, call, "if-match")) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2823 { |
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
|
2824 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
|
2825 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2826 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2827 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2828 OrthancConfiguration::ReaderLock lock; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2829 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2830 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2831 throw OrthancException(ErrorCode_Revision, |
4661
b1d87d41874e
typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4657
diff
changeset
|
2832 "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
|
2833 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2834 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2835 { |
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
|
2836 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
|
2837 false, -1 /* dummy value */, "" /* dummy value */); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2838 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2839 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2840 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2841 if (found) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2842 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2843 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2844 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2845 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2846 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2847 throw OrthancException(ErrorCode_UnknownResource); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2848 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2849 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2850 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2851 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2852 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
|
2853 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2854 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2855 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2856 |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2857 template <enum CompressionType compression> |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2858 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
|
2859 { |
4413 | 2860 if (call.IsDocumentation()) |
2861 { | |
2862 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2863 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2864 call.GetDocumentation() | |
2865 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2866 .SetSummary(compression == CompressionType_None ? "Uncompress attachment" : "Compress attachment") | |
2867 .SetDescription("Change the compression scheme that is used to store an attachment.") | |
2868 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4414 | 2869 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)"); |
4413 | 2870 return; |
2871 } | |
2872 | |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2873 CheckValidResourceType(call); |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2874 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2875 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
|
2876 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
|
2877 FileContentType contentType = StringToContentType(name); |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2878 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2879 OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2880 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
|
2881 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2882 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2883 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2884 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
|
2885 { |
4413 | 2886 if (call.IsDocumentation()) |
2887 { | |
2888 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2889 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
|
2890 AddAttachmentDocumentation(call, r); |
4413 | 2891 call.GetDocumentation() |
2892 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2893 .SetSummary("Is attachment compressed?") | |
2894 .SetDescription("Test whether the attachment has been stored as a compressed file on the disk.") | |
2895 .AddAnswerType(MimeType_PlainText, "`0` if the attachment was stored uncompressed, `1` if it was compressed"); | |
2896 return; | |
2897 } | |
2898 | |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2899 FileInfo info; |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2900 if (GetAttachmentInfo(info, call)) |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2901 { |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2902 std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1"; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2903 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
|
2904 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2905 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2906 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2907 |
782 | 2908 // Raw access to the DICOM tags of an instance ------------------------------ |
2909 | |
974 | 2910 static void GetRawContent(RestApiGetCall& call) |
782 | 2911 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2912 if (call.IsDocumentation()) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2913 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2914 call.GetDocumentation() |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2915 .SetTag("Instances") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2916 .SetSummary("Get raw tag") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2917 .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
|
2918 .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
|
2919 .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
|
2920 "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
|
2921 .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
|
2922 "(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
|
2923 "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
|
2924 return; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2925 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2926 |
782 | 2927 std::string id = call.GetUriComponent("id", ""); |
2928 | |
2929 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); | |
2930 | |
2931 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); | |
2932 } | |
2933 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2934 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2935 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2936 static bool ExtractSharedTags(Json::Value& shared, |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2937 ServerContext& context, |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2938 const std::string& publicId) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2939 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2940 // 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
|
2941 typedef std::list<std::string> Instances; |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2942 Instances instances; |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2943 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2944 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2945 // Loop over the instances |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2946 bool isFirst = true; |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2947 shared = Json::objectValue; |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2948 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2949 for (Instances::const_iterator it = instances.begin(); |
1303 | 2950 it != instances.end(); ++it) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2951 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2952 // 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
|
2953 Json::Value tags; |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2954 |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2955 try |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2956 { |
2124 | 2957 context.ReadDicomAsJson(tags, *it); |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2958 } |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2959 catch (OrthancException&) |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2960 { |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2961 // Race condition: This instance has been removed since |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2962 // (*). Ignore this instance. |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2963 continue; |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2964 } |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2965 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2966 if (tags.type() != Json::objectValue) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2967 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2968 return false; // Error |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2969 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2970 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2971 // 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
|
2972 Json::Value::Members members = tags.getMemberNames(); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2973 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
|
2974 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2975 const Json::Value& tag = tags[members[i]]; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2976 if (tag.type() != Json::objectValue || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2977 tag["Type"].type() != Json::stringValue || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2978 tag["Type"].asString() != "String") |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2979 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2980 tags.removeMember(members[i]); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2981 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2982 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2983 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2984 if (isFirst) |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2985 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2986 // 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
|
2987 shared = tags; |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2988 isFirst = false; |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2989 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2990 else |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2991 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2992 // 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
|
2993 // 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
|
2994 // value in the current instance, remove it. |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2995 members = shared.getMemberNames(); |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2996 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
|
2997 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2998 if (!tags.isMember(members[i]) || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2999 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
|
3000 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3001 shared.removeMember(members[i]); |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3002 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3003 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3004 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3005 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3006 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3007 return true; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3008 } |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3009 |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3010 |
974 | 3011 static void GetSharedTags(RestApiGetCall& call) |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3012 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3013 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3014 { |
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
|
3015 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
|
3016 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3017 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
|
3018 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
|
3019 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3020 .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
|
3021 .SetSummary("Get shared tags") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3022 .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
|
3023 "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
|
3024 .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
|
3025 .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
|
3026 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/shared-tags", 5); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3027 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3028 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3029 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3030 ServerContext& context = OrthancRestApi::GetContext(call); |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3031 std::string publicId = call.GetUriComponent("id", ""); |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3032 |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3033 Json::Value sharedTags; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3034 if (ExtractSharedTags(sharedTags, context, publicId)) |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3035 { |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
3036 // 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
|
3037 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
|
3038 } |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3039 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3040 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
3041 |
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
|
3042 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
|
3043 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
|
3044 static void GetModule(RestApiGetCall& call) |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3045 { |
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
|
3046 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
|
3047 { |
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
|
3048 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
|
3049 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
|
3050 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
|
3051 { |
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
|
3052 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
|
3053 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
|
3054 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
|
3055 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
|
3056 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
|
3057 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
|
3058 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
|
3059 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
|
3060 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
|
3061 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
|
3062 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
|
3063 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
|
3064 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
|
3065 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
|
3066 } |
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
|
3067 |
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
|
3068 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
|
3069 |
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
|
3070 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
|
3071 .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
|
3072 .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
|
3073 .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
|
3074 .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
|
3075 .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
|
3076 "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
|
3077 .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
|
3078 .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
|
3079 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
|
3080 } |
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
|
3081 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3082 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3083 (resourceType == ResourceType_Study && module == DicomModule_Patient) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3084 (resourceType == ResourceType_Study && module == DicomModule_Study) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3085 (resourceType == ResourceType_Series && module == DicomModule_Series) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3086 (resourceType == ResourceType_Instance && module == DicomModule_Instance) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3087 (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
|
3088 { |
1701dcb6f554
Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
3089 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
|
3090 } |
1701dcb6f554
Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
3091 |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3092 ServerContext& context = OrthancRestApi::GetContext(call); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3093 std::string publicId = call.GetUriComponent("id", ""); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3094 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3095 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
|
3096 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3097 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3098 typedef std::set<DicomTag> ModuleTags; |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3099 ModuleTags moduleTags; |
1368 | 3100 DicomTag::AddTagsForModule(moduleTags, module); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3101 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3102 Json::Value tags; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3103 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3104 if (resourceType != ResourceType_Instance) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3105 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3106 // Retrieve all the instances of this patient/study/series |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3107 typedef std::list<std::string> Instances; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3108 Instances instances; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3109 context.GetIndex().GetChildInstances(instances, publicId); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3110 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3111 if (instances.empty()) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3112 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3113 return; // Error: No instance (should never happen) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3114 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3115 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3116 // Select one child instance |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3117 publicId = instances.front(); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3118 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3119 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3120 context.ReadDicomAsJson(tags, publicId, ignoreTagLength); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3121 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3122 // 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
|
3123 Json::Value result = Json::objectValue; |
1303 | 3124 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
|
3125 { |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
3126 std::string s = tag->Format(); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3127 if (tags.isMember(s)) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3128 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3129 result[s] = tags[s]; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3130 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3131 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3132 |
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
|
3133 AnswerDicomAsJson(call, result, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3134 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3135 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
3136 |
1722 | 3137 namespace |
3138 { | |
3139 typedef std::list< std::pair<ResourceType, std::string> > LookupResults; | |
3140 } | |
3141 | |
3142 | |
3143 static void AccumulateLookupResults(LookupResults& result, | |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3144 ServerIndex& index, |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3145 const DicomTag& tag, |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
3146 const std::string& value, |
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
3147 ResourceType level) |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3148 { |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
3149 std::vector<std::string> tmp; |
1728
4941494b5dd8
rename LookupIdentifier as LookupIdentifierExact
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1727
diff
changeset
|
3150 index.LookupIdentifierExact(tmp, level, tag, value); |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
3151 |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
3152 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
|
3153 { |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
3154 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
|
3155 } |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3156 } |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3157 |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3158 |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3159 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
|
3160 { |
4422 | 3161 if (call.IsDocumentation()) |
3162 { | |
3163 call.GetDocumentation() | |
3164 .SetTag("System") | |
3165 .SetSummary("Look for DICOM identifiers") | |
3166 .SetDescription("This URI can be used to convert one DICOM identifier to a list of matching Orthanc resources") | |
3167 .AddRequestType(MimeType_PlainText, "The DICOM identifier of interest (i.e. the value of `PatientID`, " | |
3168 "`StudyInstanceUID`, `SeriesInstanceUID`, or `SOPInstanceUID`)") | |
3169 .AddAnswerType(MimeType_Json, "JSON array containing a list of matching Orthanc resources, each item in the " | |
3170 "list corresponding to a JSON object with the fields `Type`, `ID` and `Path` identifying one " | |
3171 "DICOM resource that is stored by Orthanc"); | |
3172 return; | |
3173 } | |
3174 | |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
3175 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
|
3176 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
|
3177 |
1722 | 3178 LookupResults resources; |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3179 ServerIndex& index = OrthancRestApi::GetIndex(call); |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
3180 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
|
3181 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
|
3182 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
|
3183 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
|
3184 |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3185 Json::Value result = Json::arrayValue; |
1722 | 3186 for (LookupResults::const_iterator |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3187 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
|
3188 { |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3189 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
|
3190 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
|
3191 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3192 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
|
3193 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
|
3194 item["ID"] = id; |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3195 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
|
3196 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3197 result.append(item); |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3198 } |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3199 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3200 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
|
3201 } |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3202 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3203 |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3204 namespace |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3205 { |
3021
2cbafb5d5a62
renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3012
diff
changeset
|
3206 class FindVisitor : public ServerContext::ILookupVisitor |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3207 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3208 private: |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3209 bool isComplete_; |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3210 std::list<std::string> resources_; |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
3211 FindStorageAccessMode findStorageAccessMode_; |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3212 |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3213 // cache the data we used during lookup and that we could reuse when building the answers |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3214 std::map<std::string, std::string> instancesIds_; // the id of an instance for each found resource. |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3215 std::map<std::string, boost::shared_ptr<DicomMap> > resourcesMainDicomTags_; // all tags read from DB for a resource (current level and upper levels) |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3216 std::map<std::string, boost::shared_ptr<Json::Value> > resourcesDicomAsJson_; // the dicom-as-json for a resource |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3217 |
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
|
3218 DicomToJsonFormat format_; |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3219 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3220 public: |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
3221 explicit FindVisitor(DicomToJsonFormat format, FindStorageAccessMode findStorageAccessMode) : |
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
|
3222 isComplete_(false), |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
3223 findStorageAccessMode_(findStorageAccessMode), |
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
|
3224 format_(format) |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3225 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3226 } |
4205 | 3227 |
3228 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE | |
3012
af1530b45290
Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3003
diff
changeset
|
3229 { |
af1530b45290
Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3003
diff
changeset
|
3230 return false; // (*) |
af1530b45290
Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3003
diff
changeset
|
3231 } |
af1530b45290
Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3003
diff
changeset
|
3232 |
4205 | 3233 virtual void MarkAsComplete() ORTHANC_OVERRIDE |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3234 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3235 isComplete_ = true; // Unused information as of Orthanc 1.5.0 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3236 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3237 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3238 virtual void Visit(const std::string& publicId, |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3239 const std::string& instanceId, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3240 const DicomMap& mainDicomTags, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3241 const Json::Value* dicomAsJson) ORTHANC_OVERRIDE |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3242 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3243 resources_.push_back(publicId); |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3244 instancesIds_[publicId] = instanceId; |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3245 resourcesMainDicomTags_[publicId].reset(mainDicomTags.Clone()); |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3246 if (dicomAsJson != NULL) |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3247 { |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3248 resourcesDicomAsJson_[publicId].reset(new Json::Value(*dicomAsJson)); // keep our own copy because we might reuse it between lookup and answers |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3249 } |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3250 else |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3251 { |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3252 resourcesDicomAsJson_[publicId] = boost::shared_ptr<Json::Value>(); |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3253 } |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3254 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3255 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3256 void Answer(RestApiOutput& output, |
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
|
3257 ServerContext& context, |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3258 ResourceType level, |
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
|
3259 bool expand, |
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
|
3260 const std::set<DicomTag>& requestedTags) const |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3261 { |
5554
12d8a1a266e9
introduction of FindRequest and FindResponse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
3262 AnswerListOfResources1(output, context, resources_, instancesIds_, resourcesMainDicomTags_, resourcesDicomAsJson_, level, expand, format_, requestedTags, IsStorageAccessAllowedForAnswers(findStorageAccessMode_)); |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3263 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3264 }; |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3265 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3266 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3267 |
1354 | 3268 static void Find(RestApiPostCall& call) |
3269 { | |
2998 | 3270 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive"; |
3271 static const char* const KEY_EXPAND = "Expand"; | |
3272 static const char* const KEY_LEVEL = "Level"; | |
3273 static const char* const KEY_LIMIT = "Limit"; | |
3274 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
|
3275 static const char* const KEY_REQUESTED_TAGS = "RequestedTags"; |
2998 | 3276 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
|
3277 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
|
3278 static const char* const KEY_LABELS_CONSTRAINT = "LabelsConstraint"; // New in Orthanc 1.12.0 |
2998 | 3279 |
4421 | 3280 if (call.IsDocumentation()) |
3281 { | |
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
|
3282 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
|
3283 |
4421 | 3284 call.GetDocumentation() |
3285 .SetTag("System") | |
3286 .SetSummary("Look for local resources") | |
3287 .SetDescription("This URI can be used to perform a search on the content of the local Orthanc server, " | |
3288 "in a way that is similar to querying remote DICOM modalities using C-FIND SCU: " | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5427
diff
changeset
|
3289 "https://orthanc.uclouvain.be/book/users/rest.html#performing-finds-within-orthanc") |
4421 | 3290 .SetRequestField(KEY_CASE_SENSITIVE, RestApiCallDocumentation::Type_Boolean, |
3291 "Enable case-sensitive search for PN value representations (defaults to configuration option `CaseSensitivePN`)", false) | |
3292 .SetRequestField(KEY_EXPAND, RestApiCallDocumentation::Type_Boolean, | |
3293 "Also retrieve the content of the matching resources, not only their Orthanc identifiers", false) | |
3294 .SetRequestField(KEY_LEVEL, RestApiCallDocumentation::Type_String, | |
3295 "Level of the query (`Patient`, `Study`, `Series` or `Instance`)", true) | |
3296 .SetRequestField(KEY_LIMIT, RestApiCallDocumentation::Type_Number, | |
3297 "Limit the number of reported resources", false) | |
3298 .SetRequestField(KEY_SINCE, RestApiCallDocumentation::Type_Number, | |
3299 "Show only the resources since the provided index (in conjunction with `Limit`)", false) | |
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
|
3300 .SetRequestField(KEY_REQUESTED_TAGS, RestApiCallDocumentation::Type_JsonListOfStrings, |
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
|
3301 "A list of DICOM tags to include in the response (applicable only if \"Expand\" is set to true). " |
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
|
3302 "The tags requested tags are returned in the 'RequestedTags' field in the response. " |
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
|
3303 "Note that, if you are requesting tags that are not listed in the Main Dicom Tags stored in DB, building the response " |
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
|
3304 "might be slow since Orthanc will need to access the DICOM files. If not specified, Orthanc will return " |
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
|
3305 "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false) |
4421 | 3306 .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject, |
3307 "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
|
3308 .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
|
3309 "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
|
3310 .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
|
3311 "Constraint on the labels, can be `All`, `Any`, or `None` (defaults to `All`, new in Orthanc 1.12.0)", true) |
4421 | 3312 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " |
3313 "about the reported resources (if `Expand` argument is `true`)"); | |
3314 return; | |
3315 } | |
3316 | |
1358 | 3317 ServerContext& context = OrthancRestApi::GetContext(call); |
1354 | 3318 |
3319 Json::Value request; | |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3320 if (!call.ParseJsonRequest(request) || |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3321 request.type() != Json::objectValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3322 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3323 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3324 "The body must contain a JSON object"); |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3325 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3326 else if (!request.isMember(KEY_LEVEL) || |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3327 request[KEY_LEVEL].type() != Json::stringValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3328 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3329 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3330 "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
|
3331 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3332 else if (!request.isMember(KEY_QUERY) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3333 request[KEY_QUERY].type() != Json::objectValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3334 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3335 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3336 "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
|
3337 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3338 else if (request.isMember(KEY_CASE_SENSITIVE) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3339 request[KEY_CASE_SENSITIVE].type() != Json::booleanValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3340 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3341 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3342 "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
|
3343 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3344 else if (request.isMember(KEY_LIMIT) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3345 request[KEY_LIMIT].type() != Json::intValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3346 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3347 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3348 "Field \"" + std::string(KEY_LIMIT) + "\" must be an integer"); |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3349 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3350 else if (request.isMember(KEY_SINCE) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3351 request[KEY_SINCE].type() != Json::intValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3352 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3353 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3354 "Field \"" + std::string(KEY_SINCE) + "\" must be an integer"); |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3355 } |
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
|
3356 else if (request.isMember(KEY_REQUESTED_TAGS) && |
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
|
3357 request[KEY_REQUESTED_TAGS].type() != Json::arrayValue) |
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
|
3358 { |
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
|
3359 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3360 "Field \"" + std::string(KEY_REQUESTED_TAGS) + "\" must be an array"); |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3361 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3362 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
|
3363 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
|
3364 { |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3365 throw OrthancException(ErrorCode_BadRequest, |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3366 "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
|
3367 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3368 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
|
3369 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
|
3370 { |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3371 throw OrthancException(ErrorCode_BadRequest, |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3372 "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
|
3373 } |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3374 else if (true) |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3375 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3376 /** |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3377 * EXPERIMENTAL VERSION |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3378 **/ |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3379 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3380 bool expand = false; |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3381 if (request.isMember(KEY_EXPAND)) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3382 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3383 expand = request[KEY_EXPAND].asBool(); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3384 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3385 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3386 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
|
3387 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3388 ResourceFinder finder(level, expand); |
5688
d0a264b803f1
first implementation of database paging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5684
diff
changeset
|
3389 finder.SetDatabaseLimits(context.GetDatabaseLimits(level)); |
5709
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
3390 |
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
3391 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human); |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3392 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3393 if (request.isMember(KEY_LIMIT)) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3394 { |
5693 | 3395 int64_t tmp = request[KEY_LIMIT].asInt64(); |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3396 if (tmp < 0) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3397 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3398 throw OrthancException(ErrorCode_ParameterOutOfRange, |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3399 "Field \"" + std::string(KEY_LIMIT) + "\" must be a positive integer"); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3400 } |
5695 | 3401 else if (tmp != 0) // This is for compatibility with Orthanc 1.12.4 |
5693 | 3402 { |
3403 finder.SetLimitsCount(static_cast<uint64_t>(tmp)); | |
3404 } | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3405 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3406 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3407 if (request.isMember(KEY_SINCE)) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3408 { |
5693 | 3409 int64_t tmp = request[KEY_SINCE].asInt64(); |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3410 if (tmp < 0) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3411 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3412 throw OrthancException(ErrorCode_ParameterOutOfRange, |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3413 "Field \"" + std::string(KEY_SINCE) + "\" must be a positive integer"); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3414 } |
5693 | 3415 else |
3416 { | |
3417 finder.SetLimitsSince(static_cast<uint64_t>(tmp)); | |
3418 } | |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3419 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3420 |
5690
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3421 { |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3422 bool caseSensitive = false; |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3423 if (request.isMember(KEY_CASE_SENSITIVE)) |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3424 { |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3425 caseSensitive = request[KEY_CASE_SENSITIVE].asBool(); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3426 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3427 |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3428 DatabaseLookup query; |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3429 |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3430 Json::Value::Members members = request[KEY_QUERY].getMemberNames(); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3431 for (size_t i = 0; i < members.size(); i++) |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3432 { |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3433 if (request[KEY_QUERY][members[i]].type() != Json::stringValue) |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3434 { |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3435 throw OrthancException(ErrorCode_BadRequest, |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3436 "Tag \"" + members[i] + "\" must be associated with a string"); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3437 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3438 |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3439 const std::string value = request[KEY_QUERY][members[i]].asString(); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3440 |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3441 if (!value.empty()) |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3442 { |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3443 // An empty string corresponds to an universal constraint, |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3444 // so we ignore it. This mimics the behavior of class |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3445 // "OrthancFindRequestHandler" |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3446 query.AddRestConstraint(FromDcmtkBridge::ParseTag(members[i]), |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3447 value, caseSensitive, true); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3448 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3449 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3450 |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3451 finder.SetDatabaseLookup(query); |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3452 } |
708952bd869c
integration tests are passing with ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5688
diff
changeset
|
3453 |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3454 if (request.isMember(KEY_REQUESTED_TAGS)) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3455 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3456 std::set<DicomTag> requestedTags; |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3457 FromDcmtkBridge::ParseListOfTags(requestedTags, request[KEY_REQUESTED_TAGS]); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3458 finder.AddRequestedTags(requestedTags); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3459 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3460 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3461 if (request.isMember(KEY_LABELS)) // New in Orthanc 1.12.0 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3462 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3463 for (Json::Value::ArrayIndex i = 0; i < request[KEY_LABELS].size(); i++) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3464 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3465 if (request[KEY_LABELS][i].type() != Json::stringValue) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3466 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3467 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS) + "\" must contain strings"); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3468 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3469 else |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3470 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3471 finder.AddLabel(request[KEY_LABELS][i].asString()); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3472 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3473 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3474 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3475 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3476 finder.SetLabelsConstraint(LabelsConstraint_All); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3477 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3478 if (request.isMember(KEY_LABELS_CONSTRAINT)) |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3479 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3480 const std::string& s = request[KEY_LABELS_CONSTRAINT].asString(); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3481 if (s == "All") |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3482 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3483 finder.SetLabelsConstraint(LabelsConstraint_All); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3484 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3485 else if (s == "Any") |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3486 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3487 finder.SetLabelsConstraint(LabelsConstraint_Any); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3488 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3489 else if (s == "None") |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3490 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3491 finder.SetLabelsConstraint(LabelsConstraint_None); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3492 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3493 else |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3494 { |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3495 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\""); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3496 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3497 } |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3498 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3499 Json::Value answer; |
5709
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
3500 finder.Execute(answer, context, format); |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3501 call.GetOutput().AnswerJson(answer); |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3502 } |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3503 else |
1354 | 3504 { |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3505 /** |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3506 * VERSION IN ORTHANC <= 1.12.4 |
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3507 **/ |
1354 | 3508 bool expand = false; |
2998 | 3509 if (request.isMember(KEY_EXPAND)) |
1354 | 3510 { |
2998 | 3511 expand = request[KEY_EXPAND].asBool(); |
1354 | 3512 } |
3513 | |
1374
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3514 bool caseSensitive = false; |
2998 | 3515 if (request.isMember(KEY_CASE_SENSITIVE)) |
1374
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3516 { |
2998 | 3517 caseSensitive = request[KEY_CASE_SENSITIVE].asBool(); |
1374
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3518 } |
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3519 |
1758 | 3520 size_t limit = 0; |
2998 | 3521 if (request.isMember(KEY_LIMIT)) |
1758 | 3522 { |
2998 | 3523 int tmp = request[KEY_LIMIT].asInt(); |
1847 | 3524 if (tmp < 0) |
1758 | 3525 { |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3526 throw OrthancException(ErrorCode_ParameterOutOfRange, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3527 "Field \"" + std::string(KEY_LIMIT) + "\" must be a positive integer"); |
1758 | 3528 } |
1847 | 3529 |
3530 limit = static_cast<size_t>(tmp); | |
1758 | 3531 } |
3532 | |
2304
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3533 size_t since = 0; |
2998 | 3534 if (request.isMember(KEY_SINCE)) |
2304
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3535 { |
2998 | 3536 int tmp = request[KEY_SINCE].asInt(); |
2304
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3537 if (tmp < 0) |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3538 { |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3539 throw OrthancException(ErrorCode_ParameterOutOfRange, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3540 "Field \"" + std::string(KEY_SINCE) + "\" must be a positive integer"); |
2304
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3541 } |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3542 |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3543 since = static_cast<size_t>(tmp); |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3544 } |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
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 |
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 if (request.isMember(KEY_REQUESTED_TAGS)) |
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
|
3549 { |
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
|
3550 FromDcmtkBridge::ParseListOfTags(requestedTags, request[KEY_REQUESTED_TAGS]); |
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
|
3551 } |
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
|
3552 |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
3553 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); |
1360 | 3554 |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
3555 DatabaseLookup query; |
1358 | 3556 |
2998 | 3557 Json::Value::Members members = request[KEY_QUERY].getMemberNames(); |
1354 | 3558 for (size_t i = 0; i < members.size(); i++) |
3559 { | |
2998 | 3560 if (request[KEY_QUERY][members[i]].type() != Json::stringValue) |
1354 | 3561 { |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3562 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3563 "Tag \"" + members[i] + "\" must be associated with a string"); |
1354 | 3564 } |
3565 | |
3163
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3566 const std::string value = request[KEY_QUERY][members[i]].asString(); |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3567 |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3568 if (!value.empty()) |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3569 { |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3570 // An empty string corresponds to an universal constraint, |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3571 // so we ignore it. This mimics the behavior of class |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3572 // "OrthancFindRequestHandler" |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3573 query.AddRestConstraint(FromDcmtkBridge::ParseTag(members[i]), |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3574 value, caseSensitive, true); |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3575 } |
1361
94ffb597d297
refactoring of C-Find SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1360
diff
changeset
|
3576 } |
2876 | 3577 |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3578 std::set<std::string> labels; |
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3579 |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3580 if (request.isMember(KEY_LABELS)) // New in Orthanc 1.12.0 |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3581 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3582 for (Json::Value::ArrayIndex i = 0; i < request[KEY_LABELS].size(); i++) |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3583 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3584 if (request[KEY_LABELS][i].type() != Json::stringValue) |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3585 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3586 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS) + "\" must contain strings"); |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3587 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3588 else |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3589 { |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3590 labels.insert(request[KEY_LABELS][i].asString()); |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3591 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3592 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3593 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3594 |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3595 LabelsConstraint labelsConstraint = LabelsConstraint_All; |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3596 |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3597 if (request.isMember(KEY_LABELS_CONSTRAINT)) |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3598 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3599 const std::string& s = request[KEY_LABELS_CONSTRAINT].asString(); |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3600 if (s == "All") |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3601 { |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3602 labelsConstraint = LabelsConstraint_All; |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3603 } |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3604 else if (s == "Any") |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3605 { |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3606 labelsConstraint = LabelsConstraint_Any; |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3607 } |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3608 else if (s == "None") |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3609 { |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3610 labelsConstraint = LabelsConstraint_None; |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3611 } |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3612 else |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3613 { |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3614 throw OrthancException(ErrorCode_BadRequest, "Field \"" + std::string(KEY_LABELS_CONSTRAINT) + "\" must be \"All\", \"Any\", or \"None\""); |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3615 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3616 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3617 |
5058
d4e5ca0c9307
Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents:
5054
diff
changeset
|
3618 FindVisitor visitor(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human), context.GetFindStorageAccessMode()); |
5683
0c218d90096e
moved handling of labels out of DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5655
diff
changeset
|
3619 context.Apply(visitor, query, level, labels, labelsConstraint, since, limit); |
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
|
3620 visitor.Answer(call.GetOutput(), context, level, expand, requestedTags); |
1354 | 3621 } |
3622 } | |
3623 | |
3624 | |
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
|
3625 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
|
3626 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
|
3627 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
|
3628 { |
4415 | 3629 if (call.IsDocumentation()) |
3630 { | |
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
|
3631 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
|
3632 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
|
3633 |
4415 | 3634 const std::string children = GetResourceTypeText(end, true /* plural */, false /* lower case */); |
3635 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */); | |
3636 call.GetDocumentation() | |
3637 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */)) | |
3638 .SetSummary("Get child " + children) | |
3639 .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
|
3640 resource + " whose Orthanc identifier is provided in the URL") |
4415 | 3641 .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
|
3642 .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
|
3643 "If false or missing, only retrieve the list of child " + children, false) |
4415 | 3644 .AddAnswerType(MimeType_Json, "JSON array containing information about the child DICOM " + children) |
3645 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + children, 5); | |
3646 return; | |
3647 } | |
3648 | |
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
|
3649 ServerIndex& index = OrthancRestApi::GetIndex(call); |
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
|
3650 ServerContext& context = OrthancRestApi::GetContext(call); |
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
|
3651 |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3652 const bool expand = (!call.HasArgument("expand") || |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3653 // 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
|
3654 call.GetBooleanArgument("expand", false)); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3655 const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3656 |
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
|
3657 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
|
3658 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
|
3659 |
5665
d8c86698110c
implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5656
diff
changeset
|
3660 if (true) |
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
|
3661 { |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3662 /** |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3663 * EXPERIMENTAL VERSION |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3664 **/ |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3665 |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3666 ResourceFinder finder(end, expand); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3667 finder.SetOrthancId(start, call.GetUriComponent("id", "")); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3668 finder.AddRequestedTags(requestedTags); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3669 |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3670 Json::Value answer; |
5709
476b1db52110
removed the "format_" member from ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5708
diff
changeset
|
3671 finder.Execute(answer, context, format); |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3672 call.GetOutput().AnswerJson(answer); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3673 } |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3674 else |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3675 { |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3676 /** |
5677
dc96401dbe88
starting the refactoring of /tools/find
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5665
diff
changeset
|
3677 * VERSION IN ORTHANC <= 1.12.4 |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3678 **/ |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3679 std::list<std::string> a, b, c; |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3680 a.push_back(call.GetUriComponent("id", "")); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3681 |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3682 ResourceType type = start; |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3683 while (type != end) |
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
|
3684 { |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3685 b.clear(); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3686 |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3687 for (std::list<std::string>::const_iterator |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3688 it = a.begin(); it != a.end(); ++it) |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3689 { |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3690 index.GetChildren(c, *it); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3691 b.splice(b.begin(), c); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3692 } |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3693 |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3694 type = GetChildResourceType(type); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3695 |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3696 a.clear(); |
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3697 a.splice(a.begin(), b); |
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
|
3698 } |
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
|
3699 |
5617
8905ffa45fc2
started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5615
diff
changeset
|
3700 AnswerListOfResources2(call.GetOutput(), context, a, type, expand, format, requestedTags, true /* allowStorageAccess */); |
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
|
3701 } |
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
|
3702 } |
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
|
3703 |
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
|
3704 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3705 static void GetChildInstancesTags(RestApiGetCall& call) |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3706 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3707 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3708 { |
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
|
3709 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
|
3710 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3711 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
|
3712 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
|
3713 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3714 .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
|
3715 .SetSummary("Get tags of instances") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3716 .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
|
3717 " 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
|
3718 .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
|
3719 .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
|
3720 "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
|
3721 .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
|
3722 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/instances-tags", 5); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3723 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3724 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3725 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3726 ServerContext& context = OrthancRestApi::GetContext(call); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3727 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
|
3728 DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full); |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3729 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3730 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
|
3731 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3732 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3733 // Retrieve all the instances of this patient/study/series |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3734 typedef std::list<std::string> Instances; |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3735 Instances instances; |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3736 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3737 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3738 |
1201
09aa7c126be9
URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1172
diff
changeset
|
3739 Json::Value result = Json::objectValue; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3740 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3741 for (Instances::const_iterator it = instances.begin(); |
1303 | 3742 it != instances.end(); ++it) |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3743 { |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3744 Json::Value full; |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3745 context.ReadDicomAsJson(full, *it, ignoreTagLength); |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3746 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
3747 if (format != DicomToJsonFormat_Full) |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3748 { |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3749 Json::Value simplified; |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
3750 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
|
3751 result[*it] = simplified; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3752 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3753 else |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3754 { |
1201
09aa7c126be9
URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1172
diff
changeset
|
3755 result[*it] = full; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3756 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3757 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3758 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3759 call.GetOutput().AnswerJson(result); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3760 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3761 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3762 |
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
|
3763 |
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
|
3764 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
|
3765 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
|
3766 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
|
3767 { |
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
|
3768 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
|
3769 |
4415 | 3770 if (call.IsDocumentation()) |
3771 { | |
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
|
3772 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
|
3773 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
|
3774 |
4415 | 3775 const std::string parent = GetResourceTypeText(end, false /* plural */, false /* lower case */); |
3776 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */); | |
3777 call.GetDocumentation() | |
3778 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */)) | |
3779 .SetSummary("Get parent " + parent) | |
3780 .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
|
3781 resource + " whose Orthanc identifier is provided in the URL") |
4415 | 3782 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
3783 .AddAnswerType(MimeType_Json, "Information about the parent DICOM " + parent) | |
3784 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + parent, 10); | |
3785 return; | |
3786 } | |
3787 | |
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
|
3788 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
|
3789 |
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
|
3790 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
|
3791 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
|
3792 |
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
|
3793 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
|
3794 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
|
3795 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
|
3796 { |
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
|
3797 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
|
3798 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
|
3799 { |
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
|
3800 // 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
|
3801 // 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
|
3802 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
|
3803 } |
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
|
3804 |
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
|
3805 current = parent; |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
3806 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
|
3807 } |
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
|
3808 |
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
|
3809 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
|
3810 |
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
|
3811 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
|
3812 |
4554 | 3813 Json::Value resource; |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3814 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3815 if (true) |
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
|
3816 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3817 /** |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3818 * EXPERIMENTAL VERSION |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3819 **/ |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3820 if (ExpandResource(resource, OrthancRestApi::GetIndex(call), currentType, current, format, false)) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3821 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3822 call.GetOutput().AnswerJson(resource); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3823 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3824 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3825 else |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3826 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3827 /** |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3828 * VERSION IN ORTHANC <= 1.12.4 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3829 **/ |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3830 if (OrthancRestApi::GetContext(call).ExpandResource(resource, current, end, format, requestedTags, true /* allowStorageAccess */)) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3831 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3832 call.GetOutput().AnswerJson(resource); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
3833 } |
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
|
3834 } |
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
|
3835 } |
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
|
3836 |
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
|
3837 |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3838 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
|
3839 { |
4407 | 3840 if (call.IsDocumentation()) |
3841 { | |
3842 call.GetDocumentation() | |
3843 .SetTag("Instances") | |
3844 .SetSummary("Get embedded PDF") | |
3845 .SetDescription("Get the PDF file that is embedded in one DICOM instance. " | |
3846 "If the DICOM instance doesn't contain the `EncapsulatedDocument` tag or if the " | |
3847 "`MIMETypeOfEncapsulatedDocument` tag doesn't correspond to the PDF type, a `404` HTTP error is raised.") | |
3848 .SetUriArgument("id", "Orthanc identifier of the instance interest") | |
3849 .AddAnswerType(MimeType_Pdf, "PDF file"); | |
3850 return; | |
3851 } | |
3852 | |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3853 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
|
3854 std::string pdf; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3855 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
|
3856 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3857 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
|
3858 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3859 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
|
3860 return; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3861 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3862 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3863 |
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
|
3864 |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3865 static void OrderSlices(RestApiGetCall& call) |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3866 { |
4421 | 3867 if (call.IsDocumentation()) |
3868 { | |
3869 call.GetDocumentation() | |
3870 .SetDeprecated() | |
3871 .SetTag("Series") | |
3872 .SetSummary("Order the slices") | |
3873 .SetDescription("Sort the instances and frames (slices) of the DICOM series whose Orthanc identifier is provided in the URL. " | |
3874 "This URI is essentially used by the Orthanc Web viewer and by the Osimis Web viewer.") | |
3875 .SetUriArgument("id", "Orthanc identifier of the series of interest") | |
3876 .SetAnswerField("Dicom", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3877 "Ordered list of paths to DICOM instances") | |
3878 .SetAnswerField("Slices", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3879 "Ordered list of paths to frames. It is recommended to use this field, as it is also valid " | |
3880 "in the case of multiframe images.") | |
3881 .SetAnswerField("SlicesShort", RestApiCallDocumentation::Type_JsonListOfObjects, | |
3882 "Same information as the `Slices` field, but in a compact form") | |
3883 .SetAnswerField("Type", RestApiCallDocumentation::Type_String, | |
3884 "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
|
3885 .SetTruncatedJsonHttpGetSample("https://orthanc.uclouvain.be/demo/series/1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0/ordered-slices", 10); |
4421 | 3886 return; |
3887 } | |
3888 | |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3889 const std::string id = call.GetUriComponent("id", ""); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3890 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3891 ServerIndex& index = OrthancRestApi::GetIndex(call); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3892 SliceOrdering ordering(index, id); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3893 |
1703
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3894 Json::Value result; |
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3895 ordering.Format(result); |
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3896 call.GetOutput().AnswerJson(result); |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3897 } |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3898 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3899 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3900 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
|
3901 { |
4404 | 3902 if (call.IsDocumentation()) |
3903 { | |
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
|
3904 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full); |
4404 | 3905 call.GetDocumentation() |
3906 .SetTag("Instances") | |
3907 .SetSummary("Get DICOM meta-header") | |
3908 .SetDescription("Get the DICOM tags in the meta-header of the DICOM instance. By default, the `full` format is used, which " | |
3909 "combines hexadecimal tags with human-readable description.") | |
3910 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
3911 .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
|
3912 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/header", true); |
4404 | 3913 return; |
3914 } | |
3915 | |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3916 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
|
3917 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3918 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
|
3919 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3920 std::string dicomContent; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
3921 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
|
3922 |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3923 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to |
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3924 // speed up things here |
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3925 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3926 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
|
3927 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3928 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
|
3929 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
|
3930 |
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
|
3931 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
|
3932 } |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3933 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3934 |
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
|
3935 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
|
3936 { |
4420 | 3937 if (call.IsDocumentation()) |
3938 { | |
3939 call.GetDocumentation() | |
3940 .SetTag("System") | |
3941 .SetSummary("Invalidate DICOM-as-JSON summaries") | |
3942 .SetDescription("Remove all the attachments of the type \"DICOM-as-JSON\" that are associated will all the " | |
3943 "DICOM instances stored in Orthanc. These summaries will be automatically re-created on the next access. " | |
3944 "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
|
3945 "https://orthanc.uclouvain.be/book/faq/orthanc-storage.html#storage-area"); |
4420 | 3946 return; |
3947 } | |
3948 | |
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
|
3949 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
|
3950 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3951 // 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
|
3952 // 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
|
3953 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
|
3954 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
|
3955 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3956 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
|
3957 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
|
3958 { |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3959 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
|
3960 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
|
3961 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3962 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
|
3963 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
|
3964 { |
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
|
3965 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
|
3966 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
|
3967 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3968 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3969 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3970 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
|
3971 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3972 |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3973 void DocumentReconstructFilesField(RestApiPostCall& call, bool documentLimitField) |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3974 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3975 call.GetDocumentation() |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3976 .SetRequestField(RECONSTRUCT_FILES, RestApiCallDocumentation::Type_Boolean, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3977 "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
|
3978 "'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
|
3979 if (documentLimitField) |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3980 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3981 call.GetDocumentation() |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
3982 .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
|
3983 "Only reconstruct this level MainDicomTags by re-reading them from a random child instance of the resource. " |
5655 | 3984 "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
|
3985 "'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
|
3986 "'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
|
3987 } |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3988 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3989 |
4994 | 3990 bool GetReconstructFilesField(const RestApiPostCall& call) |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3991 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3992 bool reconstructFiles = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3993 Json::Value request; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3994 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3995 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
|
3996 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3997 if (!request[RECONSTRUCT_FILES].isBool()) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3998 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3999 throw OrthancException(ErrorCode_BadFileFormat, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4000 "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
|
4001 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4002 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4003 reconstructFiles = request[RECONSTRUCT_FILES].asBool(); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4004 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4005 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4006 return reconstructFiles; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4007 } |
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
|
4008 |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4009 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
|
4010 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4011 bool limitToThisLevel = false; |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4012 Json::Value request; |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4013 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4014 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
|
4015 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4016 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
|
4017 { |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4018 throw OrthancException(ErrorCode_BadFileFormat, |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4019 "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
|
4020 } |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4021 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4022 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
|
4023 } |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4024 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4025 return limitToThisLevel; |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4026 } |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4027 |
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4028 |
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
|
4029 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
|
4030 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
|
4031 { |
4420 | 4032 if (call.IsDocumentation()) |
4033 { | |
4034 const std::string resource = GetResourceTypeText(type, false /* plural */, false /* lower case */); | |
4035 call.GetDocumentation() | |
4036 .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
|
4037 .SetSummary("Reconstruct tags & optionally files of " + resource) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4038 .SetDescription("Reconstruct the main DICOM tags in DB of the " + resource + " whose Orthanc identifier is provided " |
4420 | 4039 "in the URL. This is useful if child studies/series/instances have inconsistent values for " |
4040 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. " | |
4041 "Beware that this is a time-consuming operation, as all the children DICOM instances will be " | |
4042 "parsed again, and the Orthanc index will be updated accordingly.") | |
4043 .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
|
4044 DocumentReconstructFilesField(call, true); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4045 |
4420 | 4046 return; |
4047 } | |
4048 | |
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
|
4049 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
|
4050 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
|
4051 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
|
4052 } |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4053 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4054 |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4055 static void ReconstructAllResources(RestApiPostCall& call) |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4056 { |
4420 | 4057 if (call.IsDocumentation()) |
4058 { | |
4059 call.GetDocumentation() | |
4060 .SetTag("System") | |
4061 .SetSummary("Reconstruct all the index") | |
4062 .SetDescription("Reconstruct the index of all the tags of all the DICOM instances that are stored in Orthanc. " | |
4063 "This is notably useful after the deletion of resources whose children resources have inconsistent " | |
4064 "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
|
4065 "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
|
4066 "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
|
4067 "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
|
4068 DocumentReconstructFilesField(call, false); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4069 |
4420 | 4070 return; |
4071 } | |
4072 | |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4073 ServerContext& context = OrthancRestApi::GetContext(call); |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4074 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4075 std::list<std::string> studies; |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4076 context.GetIndex().GetAllUuids(studies, ResourceType_Study); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
4077 bool reconstructFiles = GetReconstructFilesField(call); |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4078 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4079 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
|
4080 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
|
4081 { |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
4082 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
|
4083 } |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4084 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
4085 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
|
4086 } |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4087 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4088 |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4089 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
|
4090 ServerIndex& index, |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4091 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
|
4092 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4093 target.clear(); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4094 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4095 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
|
4096 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
|
4097 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4098 std::list<std::string> children; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4099 index.GetChildren(children, *it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4100 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4101 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
|
4102 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
|
4103 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4104 target.insert(*child); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4105 } |
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 } |
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 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4110 static void AddMetadata(Json::Value& target, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4111 ServerIndex& index, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4112 const std::string& resource, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4113 ResourceType level) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4114 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4115 target = Json::objectValue; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4116 |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4117 std::map<MetadataType, std::string> content; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4118 index.GetAllMetadata(content, resource, level); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4119 |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4120 for (std::map<MetadataType, std::string>::const_iterator |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4121 it = content.begin(); it != content.end(); ++it) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4122 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4123 target[EnumerationToString(it->first)] = it->second; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4124 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4125 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4126 |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4127 |
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 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
|
4129 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4130 static const char* const LEVEL = "Level"; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4131 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
|
4132 |
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
|
4133 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
|
4134 { |
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
|
4135 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
|
4136 |
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
|
4137 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
|
4138 .SetTag("System") |
4879 | 4139 .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
|
4140 .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
|
4141 "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
|
4142 .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
|
4143 "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
|
4144 "`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
|
4145 "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
|
4146 .SetRequestField(METADATA, RestApiCallDocumentation::Type_Boolean, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4147 "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
|
4148 .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
|
4149 "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
|
4150 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
|
4151 } |
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
|
4152 |
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
|
4153 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
|
4154 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
|
4155 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
|
4156 { |
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
|
4157 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
|
4158 "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
|
4159 } |
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
|
4160 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
|
4161 { |
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
|
4162 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
|
4163 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4164 bool metadata = true; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4165 if (request.isMember(METADATA)) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4166 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4167 metadata = SerializationToolbox::ReadBoolean(request, METADATA); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4168 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4169 |
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
|
4170 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
|
4171 |
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
|
4172 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
|
4173 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4174 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
|
4175 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4176 // 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
|
4177 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
|
4178 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4179 std::set<std::string> resources; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4180 SerializationToolbox::ReadSetOfStrings(resources, request, "Resources"); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4181 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4182 std::set<std::string> interest; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4183 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4184 assert(ResourceType_Patient < ResourceType_Study && |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4185 ResourceType_Study < ResourceType_Series && |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4186 ResourceType_Series < ResourceType_Instance); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4187 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4188 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
|
4189 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
|
4190 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4191 ResourceType type; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4192 if (index.LookupResourceType(type, *it)) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4193 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4194 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4195 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4196 // 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
|
4197 interest.insert(*it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4198 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4199 else if (type < level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4200 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4201 // Need to explore children |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4202 std::set<std::string> current; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4203 current.insert(*it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4204 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4205 for (;;) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4206 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4207 std::set<std::string> children; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4208 GetBulkChildren(children, index, current); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4209 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4210 type = GetChildResourceType(type); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4211 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4212 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4213 for (std::set<std::string>::const_iterator |
4716 | 4214 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
|
4215 { |
4716 | 4216 interest.insert(*it2); |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4217 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4218 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4219 break; // done |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4220 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4221 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4222 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4223 current.swap(children); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4224 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4225 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4226 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4227 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4228 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4229 // Need to explore parents |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4230 std::string current = *it; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4231 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4232 for (;;) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4233 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4234 std::string parent; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4235 if (index.LookupParent(parent, current)) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4236 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4237 type = GetParentResourceType(type); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4238 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4239 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4240 interest.insert(parent); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4241 break; // done |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4242 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4243 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4244 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4245 current = parent; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4246 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4247 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4248 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4249 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4250 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
|
4251 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4252 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4253 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4254 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4255 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4256 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4257 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
|
4258 } |
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
|
4259 } |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4260 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4261 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
|
4262 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
|
4263 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4264 if (true) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4265 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4266 /** |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4267 * EXPERIMENTAL VERSION |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4268 **/ |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4269 Json::Value item; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4270 if (ExpandResource(item, OrthancRestApi::GetIndex(call), level, *it, format, metadata)) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4271 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4272 answer.append(item); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4273 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4274 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4275 else |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4276 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4277 /** |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4278 * VERSION IN ORTHANC <= 1.12.4 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4279 **/ |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4280 Json::Value item; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4281 std::set<DicomTag> emptyRequestedTags; // not supported for bulk content |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4282 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4283 if (OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4284 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4285 if (metadata) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4286 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4287 AddMetadata(item[METADATA], index, *it, level); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4288 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4289 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4290 answer.append(item); |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4291 } |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4292 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4293 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4294 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4295 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4296 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4297 // 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
|
4298 std::list<std::string> resources; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4299 SerializationToolbox::ReadListOfStrings(resources, request, "Resources"); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4300 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4301 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
|
4302 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
|
4303 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4304 ResourceType level; |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4305 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
|
4306 std::set<DicomTag> emptyRequestedTags; // not supported for bulk content |
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
|
4307 |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4308 if (true) |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4309 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4310 /** |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4311 * EXPERIMENTAL VERSION |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4312 **/ |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4313 if (index.LookupResourceType(level, *it) && |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4314 ExpandResource(item, OrthancRestApi::GetIndex(call), level, *it, format, metadata)) |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4315 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4316 answer.append(item); |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
4317 } |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4318 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4319 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4320 { |
5708
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4321 /** |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4322 * VERSION IN ORTHANC <= 1.12.4 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4323 **/ |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4324 if (index.LookupResourceType(level, *it) && |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4325 OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4326 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4327 if (metadata) |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4328 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4329 AddMetadata(item[METADATA], index, *it, level); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4330 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4331 |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4332 answer.append(item); |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4333 } |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4334 else |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4335 { |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4336 CLOG(INFO, HTTP) << "Unknown resource during a bulk content retrieval: " << *it; |
1891a8c2dbb4
added ExpandResource utility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5695
diff
changeset
|
4337 } |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
4338 } |
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
|
4339 } |
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
|
4340 } |
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
|
4341 |
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 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
|
4343 } |
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
|
4344 } |
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
|
4345 |
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
|
4346 |
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
|
4347 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
|
4348 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4349 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
|
4350 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4351 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
|
4352 .SetTag("System") |
4879 | 4353 .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
|
4354 .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
|
4355 "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
|
4356 .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
|
4357 "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
|
4358 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
|
4359 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4360 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4361 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
|
4362 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4363 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
|
4364 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
|
4365 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
|
4366 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4367 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
|
4368 "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
|
4369 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4370 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
|
4371 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4372 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
|
4373 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
|
4374 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4375 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
|
4376 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
|
4377 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4378 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
|
4379 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
|
4380 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4381 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
|
4382 !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
|
4383 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4384 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
|
4385 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4386 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4387 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4388 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
|
4389 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4390 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4391 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4392 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4393 void OrthancRestApi::RegisterResources() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4394 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4395 Register("/instances", ListResources<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4396 Register("/patients", ListResources<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4397 Register("/series", ListResources<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4398 Register("/studies", ListResources<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4399 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4400 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4401 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4402 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4403 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4404 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4405 Register("/series/{id}", GetSingleResource<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4406 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4407 Register("/studies/{id}", GetSingleResource<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4408 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4409 Register("/instances/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4410 Register("/patients/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4411 Register("/studies/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4412 Register("/series/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4413 |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4414 Register("/patients/{id}/shared-tags", GetSharedTags); |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4415 Register("/series/{id}/shared-tags", GetSharedTags); |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4416 Register("/studies/{id}/shared-tags", GetSharedTags); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
4417 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4418 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4419 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4420 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4421 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4422 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
|
4423 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4424 Register("/instances/{id}/file", GetInstanceFile); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4425 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
|
4426 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
|
4427 Register("/instances/{id}/simplified-tags", GetInstanceSimplifiedTags); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4428 Register("/instances/{id}/frames", ListFrames); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4429 |
4424
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4422
diff
changeset
|
4430 Register("/instances/{id}/frames/{frame}", RestApi::AutoListChildren); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4431 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
|
4432 Register("/instances/{id}/frames/{frame}/rendered", GetRenderedFrame); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4433 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4434 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4435 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
|
4436 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
|
4437 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
|
4438 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
|
4439 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
|
4440 Register("/instances/{id}/pdf", ExtractPdf); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4441 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
|
4442 Register("/instances/{id}/rendered", GetRenderedFrame); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4443 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4444 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4445 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
4446 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
|
4447 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
|
4448 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
|
4449 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4450 Register("/patients/{id}/protected", IsProtectedPatient); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4451 Register("/patients/{id}/protected", SetPatientProtection); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4452 |
4409 | 4453 std::vector<std::string> resourceTypes; |
4454 resourceTypes.push_back("patients"); | |
4455 resourceTypes.push_back("studies"); | |
4456 resourceTypes.push_back("series"); | |
4457 resourceTypes.push_back("instances"); | |
4458 | |
4459 for (size_t i = 0; i < resourceTypes.size(); i++) | |
4460 { | |
4461 Register("/" + resourceTypes[i] + "/{id}/metadata", ListMetadata); | |
4462 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", DeleteMetadata); | |
4463 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", GetMetadata); | |
4464 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", SetMetadata); | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4465 |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4466 // New in Orthanc 1.12.0 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4467 Register("/" + resourceTypes[i] + "/{id}/labels", ListLabels); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4468 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", GetLabel); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4469 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", RemoveLabel); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4470 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", AddLabel); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4471 |
4409 | 4472 Register("/" + resourceTypes[i] + "/{id}/attachments", ListAttachments); |
4473 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", DeleteAttachment); | |
4474 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", GetAttachmentOperations); | |
4475 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", UploadAttachment); | |
4476 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>); | |
4477 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>); | |
4478 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5); | |
4479 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize); | |
4480 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/data", GetAttachmentData<1>); | |
4481 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed); | |
4482 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5); | |
4483 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize); | |
4484 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>); | |
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
|
4485 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/info", GetAttachmentInfo); |
4409 | 4486 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment); |
4487 } | |
782 | 4488 |
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
|
4489 Register("/tools/invalidate-tags", InvalidateTags); |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
4490 Register("/tools/lookup", Lookup); |
1354 | 4491 Register("/tools/find", Find); |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
4492 |
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
|
4493 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
|
4494 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
|
4495 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
|
4496 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
|
4497 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
|
4498 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
|
4499 |
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
|
4500 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
|
4501 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
|
4502 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
|
4503 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
|
4504 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
|
4505 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
|
4506 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4507 Register("/patients/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4508 Register("/studies/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4509 Register("/series/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4510 |
782 | 4511 Register("/instances/{id}/content/*", GetRawContent); |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
4512 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
4513 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
|
4514 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
|
4515 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4516 Register("/patients/{id}/reconstruct", ReconstructResource<ResourceType_Patient>); |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4517 Register("/studies/{id}/reconstruct", ReconstructResource<ResourceType_Study>); |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4518 Register("/series/{id}/reconstruct", ReconstructResource<ResourceType_Series>); |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4519 Register("/instances/{id}/reconstruct", ReconstructResource<ResourceType_Instance>); |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
4520 Register("/tools/reconstruct", ReconstructAllResources); |
4694
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4521 |
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
|
4522 Register("/tools/bulk-content", BulkContent); |
4694
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
4523 Register("/tools/bulk-delete", BulkDelete); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4524 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4525 } |