Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5431:4be5f117aa0d
metrics
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 21 Nov 2023 10:32:42 +0100 |
parents | 111e21b4f8bc |
children | 59e3b6f8c5be |
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 |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5060
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5060
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * 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
|
10 * published by the Free Software Foundation, either version 3 of the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * License, or (at your option) any later version. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * 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
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
20 **/ |
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 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
23 #include "../PrecompiledHeadersServer.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
4045 | 26 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h" |
27 #include "../../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h" | |
28 #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h" | |
29 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
30 #include "../../../OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.h" | |
31 #include "../../../OrthancFramework/Sources/HttpServer/HttpContentNegociation.h" | |
32 #include "../../../OrthancFramework/Sources/Images/Image.h" | |
33 #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
|
34 #include "../../../OrthancFramework/Sources/Images/NumpyWriter.h" |
4045 | 35 #include "../../../OrthancFramework/Sources/Logging.h" |
36 #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
|
37 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" |
4045 | 38 |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
39 #include "../OrthancConfiguration.h" |
3094
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3085
diff
changeset
|
40 #include "../Search/DatabaseLookup.h" |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1385
diff
changeset
|
41 #include "../ServerContext.h" |
2131 | 42 #include "../ServerToolbox.h" |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
43 #include "../SliceOrdering.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
3687 | 45 // This "include" is mandatory for Release builds using Linux Standard Base |
46 #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
|
47 #include <boost/shared_ptr.hpp> |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
49 /** |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
50 * 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
|
51 * 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
|
52 * 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
|
53 **/ |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
54 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
|
55 |
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
56 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
57 static const std::string CHECK_REVISIONS = "CheckRevisions"; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
58 |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
59 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
|
60 static const char* const RECONSTRUCT_FILES = "ReconstructFiles"; |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
61 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
62 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
4415 | 65 static std::string GetDocumentationSampleResource(ResourceType type) |
66 { | |
67 switch (type) | |
68 { | |
69 case Orthanc::ResourceType_Instance: | |
70 return "https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2"; | |
71 break; | |
72 | |
73 case Orthanc::ResourceType_Series: | |
74 return "https://demo.orthanc-server.com/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52"; | |
75 break; | |
76 | |
77 case Orthanc::ResourceType_Study: | |
78 return "https://demo.orthanc-server.com/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988"; | |
79 break; | |
80 | |
81 case Orthanc::ResourceType_Patient: | |
82 return "https://demo.orthanc-server.com/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382"; | |
83 break; | |
84 | |
85 default: | |
86 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
87 } | |
88 } | |
89 | |
90 | |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
91 static void AnswerDicomAsJson(RestApiCall& call, |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
92 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
|
93 DicomToJsonFormat mode) |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
94 { |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
95 if (mode != DicomToJsonFormat_Full) |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
96 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
97 Json::Value simplified; |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
98 Toolbox::SimplifyDicomAsJson(simplified, dicom, mode); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
99 call.GetOutput().AnswerJson(simplified); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
100 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
101 else |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
102 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
103 call.GetOutput().AnswerJson(dicom); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
104 } |
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 |
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 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
|
109 const RestApiGetCall& call, |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
110 const std::string& argument) |
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 target.clear(); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
113 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
114 if (call.HasArgument(argument)) |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
115 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
116 std::vector<std::string> tags; |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
117 Toolbox::TokenizeString(tags, call.GetArgument(argument, ""), ','); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
118 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
119 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
|
120 { |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
121 target.insert(FromDcmtkBridge::ParseTag(tags[i])); |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
122 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
123 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
124 } |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
125 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
126 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 // List all the patients, studies, series or instances ---------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
1354 | 129 static void AnswerListOfResources(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
|
130 ServerContext& context, |
1354 | 131 const std::list<std::string>& resources, |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
132 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
|
133 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
|
134 const std::map<std::string, boost::shared_ptr<Json::Value> >& resourcesDicomAsJson, // optional: the dicom-as-json for each resource |
1354 | 135 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
|
136 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
|
137 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
|
138 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
|
139 bool allowStorageAccess) |
1354 | 140 { |
141 Json::Value answer = Json::arrayValue; | |
142 | |
143 for (std::list<std::string>::const_iterator | |
1384 | 144 resource = resources.begin(); resource != resources.end(); ++resource) |
1354 | 145 { |
146 if (expand) | |
147 { | |
4554 | 148 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
|
149 |
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
|
150 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
|
151 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
|
152 { |
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
|
153 // 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
|
154 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
|
155 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
|
156 |
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
|
157 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
|
158 *(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
|
159 instanceId->second, |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
160 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
|
161 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
|
162 } |
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
|
163 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
|
164 { |
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
|
165 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
|
166 } |
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
|
167 |
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
|
168 if (expanded.type() == Json::objectValue) |
1354 | 169 { |
4554 | 170 answer.append(expanded); |
1354 | 171 } |
172 } | |
173 else | |
174 { | |
175 answer.append(*resource); | |
176 } | |
177 } | |
178 | |
179 output.AnswerJson(answer); | |
180 } | |
181 | |
182 | |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
183 static void AnswerListOfResources(RestApiOutput& output, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
184 ServerContext& context, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
185 const std::list<std::string>& resources, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
186 ResourceType level, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
187 bool expand, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
188 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
|
189 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
|
190 bool allowStorageAccess) |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
191 { |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
192 std::map<std::string, std::string> unusedInstancesIds; |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
193 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
|
194 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
|
195 |
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
|
196 AnswerListOfResources(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
|
197 } |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
198 |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
199 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 template <enum ResourceType resourceType> |
974 | 201 static void ListResources(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 { |
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
|
203 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
|
204 { |
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
|
205 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
|
206 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
|
207 |
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
|
208 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
|
209 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
|
210 .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
|
211 .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
|
212 .SetDescription("List the Orthanc identifiers of all the available DICOM " + resources) |
4403 | 213 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) |
214 .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
|
215 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, |
4403 | 216 "If present, retrieve detailed information about the individual " + resources, false) |
4404 | 217 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " |
218 "about the reported " + resources + " (if `expand` argument is provided)") | |
4401
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4399
diff
changeset
|
219 .SetHttpGetSample("https://demo.orthanc-server.com/" + resources + "?since=0&limit=2", true); |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
220 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
|
221 } |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
222 |
1342
9ec7ac03152d
"?expand" flag for URIs "/patients", "/studies" and "/series"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1303
diff
changeset
|
223 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
|
224 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
|
225 |
1354 | 226 std::list<std::string> result; |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
227 |
4936
8422e4f99a18
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4935
diff
changeset
|
228 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
|
229 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
|
230 |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
231 if (call.HasArgument("limit") || |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
232 call.HasArgument("since")) |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
233 { |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
234 if (!call.HasArgument("limit")) |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
235 { |
2955 | 236 throw OrthancException(ErrorCode_BadRequest, |
237 "Missing \"limit\" argument for GET request against: " + | |
238 call.FlattenUri()); | |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
239 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
240 |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
241 if (!call.HasArgument("since")) |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
242 { |
2955 | 243 throw OrthancException(ErrorCode_BadRequest, |
244 "Missing \"since\" argument for GET request against: " + | |
245 call.FlattenUri()); | |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
246 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
247 |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
248 size_t since = boost::lexical_cast<size_t>(call.GetArgument("since", "")); |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
249 size_t limit = boost::lexical_cast<size_t>(call.GetArgument("limit", "")); |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
250 index.GetAllUuids(result, resourceType, since, limit); |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
251 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
252 else |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
253 { |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
254 index.GetAllUuids(result, resourceType); |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
255 } |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
256 |
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
|
257 AnswerListOfResources(call.GetOutput(), context, result, resourceType, call.HasArgument("expand") && call.GetBooleanArgument("expand", true), |
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
|
258 OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human), |
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
|
259 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
|
260 true /* allowStorageAccess */); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 |
4409 | 263 |
264 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 template <enum ResourceType resourceType> |
974 | 266 static void GetSingleResource(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 { |
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 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
|
269 { |
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
|
270 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
|
271 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
|
272 |
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
|
273 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
|
274 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
|
275 .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
|
276 .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
|
277 .SetDescription("Get detailed information about the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
4404 | 278 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
4409 | 279 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) |
280 .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
|
281 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
|
282 } |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
283 |
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
|
284 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
|
285 |
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
|
286 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
|
287 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
|
288 |
4554 | 289 Json::Value json; |
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
|
290 if (OrthancRestApi::GetContext(call).ExpandResource( |
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
|
291 json, call.GetUriComponent("id", ""), resourceType, format, requestedTags, true /* allowStorageAccess */)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 { |
4554 | 293 call.GetOutput().AnswerJson(json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 template <enum ResourceType resourceType> |
974 | 298 static void DeleteSingleResource(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 { |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
300 if (call.IsDocumentation()) |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
301 { |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
302 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
|
303 call.GetDocumentation() |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
304 .SetTag(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
|
305 .SetSummary("Delete some " + resource) |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
306 .SetDescription("Delete the DICOM " + resource + " whose Orthanc identifier is provided in the URL") |
4404 | 307 .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
|
308 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
|
309 } |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
310 |
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
|
311 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
|
312 if (OrthancRestApi::GetContext(call).DeleteResource(remainingAncestor, call.GetUriComponent("id", ""), resourceType)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 { |
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
|
314 call.GetOutput().AnswerJson(remainingAncestor); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 // Get information about a single patient ----------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 |
974 | 321 static void IsProtectedPatient(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 { |
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
|
323 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
|
324 { |
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
|
325 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
|
326 .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
|
327 .SetSummary("Is the patient protected against recycling?") |
4404 | 328 .SetUriArgument("id", "Orthanc identifier of the patient of interest") |
4403 | 329 .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
|
330 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
|
331 } |
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
|
332 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
335 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 |
974 | 339 static void SetPatientProtection(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
340 { |
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
|
341 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
|
342 { |
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
|
343 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
|
344 .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
|
345 .SetSummary("Protect one patient against recycling") |
4403 | 346 .SetDescription("Check out configuration options `MaximumStorageSize` and `MaximumPatientCount`") |
4404 | 347 .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
|
348 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
|
349 } |
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
|
350 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 |
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
|
355 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
|
356 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 // Get information about a single instance ---------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 |
974 | 362 static void GetInstanceFile(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 { |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
364 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
|
365 |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
366 if (call.IsDocumentation()) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
367 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
368 call.GetDocumentation() |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
369 .SetTag("Instances") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
370 .SetSummary("Download DICOM") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
371 .SetDescription("Download one DICOM instance") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
372 .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
|
373 .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
|
374 .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
|
375 "If present, the DICOM file will be transcoded to the provided " |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
376 "transfer syntax: https://book.orthanc-server.com/faq/transcoding.html", false) |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
377 .AddAnswerType(MimeType_Dicom, "The DICOM instance") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
378 .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
|
379 .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
|
380 return; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
381 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
382 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 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
|
386 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4294
diff
changeset
|
387 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
|
388 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
|
389 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
390 // 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
|
391 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
|
392 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
393 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
|
394 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
395 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
|
396 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
|
397 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
398 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
|
399 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
400 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
401 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
|
402 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
|
403 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
404 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
405 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
|
406 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
407 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
|
408 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
|
409 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
410 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
|
411 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
412 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
|
413 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
|
414 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
|
415 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
416 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
417 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
|
418 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
419 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
420 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
|
421 { |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
422 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
423 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
424 |
5426
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
425 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
|
426 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
427 std::string source; |
5427 | 428 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
|
429 std::string transcoded; |
5427 | 430 context.ReadDicom(source, attachmentId, publicId); |
431 | |
432 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
|
433 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
434 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
|
435 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
436 } |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
437 else |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
438 { |
c65e036d649b
StorageCache is now storing transcoded instances + added ?transcode=... option to the /file route.
Alain Mazy <am@osimis.io>
parents:
5424
diff
changeset
|
439 // 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
|
440 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
|
441 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 |
974 | 445 static void ExportInstanceFile(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
446 { |
4421 | 447 if (call.IsDocumentation()) |
448 { | |
449 call.GetDocumentation() | |
450 .SetTag("Instances") | |
451 .SetSummary("Write DICOM onto filesystem") | |
5200
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
452 .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
|
453 "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
|
454 "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
|
455 "the `RestApiWriteToFileSystemEnabled` configuration option.") |
4421 | 456 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
457 .AddRequestType(MimeType_PlainText, "Target path on the filesystem"); | |
458 return; | |
459 } | |
460 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
461 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
462 |
5200
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
463 if (!context.IsRestApiWriteToFileSystemEnabled()) |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
464 { |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
465 LOG(ERROR) << "The URI /instances/../export is disallowed for security, " |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
466 << "check your configuration option `RestApiWriteToFileSystemEnabled`"; |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
467 call.GetOutput().SignalError(HttpStatus_403_Forbidden); |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
468 return; |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
469 } |
f8f1c4a9a216
New configuration option 'RestApiWriteToFileSystemEnabled'
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
470 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
471 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
472 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 std::string dicom; |
2124 | 474 context.ReadDicom(dicom, publicId); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
476 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
|
477 call.BodyToString(target); |
2140 | 478 SystemToolbox::WriteFile(dicom, target); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
480 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
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 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
484 template <DicomToJsonFormat format> |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
485 static void GetInstanceTagsInternal(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
486 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
488 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
489 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
|
490 |
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
491 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
|
492 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
494 if (format != DicomToJsonFormat_Full || |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
495 !ignoreTagLength.empty()) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 { |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
497 Json::Value full; |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
498 context.ReadDicomAsJson(full, publicId, ignoreTagLength); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
499 AnswerDicomAsJson(call, full, format); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 { |
3973
d86bddb50972
fix spelling errors according to debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3928
diff
changeset
|
503 // This path allows one to avoid the JSON decoding if no |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
504 // simplification is asked, and if no "ignore-length" argument |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
505 // is present |
4513
1f455b86b054
simplification in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4473
diff
changeset
|
506 Json::Value full; |
2127 | 507 context.ReadDicomAsJson(full, publicId); |
4513
1f455b86b054
simplification in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4473
diff
changeset
|
508 call.GetOutput().AnswerJson(full); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
509 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
510 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
511 |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
512 |
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
|
513 static void GetInstanceTags(RestApiGetCall& call) |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
514 { |
4404 | 515 if (call.IsDocumentation()) |
516 { | |
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
|
517 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full); |
4404 | 518 call.GetDocumentation() |
519 .SetTag("Instances") | |
520 .SetSummary("Get DICOM tags") | |
521 .SetDescription("Get the DICOM tags in the specified format. By default, the `full` format is used, which " | |
522 "combines hexadecimal tags with human-readable description.") | |
523 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
524 .SetHttpGetArgument(IGNORE_LENGTH, RestApiCallDocumentation::Type_JsonListOfStrings, |
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
525 "Also include the DICOM tags that are provided in this list, even if their associated value is long", false) |
4404 | 526 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value") |
4415 | 527 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10); |
4404 | 528 return; |
529 } | |
530 | |
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
|
531 switch (OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)) |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
532 { |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
533 case DicomToJsonFormat_Human: |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
534 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
535 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
536 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
537 case DicomToJsonFormat_Short: |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
538 GetInstanceTagsInternal<DicomToJsonFormat_Short>(call); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
539 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
540 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
541 case DicomToJsonFormat_Full: |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
542 GetInstanceTagsInternal<DicomToJsonFormat_Full>(call); |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
543 break; |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
544 |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
545 default: |
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
546 throw OrthancException(ErrorCode_InternalError); |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
547 } |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
548 } |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
549 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
550 |
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
|
551 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
|
552 { |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
553 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
|
554 { |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
555 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
|
556 .SetTag("Instances") |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
557 .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
|
558 .SetDescription("Get the DICOM tags in human-readable format (same as the `/instances/{id}/tags?simplify` route)") |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
559 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") |
4722
2b4da0ee6b73
added missing documentation of "ignore-length" in "/instances/{id}/tags"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4716
diff
changeset
|
560 .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
|
561 "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
|
562 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value") |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
563 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", 10); |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
564 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
|
565 } |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
566 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
|
567 { |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
568 GetInstanceTagsInternal<DicomToJsonFormat_Human>(call); |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
569 } |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
570 } |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
571 |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
572 |
974 | 573 static void ListFrames(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
574 { |
4414 | 575 if (call.IsDocumentation()) |
576 { | |
577 call.GetDocumentation() | |
578 .SetTag("Instances") | |
579 .SetSummary("List available frames") | |
580 .SetDescription("List the frames that are available in the DICOM instance of interest") | |
581 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
582 .AddAnswerType(MimeType_Json, "The list of the indices of the available frames") | |
583 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/frames", true); | |
584 return; | |
585 } | |
586 | |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
587 std::string publicId = call.GetUriComponent("id", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
588 |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
589 unsigned int numberOfFrames; |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
590 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
591 { |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
592 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
|
593 numberOfFrames = locker.GetDicom().GetFramesCount(); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
594 } |
1950
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
595 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
596 Json::Value result = Json::arrayValue; |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
597 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
|
598 { |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
599 result.append(i); |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
600 } |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
601 |
533ff46e944b
return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
602 call.GetOutput().AnswerJson(result); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
603 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
604 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
605 |
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
|
606 namespace |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
607 { |
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
|
608 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
|
609 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
610 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
611 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
|
612 ImageExtractionMode mode_; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
613 bool invert_; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
614 MimeType format_; |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
615 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
|
616 |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
617 public: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
618 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
|
619 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
620 bool invert) : |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
621 image_(image), |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
622 mode_(mode), |
4205 | 623 invert_(invert), |
624 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
|
625 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
626 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
627 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
628 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
|
629 { |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
630 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
|
631 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
632 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
633 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
|
634 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
635 format_ = MimeType_Png; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
636 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
|
637 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
638 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
639 void EncodeUsingPam() |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
640 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
641 format_ = MimeType_Pam; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
642 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
|
643 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
644 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
645 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
|
646 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
647 format_ = MimeType_Jpeg; |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
648 DicomImageDecoder::ExtractJpegImage(answer_, image_, mode_, invert_, quality); |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1784
diff
changeset
|
649 } |
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
|
650 }; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
651 |
1784
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
652 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
|
653 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
654 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
|
655 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
|
656 |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
657 public: |
4205 | 658 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
|
659 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
660 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
661 |
1784
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
662 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
|
663 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
664 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
|
665 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
666 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
|
667 assert(subtype == "png"); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
668 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
|
669 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
670 }; |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
671 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
672 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
|
673 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
674 private: |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
675 ImageToEncode& image_; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
676 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
677 public: |
4205 | 678 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
|
679 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
680 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
681 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
682 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
|
683 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
684 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
|
685 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
686 assert(type == "image"); |
2780 | 687 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
|
688 image_.EncodeUsingPam(); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
689 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
690 }; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2622
diff
changeset
|
691 |
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
|
692 class EncodeJpeg : public HttpContentNegociation::IHandler |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
693 { |
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
|
694 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
|
695 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
|
696 unsigned int quality_; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
697 |
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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
703 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
|
704 bool ok = false; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
705 |
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
|
706 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
|
707 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
708 quality_ = boost::lexical_cast<unsigned int>(v); |
1847 | 709 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
|
710 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
711 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
|
712 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
713 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
714 |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
715 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
|
716 { |
2955 | 717 throw OrthancException( |
718 ErrorCode_BadRequest, | |
719 "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
|
720 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
721 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
722 |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
723 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
|
724 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5275
diff
changeset
|
725 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
|
726 { |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
727 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
|
728 assert(subtype == "jpeg"); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
729 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
|
730 } |
2dbf25006f88
".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1781
diff
changeset
|
731 }; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
732 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
733 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1773
diff
changeset
|
734 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
735 namespace |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
736 { |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
737 class IDecodedFrameHandler : public boost::noncopyable |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
738 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
739 public: |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
740 virtual ~IDecodedFrameHandler() |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
741 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
742 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
743 |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
744 // "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
|
745 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
|
746 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
|
747 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
748 unsigned int frame) = 0; |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
749 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
750 virtual bool RequiresDicomTags() const = 0; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
751 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
752 static void Apply(RestApiGetCall& call, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
753 IDecodedFrameHandler& handler, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
754 ImageExtractionMode mode /* for generation of documentation */, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
755 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
|
756 { |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
757 if (call.IsDocumentation()) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
758 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
759 std::string m; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
760 if (!isRendered) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
761 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
762 switch (mode) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
763 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
764 case ImageExtractionMode_Preview: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
765 m = "preview"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
766 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
767 case ImageExtractionMode_UInt8: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
768 m = "uint8"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
769 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
770 case ImageExtractionMode_UInt16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
771 m = "uint16"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
772 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
773 case ImageExtractionMode_Int16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
774 m = "int16"; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
775 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
776 default: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
777 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
778 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
779 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
780 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
781 std::string description; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
782 std::string verb = (isRendered ? "Render" : "Decode"); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
783 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
784 if (call.HasUriComponent("frame")) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
785 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
786 description = verb + " one frame of interest from the given DICOM instance."; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
787 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
788 .SetSummary(verb + " a frame" + (m.empty() ? "" : " (" + m + ")")) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
789 .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
|
790 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
791 else |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
792 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
793 description = verb + " the first frame of the given DICOM instance."; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
794 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
795 .SetSummary(verb + " an image" + (m.empty() ? "" : " (" + m + ")")); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
796 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
797 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
798 if (isRendered) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
799 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
800 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
|
801 "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
|
802 "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
|
803 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
804 .SetHttpGetArgument("window-center",RestApiCallDocumentation::Type_Number, "Windowing center", false) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
805 .SetHttpGetArgument("window-width",RestApiCallDocumentation::Type_Number, "Windowing width", false) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
806 .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
|
807 .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
|
808 .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
|
809 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
810 else |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
811 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
812 switch (mode) |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
813 { |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
814 case ImageExtractionMode_Preview: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
815 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
|
816 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
817 case ImageExtractionMode_UInt8: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
818 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
|
819 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
820 case ImageExtractionMode_UInt16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
821 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
|
822 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
823 case ImageExtractionMode_Int16: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
824 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
|
825 "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
|
826 break; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
827 default: |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
828 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
829 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
830 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
831 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
832 call.GetDocumentation() |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
833 .SetTag("Instances") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
834 .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
|
835 .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
|
836 .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
|
837 .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
|
838 .AddAnswerType(MimeType_Png, "PNG image") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
839 .AddAnswerType(MimeType_Jpeg, "JPEG image") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
840 .AddAnswerType(MimeType_Pam, "PAM image (Portable Arbitrary Map)") |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
841 .SetDescription(description); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
842 |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
843 return; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
844 } |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
845 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
846 ServerContext& context = OrthancRestApi::GetContext(call); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
847 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
848 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
|
849 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
850 unsigned int frame; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
851 try |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
852 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
853 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
|
854 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
855 catch (boost::bad_lexical_cast&) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
856 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
857 return; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
858 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
859 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
860 std::unique_ptr<ImageAccessor> decoded; |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
861 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
862 try |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
863 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
864 std::string publicId = call.GetUriComponent("id", ""); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
865 |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
866 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
|
867 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
868 if (decoded.get() == NULL) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
869 { |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
870 throw OrthancException(ErrorCode_NotImplemented, |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
871 "Cannot decode DICOM instance with ID: " + publicId); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
872 } |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
873 |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
874 if (handler.RequiresDicomTags()) |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
875 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
876 /** |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
877 * Retrieve a summary of the DICOM tags, which is |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
878 * necessary to deal with MONOCHROME1 photometric |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
879 * interpretation, and with windowing parameters. |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
880 **/ |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
881 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
|
882 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
|
883 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
884 else |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
885 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
886 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
|
887 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
888 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
889 catch (OrthancException& e) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
890 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
891 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange || |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
892 e.GetErrorCode() == ErrorCode_UnknownResource) |
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 // 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
|
895 // instance, the resource is not existent |
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 else |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
898 { |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
899 if (call.HasArgument("returnUnsupportedImage")) |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
900 { |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
901 std::string root = ""; |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
902 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
|
903 { |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
904 root += "../"; |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
905 } |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
906 |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
907 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
|
908 } |
4804
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
909 else |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
910 { |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
911 call.GetOutput().SignalError(HttpStatus_415_UnsupportedMediaType); |
ae643f664628
new option returnUnsupportedImage for /preview & /rendered routes
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
912 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
913 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
914 return; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
915 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
916 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
917 } |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
918 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
919 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
920 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
|
921 std::unique_ptr<ImageAccessor>& decoded, |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
922 ImageExtractionMode mode, |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
923 bool invert) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
924 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
925 ImageToEncode image(decoded, mode, invert); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
926 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
927 HttpContentNegociation negociation; |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
928 EncodePng png(image); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
929 negociation.Register(MIME_PNG, png); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
930 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
931 EncodeJpeg jpeg(image, call); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
932 negociation.Register(MIME_JPEG, jpeg); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
933 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
934 EncodePam pam(image); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
935 negociation.Register(MIME_PAM, pam); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
936 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
937 if (negociation.Apply(call.GetHttpHeaders())) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
938 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
939 image.Answer(call.GetOutput()); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
940 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
941 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
942 }; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
943 |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
944 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
945 class GetImageHandler : public IDecodedFrameHandler |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
946 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
947 private: |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
948 ImageExtractionMode mode_; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
949 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
950 public: |
4205 | 951 explicit GetImageHandler(ImageExtractionMode mode) : |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
952 mode_(mode) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
953 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
954 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
955 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
956 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
|
957 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
|
958 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
959 unsigned int frame) ORTHANC_OVERRIDE |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
960 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
961 bool invert = false; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
962 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
963 if (mode_ == ImageExtractionMode_Preview) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
964 { |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
965 if (dicom == NULL) |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
966 { |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
967 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
|
968 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
969 |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
970 DicomMap tags; |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
971 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
|
972 |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
973 DicomImageInformation info(tags); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
974 invert = (info.GetPhotometricInterpretation() == PhotometricInterpretation_Monochrome1); |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
975 } |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
976 |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
977 DefaultHandler(call, decoded, mode_, invert); |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
978 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
979 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
980 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
981 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
982 return mode_ == ImageExtractionMode_Preview; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
983 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
984 }; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
985 |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
986 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
987 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
|
988 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
989 private: |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
990 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
|
991 double& windowCenter /* inout */, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
992 unsigned int& argWidth, |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
993 unsigned int& argHeight, |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
994 bool& smooth, |
4205 | 995 const RestApiGetCall& call) |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
996 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
997 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
|
998 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
|
999 static const char* ARG_WIDTH = "width"; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1000 static const char* ARG_HEIGHT = "height"; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1001 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
|
1002 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1003 if (call.HasArgument(ARG_WINDOW_WIDTH) && |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1004 !SerializationToolbox::ParseDouble(windowWidth, call.GetArgument(ARG_WINDOW_WIDTH, ""))) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1005 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1006 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1007 "Bad value for argument: " + std::string(ARG_WINDOW_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1008 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1009 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1010 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
|
1011 !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
|
1012 { |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1013 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
|
1014 "Bad value for argument: " + std::string(ARG_WINDOW_CENTER)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1015 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1016 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1017 argWidth = 0; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1018 argHeight = 0; |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1019 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1020 if (call.HasArgument(ARG_WIDTH)) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1021 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1022 try |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1023 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1024 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
|
1025 if (tmp < 0) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1026 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1027 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1028 "Argument cannot be negative: " + std::string(ARG_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1029 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1030 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1031 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1032 argWidth = static_cast<unsigned int>(tmp); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1033 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1034 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1035 catch (boost::bad_lexical_cast&) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1036 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1037 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1038 "Bad value for argument: " + std::string(ARG_WIDTH)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1039 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1040 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1041 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1042 if (call.HasArgument(ARG_HEIGHT)) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1043 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1044 try |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1045 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1046 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
|
1047 if (tmp < 0) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1048 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1049 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1050 "Argument cannot be negative: " + std::string(ARG_HEIGHT)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1051 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1052 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1053 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1054 argHeight = static_cast<unsigned int>(tmp); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1055 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1056 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1057 catch (boost::bad_lexical_cast&) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1058 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1059 throw OrthancException(ErrorCode_ParameterOutOfRange, |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1060 "Bad value for argument: " + std::string(ARG_HEIGHT)); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1061 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1062 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1063 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1064 smooth = false; |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1065 |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1066 if (call.HasArgument(ARG_SMOOTH)) |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1067 { |
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
|
1068 smooth = RestApiCall::ParseBoolean(call.GetArgument(ARG_SMOOTH, "")); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1069 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1070 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1071 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1072 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1073 public: |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1074 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
|
1075 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
|
1076 const ParsedDicomFile* dicom, |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1077 unsigned int frame) ORTHANC_OVERRIDE |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1078 { |
4769
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1079 if (dicom == NULL) |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1080 { |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1081 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
|
1082 } |
9da6ca57a977
IDecodedFrameHandler can access full ParsedDicomFile instead of the DicomMap summary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4722
diff
changeset
|
1083 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1084 PhotometricInterpretation photometric; |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1085 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
|
1086 photometric == PhotometricInterpretation_Monochrome1); |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1087 |
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1088 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
|
1089 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
|
1090 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
|
1091 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1092 unsigned int argWidth, argHeight; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1093 bool smooth; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1094 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
|
1095 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1096 unsigned int targetWidth = decoded->GetWidth(); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1097 unsigned int targetHeight = decoded->GetHeight(); |
3686 | 1098 |
1099 if (decoded->GetWidth() != 0 && | |
1100 decoded->GetHeight() != 0) | |
1101 { | |
1102 float ratio = 1; | |
1103 | |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1104 if (argWidth != 0 && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1105 argHeight != 0) |
3686 | 1106 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1107 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
|
1108 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
|
1109 ratio = std::min(ratioX, ratioY); |
3686 | 1110 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1111 else if (argWidth != 0) |
3686 | 1112 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1113 ratio = static_cast<float>(argWidth) / static_cast<float>(decoded->GetWidth()); |
3686 | 1114 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1115 else if (argHeight != 0) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1116 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1117 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
|
1118 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1119 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1120 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
|
1121 targetHeight = boost::math::iround(ratio * static_cast<float>(decoded->GetHeight())); |
3686 | 1122 } |
1123 | |
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
|
1124 if (decoded->GetFormat() == PixelFormat_RGB24 || decoded->GetFormat() == PixelFormat_RGB48) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1125 { |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1126 if (targetWidth == decoded->GetWidth() && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1127 targetHeight == decoded->GetHeight()) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1128 { |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1129 DefaultHandler(call, decoded, ImageExtractionMode_Preview, false); |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1130 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1131 else |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1132 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1133 std::unique_ptr<ImageAccessor> resized( |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1134 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
|
1135 |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1136 if (smooth && |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1137 (targetWidth < decoded->GetWidth() || |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1138 targetHeight < decoded->GetHeight())) |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1139 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
1140 ImageProcessing::SmoothGaussian5x5(*decoded, false /* be fast, don't round */); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1141 } |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1142 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1143 ImageProcessing::Resize(*resized, *decoded); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1144 DefaultHandler(call, resized, ImageExtractionMode_Preview, false); |
3685
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1145 } |
2cc34837d694
rendering of RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3683
diff
changeset
|
1146 } |
3686 | 1147 else |
1148 { | |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1149 // 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
|
1150 // 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
|
1151 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1152 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
|
1153 ImageProcessing::Convert(converted, *decoded); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1154 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1155 // Avoid divisions by zero |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1156 if (windowWidth <= 1.0f) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1157 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1158 windowWidth = 1; |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1159 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1160 |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1161 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
|
1162 { |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1163 rescaleSlope = 0.0001; |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1164 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1165 |
4777
3b78ba359db3
Support detection of windowing and rescale in Philips multiframe images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4769
diff
changeset
|
1166 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
|
1167 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
|
1168 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1169 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
|
1170 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
|
1171 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1172 if (targetWidth == decoded->GetWidth() && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1173 targetHeight == decoded->GetHeight()) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1174 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1175 DefaultHandler(call, rescaled, ImageExtractionMode_UInt8, invert); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1176 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1177 else |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1178 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3690
diff
changeset
|
1179 std::unique_ptr<ImageAccessor> resized( |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1180 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
|
1181 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1182 if (smooth && |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1183 (targetWidth < decoded->GetWidth() || |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1184 targetHeight < decoded->GetHeight())) |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1185 { |
4065
d6362b2c4b61
export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
1186 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
|
1187 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1188 |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1189 ImageProcessing::Resize(*resized, *rescaled); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1190 DefaultHandler(call, resized, ImageExtractionMode_UInt8, invert); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3687
diff
changeset
|
1191 } |
3686 | 1192 } |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1193 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1194 |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1195 virtual bool RequiresDicomTags() const ORTHANC_OVERRIDE |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1196 { |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1197 return true; |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1198 } |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1199 }; |
3600
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1200 } |
4066998150ef
/instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents:
3203
diff
changeset
|
1201 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1202 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1203 template <enum ImageExtractionMode mode> |
974 | 1204 static void GetImage(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1205 { |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1206 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
|
1207 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1208 GetImageHandler handler(mode); |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1209 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
|
1210 } |
1906
d7c1cb559431
optimization for multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1902
diff
changeset
|
1211 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1212 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1213 static void GetRenderedFrame(RestApiGetCall& call) |
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1214 { |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1215 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
|
1216 |
3683
12253ddefe5a
skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1217 RenderedFrameHandler handler; |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
1218 IDecodedFrameHandler::Apply(call, handler, ImageExtractionMode_Preview /* arbitrary value */, true); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1219 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1220 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1221 |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1222 static void DocumentSharedNumpy(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1223 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1224 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1225 .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
|
1226 .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
|
1227 .SetHttpGetArgument("rescale", RestApiCallDocumentation::Type_Boolean, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1228 "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
|
1229 .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
|
1230 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1231 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1232 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1233 namespace |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1234 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1235 class NumpyVisitor : public boost::noncopyable |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1236 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1237 private: |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1238 bool rescale_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1239 unsigned int depth_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1240 unsigned int currentDepth_; |
4858 | 1241 unsigned int width_; |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1242 unsigned int height_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1243 PixelFormat format_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1244 ChunkedBuffer buffer_; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1245 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1246 public: |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1247 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
|
1248 bool rescale) : |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1249 rescale_(rescale), |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1250 depth_(depth), |
4858 | 1251 currentDepth_(0), |
1252 width_(0), // dummy initialization | |
1253 height_(0), // dummy initialization | |
1254 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
|
1255 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1256 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1257 |
4858 | 1258 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
|
1259 unsigned int frame) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1260 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1261 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
|
1262 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1263 if (decoded.get() == NULL) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1264 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1265 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
|
1266 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1267 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1268 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1269 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1270 width_ = decoded->GetWidth(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1271 height_ = decoded->GetHeight(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1272 format_ = decoded->GetFormat(); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1273 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1274 else if (width_ != decoded->GetWidth() || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1275 height_ != decoded->GetHeight()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1276 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1277 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
|
1278 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1279 else if (format_ != decoded->GetFormat()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1280 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1281 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
|
1282 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1283 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1284 if (rescale_ && |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1285 decoded->GetFormat() != PixelFormat_RGB24) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1286 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1287 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1288 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1289 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
|
1290 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1291 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1292 double rescaleIntercept, rescaleSlope; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1293 dicom.GetRescale(rescaleIntercept, rescaleSlope, frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1294 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1295 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
|
1296 ImageProcessing::Convert(converted, *decoded); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1297 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
|
1298 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1299 NumpyWriter::WritePixels(buffer_, converted); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1300 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1301 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1302 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1303 if (currentDepth_ == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1304 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1305 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
|
1306 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1307 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1308 NumpyWriter::WritePixels(buffer_, *decoded); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1309 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1310 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1311 currentDepth_ ++; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1312 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1313 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1314 void Answer(RestApiOutput& output, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1315 bool compress) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1316 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1317 if ((depth_ == 0 && currentDepth_ != 1) || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1318 (depth_ != 0 && currentDepth_ != depth_)) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1319 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1320 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1321 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1322 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1323 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1324 std::string answer; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1325 NumpyWriter::Finalize(answer, buffer_, compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1326 output.AnswerBuffer(answer, MimeType_Binary); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1327 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1328 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1329 }; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1330 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1331 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1332 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1333 static void GetNumpyFrame(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1334 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1335 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1336 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1337 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1338 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1339 .SetTag("Instances") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1340 .SetSummary("Decode frame for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1341 .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
|
1342 "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
|
1343 .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
|
1344 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1345 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1346 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1347 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
|
1348 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
|
1349 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
|
1350 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1351 uint32_t frame; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1352 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
|
1353 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1354 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
|
1355 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1356 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1357 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
|
1358 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1359 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1360 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1361 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
|
1362 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1363 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1364 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1365 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1366 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1367 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1368 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1369 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1370 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1371 static void GetNumpyInstance(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1372 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1373 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1374 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1375 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1376 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1377 .SetTag("Instances") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1378 .SetSummary("Decode instance for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1379 .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
|
1380 "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
|
1381 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1382 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1383 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1384 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
|
1385 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
|
1386 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
|
1387 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1388 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1389 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1390 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
|
1391 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1392 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
|
1393 if (depth == 0) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1394 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1395 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
|
1396 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1397 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1398 NumpyVisitor visitor(depth, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1399 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1400 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
|
1401 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1402 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1403 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1404 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1405 visitor.Answer(call.GetOutput(), compress); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1406 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1407 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1408 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1409 |
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 static void GetNumpySeries(RestApiGetCall& call) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1412 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1413 if (call.IsDocumentation()) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1414 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1415 DocumentSharedNumpy(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1416 call.GetDocumentation() |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1417 .SetTag("Series") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1418 .SetSummary("Decode series for numpy") |
4836
ec1e9571b645
document number of dimensions in numpy arrays
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4834
diff
changeset
|
1419 .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
|
1420 "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
|
1421 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1422 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1423 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1424 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
|
1425 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
|
1426 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
|
1427 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1428 Semaphore::Locker throttling(throttlingSemaphore_); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1429 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1430 ServerIndex& index = OrthancRestApi::GetIndex(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1431 SliceOrdering ordering(index, seriesId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1432 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1433 unsigned int depth = 0; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1434 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
|
1435 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1436 depth += ordering.GetFramesCount(i); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1437 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1438 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1439 ServerContext& context = OrthancRestApi::GetContext(call); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1440 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1441 NumpyVisitor visitor(depth, rescale); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1442 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1443 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
|
1444 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1445 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
|
1446 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
|
1447 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1448 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1449 ServerContext::DicomCacheLocker locker(context, instanceId); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1450 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1451 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
|
1452 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1453 visitor.WriteFrame(locker.GetDicom(), frame); |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1454 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1455 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
1456 } |
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 visitor.Answer(call.GetOutput(), compress); |
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 } |
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 |
974 | 1463 static void GetMatlabImage(RestApiGetCall& call) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1464 { |
4414 | 1465 if (call.IsDocumentation()) |
1466 { | |
1467 std::string description; | |
1468 | |
1469 if (call.HasUriComponent("frame")) | |
1470 { | |
1471 description = "Decode one frame of interest from the given DICOM instance"; | |
1472 call.GetDocumentation() | |
1473 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); | |
1474 } | |
1475 else | |
1476 { | |
1477 description = "Decode the first frame of the given DICOM instance."; | |
1478 } | |
1479 | |
1480 call.GetDocumentation() | |
1481 .SetTag("Instances") | |
1482 .SetSummary("Decode frame for Matlab") | |
1483 .SetDescription(description + ", and export this frame as a Octave/Matlab matrix to be imported with `eval()`: " | |
1484 "https://book.orthanc-server.com/faq/matlab.html") | |
1485 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
1486 .AddAnswerType(MimeType_PlainText, "Octave/Matlab matrix"); | |
1487 return; | |
1488 } | |
1489 | |
3926
2910b0d30fe0
Allow concurrent calls to the custom image decoders provided by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3816
diff
changeset
|
1490 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
|
1491 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1492 ServerContext& context = OrthancRestApi::GetContext(call); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1493 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1494 std::string frameId = call.GetUriComponent("frame", "0"); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1495 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1496 unsigned int frame; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1497 try |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1498 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1499 frame = boost::lexical_cast<unsigned int>(frameId); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1500 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2804
diff
changeset
|
1501 catch (boost::bad_lexical_cast&) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1502 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1503 return; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1504 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1505 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1506 std::string publicId = call.GetUriComponent("id", ""); |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1507 std::unique_ptr<ImageAccessor> decoded(context.DecodeDicomFrame(publicId, frame)); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1508 |
3928
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1509 if (decoded.get() == NULL) |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1510 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1511 throw OrthancException(ErrorCode_NotImplemented, |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1512 "Cannot decode DICOM instance with ID: " + publicId); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1513 } |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1514 else |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1515 { |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1516 std::string result; |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1517 decoded->ToMatlabString(result); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1518 call.GetOutput().AnswerBuffer(result, MimeType_PlainText); |
4cdc875510d1
ServerContext::DecodeDicomFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3926
diff
changeset
|
1519 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1520 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1521 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
1522 |
2408
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1523 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
|
1524 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
|
1525 { |
4408 | 1526 if (call.IsDocumentation()) |
1527 { | |
1528 call.GetDocumentation() | |
1529 .SetTag("Instances") | |
1530 .SetSummary("Access raw frame" + std::string(GzipCompression ? " (compressed)" : "")) | |
1531 .SetDescription("Access the raw content of one individual frame of the DICOM instance of interest, " | |
1532 "bypassing image decoding. This is notably useful to access the source files " | |
1533 "in compressed transfer syntaxes." + | |
1534 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
|
1535 .SetUriArgument("id", "Orthanc identifier of the instance of interest") |
4408 | 1536 .SetUriArgument("frame", RestApiCallDocumentation::Type_Number, "Index of the frame (starts at `0`)"); |
1537 | |
1538 if (GzipCompression) | |
1539 { | |
1540 call.GetDocumentation().AddAnswerType(MimeType_Gzip, "The raw frame, compressed using gzip"); | |
1541 } | |
1542 else | |
1543 { | |
1544 call.GetDocumentation().AddAnswerType(MimeType_Binary, "The raw frame"); | |
1545 } | |
1546 return; | |
1547 } | |
1548 | |
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
|
1549 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
|
1550 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1551 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
|
1552 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
|
1553 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1554 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
|
1555 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2804
diff
changeset
|
1556 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
|
1557 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1558 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
|
1559 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1560 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1561 std::string publicId = call.GetUriComponent("id", ""); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
1562 std::string raw; |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
1563 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
|
1564 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1565 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1566 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
|
1567 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
|
1568 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1569 |
2408
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1570 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
|
1571 { |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1572 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
|
1573 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
|
1574 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
|
1575 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
|
1576 } |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1577 else |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1578 { |
26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1579 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
|
1580 } |
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
|
1581 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1582 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1906
diff
changeset
|
1583 |
974 | 1584 static void GetResourceStatistics(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1585 { |
4418 | 1586 if (call.IsDocumentation()) |
1587 { | |
1588 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1589 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1590 call.GetDocumentation() | |
1591 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1592 .SetSummary("Get " + r + " statistics") | |
1593 .SetDescription("Get statistics about the given " + r) | |
1594 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1595 .SetAnswerField("DiskSize", RestApiCallDocumentation::Type_String, | |
1596 "Size of the " + r + " on the disk in bytes, expressed as a string for 64bit compatibility with JSON") | |
1597 .SetAnswerField("DiskSizeMB", RestApiCallDocumentation::Type_Number, | |
1598 "Size of the " + r + " on the disk, expressed in megabytes (MB)") | |
1599 .SetAnswerField("UncompressedSize", RestApiCallDocumentation::Type_String, | |
1600 "Size of the " + r + " after decompression in bytes, expressed as a string for 64bit compatibility with JSON") | |
1601 .SetAnswerField("UncompressedSizeMB", RestApiCallDocumentation::Type_Number, | |
1602 "Size of the " + r + " after decompression, expressed in megabytes (MB). " | |
1603 "This is different from `DiskSizeMB` iff `StorageCompression` is `true`.") | |
1604 .SetAnswerField("DicomDiskSize", RestApiCallDocumentation::Type_String, | |
1605 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in bytes") | |
1606 .SetAnswerField("DicomDiskSizeMB", RestApiCallDocumentation::Type_Number, | |
1607 "Size on the disk of the DICOM instances associated with the " + r + ", expressed in megabytes (MB)") | |
1608 .SetAnswerField("DicomUncompressedSize", RestApiCallDocumentation::Type_String, | |
1609 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in bytes") | |
1610 .SetAnswerField("DicomUncompressedSizeMB", RestApiCallDocumentation::Type_Number, | |
1611 "Size on the disk of the uncompressed DICOM instances associated with the " + r + ", expressed in megabytes (MB)") | |
1612 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/statistics", true); | |
1613 | |
1614 switch (t) | |
1615 { | |
1616 // Do NOT add "break" below this point! | |
1617 case ResourceType_Patient: | |
1618 call.GetDocumentation().SetAnswerField("CountStudies", RestApiCallDocumentation::Type_Number, | |
1619 "Number of child studies within this " + r); | |
1620 | |
1621 case ResourceType_Study: | |
1622 call.GetDocumentation().SetAnswerField("CountSeries", RestApiCallDocumentation::Type_Number, | |
1623 "Number of child series within this " + r); | |
1624 | |
1625 case ResourceType_Series: | |
1626 call.GetDocumentation().SetAnswerField("CountInstances", RestApiCallDocumentation::Type_Number, | |
1627 "Number of child instances within this " + r); | |
1628 | |
1629 case ResourceType_Instance: | |
1630 default: | |
1631 break; | |
1632 } | |
1633 | |
1634 return; | |
1635 } | |
1636 | |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1637 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
|
1638 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1639 std::string publicId = call.GetUriComponent("id", ""); |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1640 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1641 ResourceType type; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1642 uint64_t diskSize, uncompressedSize, dicomDiskSize, dicomUncompressedSize; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1643 unsigned int countStudies, countSeries, countInstances; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1644 OrthancRestApi::GetIndex(call).GetResourceStatistics( |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1645 type, diskSize, uncompressedSize, countStudies, countSeries, |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1646 countInstances, dicomDiskSize, dicomUncompressedSize, publicId); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1647 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1648 Json::Value result = Json::objectValue; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1649 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
|
1650 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
|
1651 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
|
1652 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
|
1653 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1654 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
|
1655 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
|
1656 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
|
1657 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
|
1658 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1659 switch (type) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1660 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1661 // Do NOT add "break" below this point! |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1662 case ResourceType_Patient: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1663 result["CountStudies"] = countStudies; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1664 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1665 case ResourceType_Study: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1666 result["CountSeries"] = countSeries; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1667 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1668 case ResourceType_Series: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1669 result["CountInstances"] = countInstances; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1670 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1671 case ResourceType_Instance: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1672 default: |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1673 break; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1674 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3163
diff
changeset
|
1675 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1676 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1677 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1678 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1679 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1680 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1681 // Handling of metadata ----------------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1682 |
4205 | 1683 static void CheckValidResourceType(const RestApiCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1684 { |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1685 assert(!call.GetFullUri().empty()); |
4409 | 1686 const std::string resourceType = call.GetFullUri() [0]; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1687 StringToResourceType(resourceType.c_str()); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1688 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1689 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1690 |
974 | 1691 static void ListMetadata(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1692 { |
4414 | 1693 if (call.IsDocumentation()) |
1694 { | |
1695 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1696 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1697 call.GetDocumentation() | |
1698 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1699 .SetSummary("List metadata") | |
1700 .SetDescription("Get the list of metadata that are associated with the given " + r) | |
1701 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1702 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, | |
1703 "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
|
1704 .SetHttpGetArgument("numeric", RestApiCallDocumentation::Type_String, |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1705 "If present, use the numeric identifier of the metadata instead of its symbolic name", false) |
4414 | 1706 .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, " |
1707 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") | |
1708 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); | |
1709 return; | |
1710 } | |
1711 | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1712 assert(!call.GetFullUri().empty()); |
4554 | 1713 const std::string publicId = call.GetUriComponent("id", ""); |
1714 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1715 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1716 typedef std::map<MetadataType, std::string> Metadata; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1717 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1718 Metadata metadata; |
4554 | 1719 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
|
1720 |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1721 Json::Value result; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1722 |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1723 bool isNumeric = call.HasArgument("numeric"); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1724 |
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
|
1725 if (call.HasArgument("expand") && call.GetBooleanArgument("expand", true)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1726 { |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1727 result = Json::objectValue; |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1728 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1729 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
|
1730 { |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1731 std::string key; |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1732 if (isNumeric) |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1733 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1734 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
|
1735 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1736 else |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1737 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1738 key = EnumerationToString(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1739 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1740 |
3187
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
1741 result[key] = it->second; |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1742 } |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1743 } |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1744 else |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1745 { |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1746 result = Json::arrayValue; |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1747 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1748 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
|
1749 { |
5274
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1750 if (isNumeric) |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1751 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1752 result.append(it->first); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1753 } |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1754 else |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1755 { |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1756 result.append(EnumerationToString(it->first)); |
e5b0bd6b2242
Added option "?numeric" if listing metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5248
diff
changeset
|
1757 } |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2704
diff
changeset
|
1758 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1759 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1760 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1761 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1762 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1763 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1764 |
4657 | 1765 static void SetStringContentETag(const RestApiOutput& output, |
1766 int64_t revision, | |
1767 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
|
1768 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1774 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1775 |
4657 | 1776 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
|
1777 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
|
1778 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
|
1779 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
|
1780 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1781 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
|
1782 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
|
1783 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
|
1784 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
|
1785 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1786 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1787 |
4657 | 1788 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
|
1789 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
|
1790 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
|
1791 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1792 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
|
1793 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
|
1794 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
|
1795 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1796 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1797 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1798 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
|
1799 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1800 std::string md5; |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1801 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
|
1802 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
|
1803 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1804 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1805 |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1806 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
|
1807 std::string& md5 /* out */, |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1808 const RestApiCall& call, |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1809 const std::string& header) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1810 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1811 std::string lower; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1812 Toolbox::ToLowerCase(lower, header); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1813 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1814 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
|
1815 if (found == call.GetHttpHeaders().end()) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1816 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1817 return false; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1818 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1819 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1820 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1821 std::string value = Toolbox::StripSpaces(found->second); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1822 Toolbox::RemoveSurroundingQuotes(value); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1823 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1824 try |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1825 { |
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
|
1826 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
|
1827 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
|
1828 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1829 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
|
1830 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
|
1831 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
|
1832 } |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1833 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1834 catch (boost::bad_lexical_cast&) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1835 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1836 } |
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
|
1837 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1838 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
|
1839 "\" 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
|
1840 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1841 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1842 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1843 |
974 | 1844 static void GetMetadata(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1845 { |
4414 | 1846 if (call.IsDocumentation()) |
1847 { | |
1848 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1849 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1850 call.GetDocumentation() | |
1851 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1852 .SetSummary("Get metadata") | |
1853 .SetDescription("Get the value of a metadata that is associated with the given " + r) | |
1854 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1855 .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
|
1856 .AddAnswerType(MimeType_PlainText, "Value of the metadata") |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1857 .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
|
1858 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed"); |
4414 | 1859 return; |
1860 } | |
1861 | |
4460
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1862 assert(!call.GetFullUri().empty()); |
6831de40acd9
New metadata automatically computed at the series level: "RemoteAET"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1863 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
|
1864 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
|
1865 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1866 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1867 MetadataType metadata = StringToMetadata(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1868 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1869 std::string value; |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1870 int64_t revision; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1871 if (OrthancRestApi::GetIndex(call).LookupMetadata(value, revision, publicId, level, metadata)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1872 { |
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
|
1873 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
|
1874 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1875 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
|
1876 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
|
1877 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
|
1878 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
|
1879 userMD5 == GetMD5(value)) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1880 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1881 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1882 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1883 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1884 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1885 call.GetOutput().AnswerBuffer(value, MimeType_PlainText); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1886 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1887 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1888 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1889 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1890 |
974 | 1891 static void DeleteMetadata(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1892 { |
4414 | 1893 if (call.IsDocumentation()) |
1894 { | |
1895 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1896 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1897 call.GetDocumentation() | |
1898 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1899 .SetSummary("Delete metadata") | |
1900 .SetDescription("Delete some metadata associated with the given DICOM " + r + | |
1901 ". This call will fail if trying to delete a system metadata (i.e. whose index is < 1024).") | |
1902 .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
|
1903 .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
|
1904 .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
|
1905 "be deleted. This header is mandatory if `CheckRevisions` option is `true`."); |
4414 | 1906 return; |
1907 } | |
1908 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1909 CheckValidResourceType(call); |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1910 const std::string publicId = call.GetUriComponent("id", ""); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1911 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1912 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1913 MetadataType metadata = StringToMetadata(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1914 |
1773
613df4362575
New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1759
diff
changeset
|
1915 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1916 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1917 bool found; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1918 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
|
1919 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
|
1920 if (GetRevisionHeader(revision, md5, call, "if-match")) |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1921 { |
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
|
1922 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
|
1923 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1924 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1925 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1926 OrthancConfiguration::ReaderLock lock; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1927 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1928 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1929 throw OrthancException(ErrorCode_Revision, |
4661
b1d87d41874e
typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4657
diff
changeset
|
1930 "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
|
1931 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1932 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1933 { |
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
|
1934 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
|
1935 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1936 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1937 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1938 if (found) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1939 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1940 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1941 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1942 else |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1943 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1944 throw OrthancException(ErrorCode_UnknownResource); |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1945 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1946 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
1947 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
1948 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
1949 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
|
1950 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1951 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1952 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1953 |
974 | 1954 static void SetMetadata(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1955 { |
4414 | 1956 if (call.IsDocumentation()) |
1957 { | |
1958 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1959 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1960 call.GetDocumentation() | |
1961 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1962 .SetSummary("Set metadata") | |
1963 .SetDescription("Set the value of some metadata in the given DICOM " + r + | |
1964 ". This call will fail if trying to modify a system metadata (i.e. whose index is < 1024).") | |
1965 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1966 .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
|
1967 .AddRequestType(MimeType_PlainText, "String value of the metadata") |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1968 .SetHttpHeader("If-Match", "Revision of the metadata, if this is not the first time this metadata is set."); |
4414 | 1969 return; |
1970 } | |
1971 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1972 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1973 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1974 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1975 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1976 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
|
1977 |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
1978 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
|
1979 call.BodyToString(value); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1980 |
1773
613df4362575
New UpdatedAttachment and UpdatedMetadata events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1759
diff
changeset
|
1981 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1982 { |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1983 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
|
1984 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
|
1985 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
|
1986 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1987 if (!hasOldRevision) |
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 OrthancConfiguration::ReaderLock lock; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1990 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1991 { |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1992 // "StatelessDatabaseOperations::SetMetadata()" will ignore |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1993 // 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
|
1994 // inexistent as expected |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1995 hasOldRevision = true; |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1996 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
|
1997 oldMD5.clear(); // dummy value |
4623
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1998 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
1999 } |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2000 |
95ffe3b6ef7c
handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
2001 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
|
2002 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
|
2003 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
|
2004 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2005 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
|
2006 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2007 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2008 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2009 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2010 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
|
2011 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2012 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2013 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2014 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2015 |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2016 // Handling of labels ------------------------------------------------------- |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2017 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2018 static void ListLabels(RestApiGetCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2019 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2020 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2021 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2022 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2023 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
|
2024 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2025 .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
|
2026 .SetSummary("List labels") |
8686476e9d12
fix inclusion of winsock.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5274
diff
changeset
|
2027 .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
|
2028 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2029 .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
|
2030 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/labels", true); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2031 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2032 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2033 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2034 assert(!call.GetFullUri().empty()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2035 const std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2036 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2037 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2038 std::set<std::string> labels; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2039 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2040 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2041 Json::Value result = Json::arrayValue; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2042 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2043 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
|
2044 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2045 result.append(*it); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2046 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2047 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2048 call.GetOutput().AnswerJson(result); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2049 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2050 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2051 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2052 static void GetLabel(RestApiGetCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2053 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2054 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2055 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2056 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2057 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
|
2058 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2059 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2060 .SetSummary("Test label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2061 .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
|
2062 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2063 .SetUriArgument("label", "The label of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2064 .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
|
2065 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2066 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2067 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2068 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2069 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2070 assert(!call.GetFullUri().empty()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2071 const std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2072 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2073 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2074 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2075 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2076 std::set<std::string> labels; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2077 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2078 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2079 if (labels.find(label) != labels.end()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2080 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2081 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2082 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2083 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2084 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2085 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2086 static void AddLabel(RestApiPutCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2087 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2088 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2089 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2090 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2091 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
|
2092 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2093 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2094 .SetSummary("Add label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2095 .SetDescription("Associate a label with a " + r) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2096 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2097 .SetUriArgument("label", "The label to be added"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2098 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2099 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2100 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2101 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2102 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2103 std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2104 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2105 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2106 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2107 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
|
2108 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2109 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2110 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2111 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2112 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2113 static void RemoveLabel(RestApiDeleteCall& call) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2114 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2115 if (call.IsDocumentation()) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2116 { |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2117 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2118 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
|
2119 call.GetDocumentation() |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2120 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2121 .SetSummary("Remove label") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2122 .SetDescription("Remove a label associated with a " + r) |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2123 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2124 .SetUriArgument("label", "The label to be removed"); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2125 return; |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2126 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2127 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2128 CheckValidResourceType(call); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2129 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2130 std::string publicId = call.GetUriComponent("id", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2131 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2132 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2133 std::string label = call.GetUriComponent("label", ""); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2134 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
|
2135 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2136 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2137 } |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
2138 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2139 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2140 // Handling of attached files ----------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2141 |
974 | 2142 static void ListAttachments(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2143 { |
4409 | 2144 if (call.IsDocumentation()) |
2145 { | |
2146 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2147 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2148 call.GetDocumentation() | |
2149 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2150 .SetSummary("List attachments") | |
2151 .SetDescription("Get the list of attachments that are associated with the given " + r) | |
2152 .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
|
2153 .SetHttpGetArgument("full", RestApiCallDocumentation::Type_String, |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2154 "If present, retrieve the attachments list and their numerical ids", false) |
4409 | 2155 .AddAnswerType(MimeType_Json, "JSON array containing the names of the attachments") |
2156 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/attachments", true); | |
2157 return; | |
2158 } | |
2159 | |
2160 const std::string resourceType = call.GetFullUri() [0]; | |
2161 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
|
2162 std::set<FileContentType> attachments; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2163 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str())); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2164 |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2165 Json::Value result; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2166 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2167 if (call.HasArgument("full")) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2168 { |
4853
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2169 result = Json::objectValue; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2170 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2171 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
|
2172 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
|
2173 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2174 std::string key = EnumerationToString(*it); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2175 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
|
2176 } |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2177 } |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2178 else |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2179 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2180 result = Json::arrayValue; |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2181 |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2182 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
|
2183 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
|
2184 { |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2185 result.append(EnumerationToString(*it)); |
b3d0a3a4d890
Added links to download attachments from the Orthanc Explorer
Alain Mazy <am@osimis.io>
parents:
4836
diff
changeset
|
2186 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2187 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2188 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2189 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2190 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2191 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2192 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2193 static void AddAttachmentDocumentation(RestApiGetCall& call, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2194 const std::string& resourceType) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2195 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2196 call.GetDocumentation() |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2197 .SetUriArgument("id", "Orthanc identifier of the " + resourceType + " of interest") |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2198 .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
|
2199 .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
|
2200 .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
|
2201 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2202 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2203 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2204 static bool GetAttachmentInfo(FileInfo& info, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2205 RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2206 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2207 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2208 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2209 const std::string publicId = call.GetUriComponent("id", ""); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2210 const std::string name = call.GetUriComponent("name", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2211 FileContentType contentType = StringToContentType(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2212 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2213 int64_t revision; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2214 if (OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2215 { |
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
|
2216 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
|
2217 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2218 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
|
2219 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
|
2220 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
|
2221 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
|
2222 info.GetUncompressedMD5() == userMD5) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2223 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2224 call.GetOutput().GetLowLevelOutput().SendStatus(HttpStatus_304_NotModified); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2225 return false; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2226 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2227 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2228 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2229 return true; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2230 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2231 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2232 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2233 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2234 throw OrthancException(ErrorCode_UnknownResource); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2235 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2236 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2237 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2238 |
974 | 2239 static void GetAttachmentOperations(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2240 { |
4409 | 2241 if (call.IsDocumentation()) |
2242 { | |
2243 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2244 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
|
2245 AddAttachmentDocumentation(call, r); |
4409 | 2246 call.GetDocumentation() |
2247 .SetTag("Other") | |
4414 | 2248 .SetSummary("List operations on attachments") |
2249 .SetDescription("Get the list of the operations that are available for attachments associated with the given " + r) | |
4409 | 2250 .AddAnswerType(MimeType_Json, "List of the available operations") |
2251 .SetHttpGetSample("https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2/attachments/dicom", true); | |
2252 return; | |
2253 } | |
2254 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2255 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2256 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2257 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2258 Json::Value operations = Json::arrayValue; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2259 |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2260 operations.append("compress"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2261 operations.append("compressed-data"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2262 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2263 if (info.GetCompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2264 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2265 operations.append("compressed-md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2266 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2267 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2268 operations.append("compressed-size"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2269 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
|
2270 operations.append("info"); |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2271 operations.append("is-compressed"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2272 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2273 if (info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2274 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2275 operations.append("md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2276 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2277 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2278 operations.append("size"); |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2279 operations.append("uncompress"); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2280 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2281 if (info.GetCompressedMD5() != "" && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2282 info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2283 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2284 operations.append("verify-md5"); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2285 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2286 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2287 call.GetOutput().AnswerJson(operations); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2288 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2289 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2290 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2291 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2292 template <int uncompress> |
974 | 2293 static void GetAttachmentData(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2294 { |
4409 | 2295 if (call.IsDocumentation()) |
2296 { | |
2297 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2298 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2299 call.GetDocumentation() | |
2300 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2301 .SetSummary("Get attachment" + std::string(uncompress ? "" : " (no decompression)")) | |
2302 .SetDescription("Get the (binary) content of one attachment associated with the given " + r + | |
4418 | 2303 std::string(uncompress ? "" : ". The attachment will not be decompressed if `StorageCompression` is `true`.")) |
4409 | 2304 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
4414 | 2305 .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
|
2306 .AddAnswerType(MimeType_Binary, "The attachment") |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2307 .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
|
2308 .SetHttpHeader("If-None-Match", "Optional revision of the metadata, to check if its content has changed"); |
4409 | 2309 return; |
2310 } | |
2311 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2312 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2313 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2314 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2315 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2316 std::string publicId = call.GetUriComponent("id", ""); |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2317 FileContentType type = StringToContentType(call.GetUriComponent("name", "")); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2318 |
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
|
2319 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
|
2320 if (GetAttachmentInfo(info, call)) |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2321 { |
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
|
2322 // 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
|
2323 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2324 if (uncompress) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2325 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2326 context.AnswerAttachment(call.GetOutput(), publicId, type); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2327 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2328 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2329 { |
4640
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2330 // 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
|
2331 std::string content; |
5427 | 2332 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
|
2333 int64_t revision; |
5427 | 2334 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
|
2335 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2336 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
|
2337 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
|
2338 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
|
2339 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
|
2340 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
|
2341 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2342 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
|
2343 } |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2344 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
|
2345 { |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2346 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
|
2347 } |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2348 } |
1146
200fcac0deb4
optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
2349 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2350 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2351 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2352 |
974 | 2353 static void GetAttachmentSize(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2354 { |
4409 | 2355 if (call.IsDocumentation()) |
2356 { | |
2357 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2358 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
|
2359 AddAttachmentDocumentation(call, r); |
4409 | 2360 call.GetDocumentation() |
2361 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2362 .SetSummary("Get size of attachment") | |
2363 .SetDescription("Get the size of one attachment associated with the given " + r) | |
2364 .AddAnswerType(MimeType_PlainText, "The size of the attachment"); | |
2365 return; | |
2366 } | |
2367 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2368 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2369 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2370 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2371 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
|
2372 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2373 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2374 |
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
|
2375 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
|
2376 { |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2377 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
|
2378 { |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2379 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
|
2380 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
|
2381 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
|
2382 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
|
2383 .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
|
2384 .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
|
2385 .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
|
2386 .AddAnswerType(MimeType_Json, "JSON object containing the information about the attachment") |
5003 | 2387 .SetHttpGetSample("https://demo.orthanc-server.com/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
|
2388 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
|
2389 } |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2390 |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2391 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
|
2392 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
|
2393 { |
504624b0a062
Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
Alain Mazy <am@osimis.io>
parents:
4880
diff
changeset
|
2394 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
|
2395 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
|
2396 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
|
2397 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
|
2398 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
|
2399 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
|
2400 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
|
2401 |
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
|
2402 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
|
2403 } |
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
|
2404 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2405 |
974 | 2406 static void GetAttachmentCompressedSize(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2407 { |
4409 | 2408 if (call.IsDocumentation()) |
2409 { | |
2410 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2411 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
|
2412 AddAttachmentDocumentation(call, r); |
4409 | 2413 call.GetDocumentation() |
2414 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
4410 | 2415 .SetSummary("Get size of attachment on disk") |
4409 | 2416 .SetDescription("Get the size of one attachment associated with the given " + r + ", as stored on the disk. " |
4413 | 2417 "This is different from `.../size` iff `EnableStorage` is `true`.") |
4410 | 2418 .AddAnswerType(MimeType_PlainText, "The size of the attachment, as stored on the disk"); |
4409 | 2419 return; |
2420 } | |
2421 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2422 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2423 if (GetAttachmentInfo(info, call)) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2424 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2425 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
|
2426 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2427 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2428 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2429 |
974 | 2430 static void GetAttachmentMD5(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2431 { |
4410 | 2432 if (call.IsDocumentation()) |
2433 { | |
2434 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2435 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
|
2436 AddAttachmentDocumentation(call, r); |
4410 | 2437 call.GetDocumentation() |
2438 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2439 .SetSummary("Get MD5 of attachment") | |
2440 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r) | |
2441 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment"); | |
2442 return; | |
2443 } | |
2444 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2445 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2446 if (GetAttachmentInfo(info, call) && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2447 info.GetUncompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2448 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2449 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
|
2450 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2451 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2452 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2453 |
974 | 2454 static void GetAttachmentCompressedMD5(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2455 { |
4410 | 2456 if (call.IsDocumentation()) |
2457 { | |
2458 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2459 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
|
2460 AddAttachmentDocumentation(call, r); |
4410 | 2461 call.GetDocumentation() |
2462 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2463 .SetSummary("Get MD5 of attachment on disk") | |
2464 .SetDescription("Get the MD5 hash of one attachment associated with the given " + r + ", as stored on the disk. " | |
4413 | 2465 "This is different from `.../md5` iff `EnableStorage` is `true`.") |
4410 | 2466 .AddAnswerType(MimeType_PlainText, "The MD5 of the attachment, as stored on the disk"); |
2467 return; | |
2468 } | |
2469 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2470 FileInfo info; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2471 if (GetAttachmentInfo(info, call) && |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2472 info.GetCompressedMD5() != "") |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2473 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2474 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
|
2475 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2476 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2477 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2478 |
974 | 2479 static void VerifyAttachment(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2480 { |
4410 | 2481 if (call.IsDocumentation()) |
2482 { | |
2483 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2484 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2485 call.GetDocumentation() | |
2486 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2487 .SetSummary("Verify attachment") | |
2488 .SetDescription("Verify that the attachment is not corrupted, by validating its MD5 hash") | |
2489 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4414 | 2490 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)") |
4410 | 2491 .AddAnswerType(MimeType_Json, "On success, a valid JSON object is returned"); |
2492 return; | |
2493 } | |
2494 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2495 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2496 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2497 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2498 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2499 std::string name = call.GetUriComponent("name", ""); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2500 FileContentType contentType = StringToContentType(name); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2501 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2502 FileInfo info; |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2503 int64_t revision; // Ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2504 if (!OrthancRestApi::GetIndex(call).LookupAttachment(info, revision, publicId, contentType) || |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2505 info.GetCompressedMD5() == "" || |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2506 info.GetUncompressedMD5() == "") |
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 // Inexistent resource, or no MD5 available |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2509 return; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2510 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2511 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2512 bool ok = false; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2513 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2514 // 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
|
2515 std::string data; |
5427 | 2516 std::string attachmentId; |
2517 | |
2518 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
|
2519 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2520 std::string actualMD5; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2521 Toolbox::ComputeMD5(actualMD5, data); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2522 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2523 if (actualMD5 == info.GetCompressedMD5()) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2524 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2525 // The compressed data is OK. If a compression algorithm was |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2526 // applied to it, now check the MD5 of the uncompressed data. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2527 if (info.GetCompressionType() == CompressionType_None) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2528 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2529 ok = true; |
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 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2532 { |
5427 | 2533 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
|
2534 Toolbox::ComputeMD5(actualMD5, data); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2535 ok = (actualMD5 == info.GetUncompressedMD5()); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2536 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2537 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2538 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2539 if (ok) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2540 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
2541 CLOG(INFO, HTTP) << "The attachment " << name << " of resource " << publicId << " has the right MD5"; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2542 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2543 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2544 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2545 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
2546 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
|
2547 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2548 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2549 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2550 |
974 | 2551 static void UploadAttachment(RestApiPutCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2552 { |
4414 | 2553 if (call.IsDocumentation()) |
2554 { | |
2555 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2556 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2557 call.GetDocumentation() | |
2558 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2559 .SetSummary("Set attachment") | |
2560 .SetDescription("Attach a file to the given DICOM " + r + | |
2561 ". This call will fail if trying to modify a system attachment (i.e. whose index is < 1024).") | |
2562 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2563 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)") | |
2564 .AddRequestType(MimeType_Binary, "Binary data containing the attachment") | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2565 .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
|
2566 .SetHttpHeader("If-Match", "Revision of the attachment, if this is not the first time this attachment is set."); |
4414 | 2567 return; |
2568 } | |
2569 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2570 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2571 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2572 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2573 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2574 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2575 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2576 FileContentType contentType = StringToContentType(name); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2577 if (IsUserContentType(contentType)) // It is forbidden to modify internal attachments |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2578 { |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2579 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
|
2580 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
|
2581 bool hasOldRevision = GetRevisionHeader(oldRevision, oldMD5, call, "if-match"); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2582 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2583 if (!hasOldRevision) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2584 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2585 OrthancConfiguration::ReaderLock lock; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2586 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2587 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2588 // "StatelessDatabaseOperations::AddAttachment()" will ignore |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2589 // the actual value of "oldRevision" if the metadata is |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2590 // inexistent as expected |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2591 hasOldRevision = true; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2592 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
|
2593 oldMD5.clear(); // dummy value |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2594 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2595 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2596 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2597 int64_t newRevision; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2598 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
|
2599 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
|
2600 |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
2601 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
|
2602 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2603 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2604 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2605 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2606 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
|
2607 } |
751
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 DeleteAttachment(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2612 { |
4413 | 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 */); | |
2617 call.GetDocumentation() | |
2618 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2619 .SetSummary("Delete attachment") | |
4414 | 2620 .SetDescription("Delete an attachment associated with the given DICOM " + r + |
2621 ". This call will fail if trying to delete a system attachment (i.e. whose index is < 1024).") | |
4413 | 2622 .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
|
2623 .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
|
2624 .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
|
2625 "be deleted. This header is mandatory if `CheckRevisions` option is `true`."); |
4413 | 2626 return; |
2627 } | |
2628 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2629 CheckValidResourceType(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2630 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2631 std::string publicId = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2632 std::string name = call.GetUriComponent("name", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2633 FileContentType contentType = StringToContentType(name); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2634 |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2635 bool allowed; |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2636 if (IsUserContentType(contentType)) |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2637 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2638 allowed = true; |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2639 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2640 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2641 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2642 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2643 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2644 if (lock.GetConfiguration().GetBooleanParameter("StoreDicom", true) && |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2645 contentType == FileContentType_DicomAsJson) |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2646 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2647 allowed = true; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2648 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2649 else |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2650 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2651 // 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
|
2652 // 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
|
2653 // 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
|
2654 allowed = false; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2935
diff
changeset
|
2655 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2656 } |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2657 |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2658 if (allowed) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2659 { |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2660 bool found; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2661 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
|
2662 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
|
2663 if (GetRevisionHeader(revision, md5, call, "if-match")) |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2664 { |
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
|
2665 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
|
2666 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2667 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2668 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2669 OrthancConfiguration::ReaderLock lock; |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2670 if (lock.GetConfiguration().GetBooleanParameter(CHECK_REVISIONS, false)) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2671 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2672 throw OrthancException(ErrorCode_Revision, |
4661
b1d87d41874e
typo: replaced "CheckRevision" by "CheckRevisions"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4657
diff
changeset
|
2673 "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
|
2674 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2675 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2676 { |
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
|
2677 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
|
2678 false, -1 /* dummy value */, "" /* dummy value */); |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2679 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2680 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2681 |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2682 if (found) |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2683 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2684 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2685 } |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2686 else |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2687 { |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2688 throw OrthancException(ErrorCode_UnknownResource); |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4623
diff
changeset
|
2689 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2690 } |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2691 else |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2692 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2127
diff
changeset
|
2693 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
|
2694 } |
751
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 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2697 |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2698 template <enum CompressionType compression> |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2699 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
|
2700 { |
4413 | 2701 if (call.IsDocumentation()) |
2702 { | |
2703 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2704 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2705 call.GetDocumentation() | |
2706 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2707 .SetSummary(compression == CompressionType_None ? "Uncompress attachment" : "Compress attachment") | |
2708 .SetDescription("Change the compression scheme that is used to store an attachment.") | |
2709 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
4414 | 2710 .SetUriArgument("name", "The name of the attachment, or its index (cf. `UserContentType` configuration option)"); |
4413 | 2711 return; |
2712 } | |
2713 | |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2714 CheckValidResourceType(call); |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2715 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2716 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
|
2717 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
|
2718 FileContentType contentType = StringToContentType(name); |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2719 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2720 OrthancRestApi::GetContext(call).ChangeAttachmentCompression(publicId, contentType, compression); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2721 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
|
2722 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2723 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2724 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2725 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
|
2726 { |
4413 | 2727 if (call.IsDocumentation()) |
2728 { | |
2729 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2730 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
|
2731 AddAttachmentDocumentation(call, r); |
4413 | 2732 call.GetDocumentation() |
2733 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2734 .SetSummary("Is attachment compressed?") | |
2735 .SetDescription("Test whether the attachment has been stored as a compressed file on the disk.") | |
2736 .AddAnswerType(MimeType_PlainText, "`0` if the attachment was stored uncompressed, `1` if it was compressed"); | |
2737 return; | |
2738 } | |
2739 | |
1700
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2740 FileInfo info; |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2741 if (GetAttachmentInfo(info, call)) |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2742 { |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2743 std::string answer = (info.GetCompressionType() == CompressionType_None) ? "0" : "1"; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
2744 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
|
2745 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2746 } |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2747 |
f5ddbd9239dd
New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1556
diff
changeset
|
2748 |
782 | 2749 // Raw access to the DICOM tags of an instance ------------------------------ |
2750 | |
974 | 2751 static void GetRawContent(RestApiGetCall& call) |
782 | 2752 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2753 if (call.IsDocumentation()) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2754 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2755 call.GetDocumentation() |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2756 .SetTag("Instances") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2757 .SetSummary("Get raw tag") |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2758 .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
|
2759 .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
|
2760 .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
|
2761 "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
|
2762 .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
|
2763 "(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
|
2764 "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
|
2765 return; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2766 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4404
diff
changeset
|
2767 |
782 | 2768 std::string id = call.GetUriComponent("id", ""); |
2769 | |
2770 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); | |
2771 | |
2772 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); | |
2773 } | |
2774 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2775 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2776 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2777 static bool ExtractSharedTags(Json::Value& shared, |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2778 ServerContext& context, |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2779 const std::string& publicId) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2780 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2781 // 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
|
2782 typedef std::list<std::string> Instances; |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2783 Instances instances; |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2784 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2785 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2786 // Loop over the instances |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2787 bool isFirst = true; |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2788 shared = Json::objectValue; |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2789 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2790 for (Instances::const_iterator it = instances.begin(); |
1303 | 2791 it != instances.end(); ++it) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2792 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2793 // 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
|
2794 Json::Value tags; |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2795 |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2796 try |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2797 { |
2124 | 2798 context.ReadDicomAsJson(tags, *it); |
959
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2799 } |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2800 catch (OrthancException&) |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2801 { |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2802 // Race condition: This instance has been removed since |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2803 // (*). Ignore this instance. |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2804 continue; |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2805 } |
bd5659f2a50a
fix possible race condition
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
958
diff
changeset
|
2806 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2807 if (tags.type() != Json::objectValue) |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2808 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2809 return false; // Error |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2810 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2811 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2812 // 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
|
2813 Json::Value::Members members = tags.getMemberNames(); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2814 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
|
2815 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2816 const Json::Value& tag = tags[members[i]]; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2817 if (tag.type() != Json::objectValue || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2818 tag["Type"].type() != Json::stringValue || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2819 tag["Type"].asString() != "String") |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2820 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2821 tags.removeMember(members[i]); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2822 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2823 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2824 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2825 if (isFirst) |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2826 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2827 // 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
|
2828 shared = tags; |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2829 isFirst = false; |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2830 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2831 else |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2832 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2833 // 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
|
2834 // 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
|
2835 // value in the current instance, remove it. |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2836 members = shared.getMemberNames(); |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2837 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
|
2838 { |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2839 if (!tags.isMember(members[i]) || |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2840 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
|
2841 { |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2842 shared.removeMember(members[i]); |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2843 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2844 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2845 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2846 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2847 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2848 return true; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2849 } |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2850 |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2851 |
974 | 2852 static void GetSharedTags(RestApiGetCall& call) |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2853 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2854 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2855 { |
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
|
2856 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
|
2857 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2858 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
|
2859 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
|
2860 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2861 .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
|
2862 .SetSummary("Get shared tags") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2863 .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
|
2864 "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
|
2865 .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
|
2866 .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
|
2867 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/shared-tags", 5); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2868 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2869 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
2870 |
960
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2871 ServerContext& context = OrthancRestApi::GetContext(call); |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2872 std::string publicId = call.GetUriComponent("id", ""); |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2873 |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2874 Json::Value sharedTags; |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2875 if (ExtractSharedTags(sharedTags, context, publicId)) |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2876 { |
abac5c83134f
simplified and extensive shared-tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
959
diff
changeset
|
2877 // 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
|
2878 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
|
2879 } |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2880 } |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2881 |
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
2882 |
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
|
2883 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
|
2884 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
|
2885 static void GetModule(RestApiGetCall& call) |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2886 { |
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
|
2887 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
|
2888 { |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2889 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
|
2890 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
|
2891 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
|
2892 { |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2893 case DicomModule_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
|
2894 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
|
2895 break; |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2896 case DicomModule_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
|
2897 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
|
2898 break; |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2899 case DicomModule_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
|
2900 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
|
2901 break; |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2902 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
|
2903 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
|
2904 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
|
2905 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
|
2906 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
|
2907 } |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2908 |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2909 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
|
2910 |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2911 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
|
2912 .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
|
2913 .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
|
2914 .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
|
2915 .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
|
2916 .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
|
2917 "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
|
2918 .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
|
2919 .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
|
2920 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
|
2921 } |
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4694
diff
changeset
|
2922 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2923 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2924 (resourceType == ResourceType_Study && module == DicomModule_Patient) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2925 (resourceType == ResourceType_Study && module == DicomModule_Study) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2926 (resourceType == ResourceType_Series && module == DicomModule_Series) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2927 (resourceType == ResourceType_Instance && module == DicomModule_Instance) || |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2928 (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
|
2929 { |
1701dcb6f554
Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
2930 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
|
2931 } |
1701dcb6f554
Access patient module at the study level to cope with PatientID collisions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
2932 |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2933 ServerContext& context = OrthancRestApi::GetContext(call); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2934 std::string publicId = call.GetUriComponent("id", ""); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2935 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
2936 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
|
2937 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
2938 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2939 typedef std::set<DicomTag> ModuleTags; |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2940 ModuleTags moduleTags; |
1368 | 2941 DicomTag::AddTagsForModule(moduleTags, module); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2942 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2943 Json::Value tags; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2944 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2945 if (resourceType != ResourceType_Instance) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2946 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2947 // Retrieve all the instances of this patient/study/series |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2948 typedef std::list<std::string> Instances; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2949 Instances instances; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2950 context.GetIndex().GetChildInstances(instances, publicId); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2951 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2952 if (instances.empty()) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2953 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2954 return; // Error: No instance (should never happen) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2955 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2956 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2957 // Select one child instance |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2958 publicId = instances.front(); |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2959 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2960 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
2961 context.ReadDicomAsJson(tags, publicId, ignoreTagLength); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2962 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2963 // 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
|
2964 Json::Value result = Json::objectValue; |
1303 | 2965 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
|
2966 { |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
2967 std::string s = tag->Format(); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2968 if (tags.isMember(s)) |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2969 { |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2970 result[s] = tags[s]; |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2971 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2972 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2973 |
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
|
2974 AnswerDicomAsJson(call, result, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full)); |
963
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2975 } |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2976 |
81134ea872ff
retrieve values of modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
960
diff
changeset
|
2977 |
1722 | 2978 namespace |
2979 { | |
2980 typedef std::list< std::pair<ResourceType, std::string> > LookupResults; | |
2981 } | |
2982 | |
2983 | |
2984 static void AccumulateLookupResults(LookupResults& result, | |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2985 ServerIndex& index, |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2986 const DicomTag& tag, |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
2987 const std::string& value, |
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
2988 ResourceType level) |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2989 { |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
2990 std::vector<std::string> tmp; |
1728
4941494b5dd8
rename LookupIdentifier as LookupIdentifierExact
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1727
diff
changeset
|
2991 index.LookupIdentifierExact(tmp, level, tag, value); |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
2992 |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
2993 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
|
2994 { |
3034
54e422fe31ce
moving LookupResource to graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
2995 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
|
2996 } |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2997 } |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2998 |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
2999 |
1139
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3000 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
|
3001 { |
4422 | 3002 if (call.IsDocumentation()) |
3003 { | |
3004 call.GetDocumentation() | |
3005 .SetTag("System") | |
3006 .SetSummary("Look for DICOM identifiers") | |
3007 .SetDescription("This URI can be used to convert one DICOM identifier to a list of matching Orthanc resources") | |
3008 .AddRequestType(MimeType_PlainText, "The DICOM identifier of interest (i.e. the value of `PatientID`, " | |
3009 "`StudyInstanceUID`, `SeriesInstanceUID`, or `SOPInstanceUID`)") | |
3010 .AddAnswerType(MimeType_Json, "JSON array containing a list of matching Orthanc resources, each item in the " | |
3011 "list corresponding to a JSON object with the fields `Type`, `ID` and `Path` identifying one " | |
3012 "DICOM resource that is stored by Orthanc"); | |
3013 return; | |
3014 } | |
3015 | |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
3016 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
|
3017 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
|
3018 |
1722 | 3019 LookupResults resources; |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3020 ServerIndex& index = OrthancRestApi::GetIndex(call); |
1719
3b1f7e706d38
fix Orthanc.test_lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1718
diff
changeset
|
3021 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
|
3022 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
|
3023 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
|
3024 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
|
3025 |
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3026 Json::Value result = Json::arrayValue; |
1722 | 3027 for (LookupResults::const_iterator |
1718
2b812969e136
getting rid of an IDatabaseWrapper::LookupIdentifier flavor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1703
diff
changeset
|
3028 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
|
3029 { |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3030 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
|
3031 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
|
3032 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3033 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
|
3034 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
|
3035 item["ID"] = id; |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3036 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
|
3037 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3038 result.append(item); |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3039 } |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3040 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3041 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
|
3042 } |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3043 |
f167b672db94
/tools/lookup URI to map DICOM UIDs to Orthanc identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
3044 |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3045 namespace |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3046 { |
3021
2cbafb5d5a62
renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3012
diff
changeset
|
3047 class FindVisitor : public ServerContext::ILookupVisitor |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3048 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3049 private: |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3050 bool isComplete_; |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3051 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
|
3052 FindStorageAccessMode findStorageAccessMode_; |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3053 |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3054 // 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
|
3055 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
|
3056 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
|
3057 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
|
3058 |
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
|
3059 DicomToJsonFormat format_; |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3060 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3061 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
|
3062 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
|
3063 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
|
3064 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
|
3065 format_(format) |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3066 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3067 } |
4205 | 3068 |
3069 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
|
3070 { |
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
|
3071 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
|
3072 } |
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
|
3073 |
4205 | 3074 virtual void MarkAsComplete() ORTHANC_OVERRIDE |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3075 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3076 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
|
3077 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3078 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3079 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
|
3080 const std::string& instanceId, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3081 const DicomMap& mainDicomTags, |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3082 const Json::Value* dicomAsJson) ORTHANC_OVERRIDE |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3083 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3084 resources_.push_back(publicId); |
4937
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3085 instancesIds_[publicId] = instanceId; |
3f9b9865c8cc
include requested tags from storage if needed
Alain Mazy <am@osimis.io>
parents:
4936
diff
changeset
|
3086 resourcesMainDicomTags_[publicId].reset(mainDicomTags.Clone()); |
5060
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3087 if (dicomAsJson != NULL) |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3088 { |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3089 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
|
3090 } |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3091 else |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3092 { |
e69a3ff39bc5
fix reuse of DicomAsJson between lookup and answers
Alain Mazy <am@osimis.io>
parents:
5058
diff
changeset
|
3093 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
|
3094 } |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3095 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3096 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3097 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
|
3098 ServerContext& context, |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3099 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
|
3100 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
|
3101 const std::set<DicomTag>& requestedTags) const |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3102 { |
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
|
3103 AnswerListOfResources(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
|
3104 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3105 }; |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3106 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3107 |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3108 |
1354 | 3109 static void Find(RestApiPostCall& call) |
3110 { | |
2998 | 3111 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive"; |
3112 static const char* const KEY_EXPAND = "Expand"; | |
3113 static const char* const KEY_LEVEL = "Level"; | |
3114 static const char* const KEY_LIMIT = "Limit"; | |
3115 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
|
3116 static const char* const KEY_REQUESTED_TAGS = "RequestedTags"; |
2998 | 3117 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
|
3118 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
|
3119 static const char* const KEY_LABELS_CONSTRAINT = "LabelsConstraint"; // New in Orthanc 1.12.0 |
2998 | 3120 |
4421 | 3121 if (call.IsDocumentation()) |
3122 { | |
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
|
3123 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
|
3124 |
4421 | 3125 call.GetDocumentation() |
3126 .SetTag("System") | |
3127 .SetSummary("Look for local resources") | |
3128 .SetDescription("This URI can be used to perform a search on the content of the local Orthanc server, " | |
3129 "in a way that is similar to querying remote DICOM modalities using C-FIND SCU: " | |
3130 "https://book.orthanc-server.com/users/rest.html#performing-finds-within-orthanc") | |
3131 .SetRequestField(KEY_CASE_SENSITIVE, RestApiCallDocumentation::Type_Boolean, | |
3132 "Enable case-sensitive search for PN value representations (defaults to configuration option `CaseSensitivePN`)", false) | |
3133 .SetRequestField(KEY_EXPAND, RestApiCallDocumentation::Type_Boolean, | |
3134 "Also retrieve the content of the matching resources, not only their Orthanc identifiers", false) | |
3135 .SetRequestField(KEY_LEVEL, RestApiCallDocumentation::Type_String, | |
3136 "Level of the query (`Patient`, `Study`, `Series` or `Instance`)", true) | |
3137 .SetRequestField(KEY_LIMIT, RestApiCallDocumentation::Type_Number, | |
3138 "Limit the number of reported resources", false) | |
3139 .SetRequestField(KEY_SINCE, RestApiCallDocumentation::Type_Number, | |
3140 "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
|
3141 .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
|
3142 "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
|
3143 "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
|
3144 "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
|
3145 "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
|
3146 "all Main Dicom Tags to keep backward compatibility with Orthanc prior to 1.11.0.", false) |
4421 | 3147 .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject, |
3148 "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
|
3149 .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
|
3150 "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
|
3151 .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
|
3152 "Constraint on the labels, can be `All`, `Any`, or `None` (defaults to `All`, new in Orthanc 1.12.0)", true) |
4421 | 3153 .AddAnswerType(MimeType_Json, "JSON array containing either the Orthanc identifiers, or detailed information " |
3154 "about the reported resources (if `Expand` argument is `true`)"); | |
3155 return; | |
3156 } | |
3157 | |
1358 | 3158 ServerContext& context = OrthancRestApi::GetContext(call); |
1354 | 3159 |
3160 Json::Value request; | |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3161 if (!call.ParseJsonRequest(request) || |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3162 request.type() != Json::objectValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3163 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3164 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3165 "The body must contain a JSON object"); |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3166 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3167 else if (!request.isMember(KEY_LEVEL) || |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3168 request[KEY_LEVEL].type() != Json::stringValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3169 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3170 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3171 "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
|
3172 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3173 else if (!request.isMember(KEY_QUERY) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3174 request[KEY_QUERY].type() != Json::objectValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3175 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3176 throw OrthancException(ErrorCode_BadRequest, |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3177 "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
|
3178 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3179 else if (request.isMember(KEY_CASE_SENSITIVE) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3180 request[KEY_CASE_SENSITIVE].type() != Json::booleanValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3181 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3182 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3183 "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
|
3184 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3185 else if (request.isMember(KEY_LIMIT) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3186 request[KEY_LIMIT].type() != Json::intValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3187 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3188 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3189 "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
|
3190 } |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3191 else if (request.isMember(KEY_SINCE) && |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3192 request[KEY_SINCE].type() != Json::intValue) |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3193 { |
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3194 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3195 "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
|
3196 } |
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
|
3197 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
|
3198 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
|
3199 { |
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
|
3200 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3201 "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
|
3202 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3203 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
|
3204 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
|
3205 { |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3206 throw OrthancException(ErrorCode_BadRequest, |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3207 "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
|
3208 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3209 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
|
3210 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
|
3211 { |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3212 throw OrthancException(ErrorCode_BadRequest, |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3213 "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
|
3214 } |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3215 else |
1354 | 3216 { |
3217 bool expand = false; | |
2998 | 3218 if (request.isMember(KEY_EXPAND)) |
1354 | 3219 { |
2998 | 3220 expand = request[KEY_EXPAND].asBool(); |
1354 | 3221 } |
3222 | |
1374
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3223 bool caseSensitive = false; |
2998 | 3224 if (request.isMember(KEY_CASE_SENSITIVE)) |
1374
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3225 { |
2998 | 3226 caseSensitive = request[KEY_CASE_SENSITIVE].asBool(); |
1374
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3227 } |
a1745d9be6e9
CaseSensitivePN configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1361
diff
changeset
|
3228 |
1758 | 3229 size_t limit = 0; |
2998 | 3230 if (request.isMember(KEY_LIMIT)) |
1758 | 3231 { |
2998 | 3232 int tmp = request[KEY_LIMIT].asInt(); |
1847 | 3233 if (tmp < 0) |
1758 | 3234 { |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3235 throw OrthancException(ErrorCode_ParameterOutOfRange, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3236 "Field \"" + std::string(KEY_LIMIT) + "\" must be a positive integer"); |
1758 | 3237 } |
1847 | 3238 |
3239 limit = static_cast<size_t>(tmp); | |
1758 | 3240 } |
3241 | |
2304
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3242 size_t since = 0; |
2998 | 3243 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
|
3244 { |
2998 | 3245 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
|
3246 if (tmp < 0) |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3247 { |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3248 throw OrthancException(ErrorCode_ParameterOutOfRange, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3249 "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
|
3250 } |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3251 |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3252 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
|
3253 } |
563bf878407a
Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
3254 |
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
|
3255 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
|
3256 |
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
|
3257 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
|
3258 { |
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 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
|
3260 } |
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
|
3261 |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
3262 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); |
1360 | 3263 |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
3264 DatabaseLookup query; |
1358 | 3265 |
2998 | 3266 Json::Value::Members members = request[KEY_QUERY].getMemberNames(); |
1354 | 3267 for (size_t i = 0; i < members.size(); i++) |
3268 { | |
2998 | 3269 if (request[KEY_QUERY][members[i]].type() != Json::stringValue) |
1354 | 3270 { |
3001
7695a9c81099
refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2998
diff
changeset
|
3271 throw OrthancException(ErrorCode_BadRequest, |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3272 "Tag \"" + members[i] + "\" must be associated with a string"); |
1354 | 3273 } |
3274 | |
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
|
3275 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
|
3276 |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3277 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
|
3278 { |
cf91b6f22278
Fix issue #90 (C-Find shall match missing tags to null/empty string)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
3279 // 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
|
3280 // 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
|
3281 // "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
|
3282 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
|
3283 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
|
3284 } |
1361
94ffb597d297
refactoring of C-Find SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1360
diff
changeset
|
3285 } |
2876 | 3286 |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3287 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
|
3288 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3289 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
|
3290 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3291 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
|
3292 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3293 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
|
3294 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3295 else |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3296 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3297 query.AddLabel(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
|
3298 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3299 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3300 } |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3301 |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3302 query.SetLabelsConstraint(LabelsConstraint_All); |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3303 |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3304 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
|
3305 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3306 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
|
3307 if (s == "All") |
5227
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3308 { |
5248
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3309 query.SetLabelsConstraint(LabelsConstraint_All); |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3310 } |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3311 else if (s == "Any") |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3312 { |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3313 query.SetLabelsConstraint(LabelsConstraint_Any); |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3314 } |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3315 else if (s == "None") |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3316 { |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3317 query.SetLabelsConstraint(LabelsConstraint_None); |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3318 } |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3319 else |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3320 { |
a7d95f951f8a
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5227
diff
changeset
|
3321 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
|
3322 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3323 } |
988dab8deb1c
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5221
diff
changeset
|
3324 |
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
|
3325 FindVisitor visitor(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human), context.GetFindStorageAccessMode()); |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
3326 context.Apply(visitor, query, level, 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
|
3327 visitor.Answer(call.GetOutput(), context, level, expand, requestedTags); |
1354 | 3328 } |
3329 } | |
3330 | |
3331 | |
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
|
3332 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
|
3333 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
|
3334 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
|
3335 { |
4415 | 3336 if (call.IsDocumentation()) |
3337 { | |
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
|
3338 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
|
3339 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
|
3340 |
4415 | 3341 const std::string children = GetResourceTypeText(end, true /* plural */, false /* lower case */); |
3342 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */); | |
3343 call.GetDocumentation() | |
3344 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */)) | |
3345 .SetSummary("Get child " + children) | |
3346 .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
|
3347 resource + " whose Orthanc identifier is provided in the URL") |
4415 | 3348 .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
|
3349 .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
|
3350 "If false or missing, only retrieve the list of child " + children, false) |
4415 | 3351 .AddAnswerType(MimeType_Json, "JSON array containing information about the child DICOM " + children) |
3352 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + children, 5); | |
3353 return; | |
3354 } | |
3355 | |
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
|
3356 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
|
3357 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
|
3358 |
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
|
3359 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
|
3360 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
|
3361 |
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
|
3362 std::list<std::string> a, b, c; |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3363 a.push_back(call.GetUriComponent("id", "")); |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3364 |
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
|
3365 ResourceType type = start; |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3366 while (type != end) |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3367 { |
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
|
3368 b.clear(); |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3369 |
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
|
3370 for (std::list<std::string>::const_iterator |
1303 | 3371 it = a.begin(); it != a.end(); ++it) |
1140
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3372 { |
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
|
3373 index.GetChildren(c, *it); |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3374 b.splice(b.begin(), c); |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3375 } |
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
|
3376 |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
3377 type = GetChildResourceType(type); |
1140
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3378 |
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
|
3379 a.clear(); |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3380 a.splice(a.begin(), b); |
94c5f6623b3a
URIs to get all the children of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1139
diff
changeset
|
3381 } |
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
|
3382 |
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
|
3383 AnswerListOfResources(call.GetOutput(), context, a, type, !call.HasArgument("expand") || call.GetBooleanArgument("expand", false), // this "expand" is the only one to have a false default value to keep backward compatibility |
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
|
3384 OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human), |
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
|
3385 requestedTags, |
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
|
3386 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
|
3387 } |
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
|
3388 |
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
|
3389 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3390 static void GetChildInstancesTags(RestApiGetCall& call) |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3391 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3392 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3393 { |
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
|
3394 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
|
3395 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3396 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
|
3397 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
|
3398 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3399 .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
|
3400 .SetSummary("Get tags of instances") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3401 .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
|
3402 " 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
|
3403 .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
|
3404 .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
|
3405 "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
|
3406 .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
|
3407 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(t) + "/instances-tags", 5); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3408 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3409 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4415
diff
changeset
|
3410 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3411 ServerContext& context = OrthancRestApi::GetContext(call); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3412 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
|
3413 DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full); |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3414 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3415 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
|
3416 ParseSetOfTags(ignoreTagLength, call, IGNORE_LENGTH); |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3417 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3418 // Retrieve all the instances of this patient/study/series |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3419 typedef std::list<std::string> Instances; |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3420 Instances instances; |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3421 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3422 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3423 |
1201
09aa7c126be9
URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1172
diff
changeset
|
3424 Json::Value result = Json::objectValue; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3425 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3426 for (Instances::const_iterator it = instances.begin(); |
1303 | 3427 it != instances.end(); ++it) |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3428 { |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3429 Json::Value full; |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2408
diff
changeset
|
3430 context.ReadDicomAsJson(full, *it, ignoreTagLength); |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3431 |
2622
3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
3432 if (format != DicomToJsonFormat_Full) |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3433 { |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3434 Json::Value simplified; |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
3435 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
|
3436 result[*it] = simplified; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3437 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3438 else |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3439 { |
1201
09aa7c126be9
URIs 'instance-tags' now indexed by the instance IDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1172
diff
changeset
|
3440 result[*it] = full; |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3441 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3442 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3443 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3444 call.GetOutput().AnswerJson(result); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3445 } |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3446 |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
3447 |
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
|
3448 |
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
|
3449 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
|
3450 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
|
3451 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
|
3452 { |
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
|
3453 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
|
3454 |
4415 | 3455 if (call.IsDocumentation()) |
3456 { | |
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
|
3457 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
|
3458 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
|
3459 |
4415 | 3460 const std::string parent = GetResourceTypeText(end, false /* plural */, false /* lower case */); |
3461 const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */); | |
3462 call.GetDocumentation() | |
3463 .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */)) | |
3464 .SetSummary("Get parent " + parent) | |
3465 .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
|
3466 resource + " whose Orthanc identifier is provided in the URL") |
4415 | 3467 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
3468 .AddAnswerType(MimeType_Json, "Information about the parent DICOM " + parent) | |
3469 .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + parent, 10); | |
3470 return; | |
3471 } | |
3472 | |
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
|
3473 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
|
3474 |
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
|
3475 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
|
3476 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
|
3477 |
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
|
3478 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
|
3479 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
|
3480 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
|
3481 { |
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
|
3482 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
|
3483 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
|
3484 { |
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
|
3485 // 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
|
3486 // 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
|
3487 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
|
3488 } |
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
|
3489 |
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
|
3490 current = parent; |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
3491 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
|
3492 } |
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
|
3493 |
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
|
3494 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
|
3495 |
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
|
3496 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
|
3497 |
4554 | 3498 Json::Value 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
|
3499 if (OrthancRestApi::GetContext(call).ExpandResource(resource, current, end, format, requestedTags, true /* allowStorageAccess */)) |
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
|
3500 { |
4554 | 3501 call.GetOutput().AnswerJson(resource); |
1281
8dac11c78d71
URIs to get all the parents of a given resource in a single REST call
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1276
diff
changeset
|
3502 } |
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
|
3503 } |
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
|
3504 |
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
|
3505 |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3506 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
|
3507 { |
4407 | 3508 if (call.IsDocumentation()) |
3509 { | |
3510 call.GetDocumentation() | |
3511 .SetTag("Instances") | |
3512 .SetSummary("Get embedded PDF") | |
3513 .SetDescription("Get the PDF file that is embedded in one DICOM instance. " | |
3514 "If the DICOM instance doesn't contain the `EncapsulatedDocument` tag or if the " | |
3515 "`MIMETypeOfEncapsulatedDocument` tag doesn't correspond to the PDF type, a `404` HTTP error is raised.") | |
3516 .SetUriArgument("id", "Orthanc identifier of the instance interest") | |
3517 .AddAnswerType(MimeType_Pdf, "PDF file"); | |
3518 return; | |
3519 } | |
3520 | |
1556
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3521 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
|
3522 std::string pdf; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3523 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
|
3524 |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3525 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
|
3526 { |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3527 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
|
3528 return; |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3529 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3530 } |
b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
3531 |
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
|
3532 |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3533 static void OrderSlices(RestApiGetCall& call) |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3534 { |
4421 | 3535 if (call.IsDocumentation()) |
3536 { | |
3537 call.GetDocumentation() | |
3538 .SetDeprecated() | |
3539 .SetTag("Series") | |
3540 .SetSummary("Order the slices") | |
3541 .SetDescription("Sort the instances and frames (slices) of the DICOM series whose Orthanc identifier is provided in the URL. " | |
3542 "This URI is essentially used by the Orthanc Web viewer and by the Osimis Web viewer.") | |
3543 .SetUriArgument("id", "Orthanc identifier of the series of interest") | |
3544 .SetAnswerField("Dicom", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3545 "Ordered list of paths to DICOM instances") | |
3546 .SetAnswerField("Slices", RestApiCallDocumentation::Type_JsonListOfStrings, | |
3547 "Ordered list of paths to frames. It is recommended to use this field, as it is also valid " | |
3548 "in the case of multiframe images.") | |
3549 .SetAnswerField("SlicesShort", RestApiCallDocumentation::Type_JsonListOfObjects, | |
3550 "Same information as the `Slices` field, but in a compact form") | |
3551 .SetAnswerField("Type", RestApiCallDocumentation::Type_String, | |
3552 "Can be `Volume` (for 3D volumes) or `Sequence` (notably for cine images)") | |
3553 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/series/1e2c125c-411b8e86-3f4fe68e-a7584dd3-c6da78f0/ordered-slices", 10); | |
3554 return; | |
3555 } | |
3556 | |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3557 const std::string id = call.GetUriComponent("id", ""); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3558 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3559 ServerIndex& index = OrthancRestApi::GetIndex(call); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3560 SliceOrdering ordering(index, id); |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3561 |
1703
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3562 Json::Value result; |
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3563 ordering.Format(result); |
b80e76dd1d56
ordered-slices continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1702
diff
changeset
|
3564 call.GetOutput().AnswerJson(result); |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3565 } |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3566 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
3567 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3568 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
|
3569 { |
4404 | 3570 if (call.IsDocumentation()) |
3571 { | |
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
|
3572 OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Full); |
4404 | 3573 call.GetDocumentation() |
3574 .SetTag("Instances") | |
3575 .SetSummary("Get DICOM meta-header") | |
3576 .SetDescription("Get the DICOM tags in the meta-header of the DICOM instance. By default, the `full` format is used, which " | |
3577 "combines hexadecimal tags with human-readable description.") | |
3578 .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") | |
3579 .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value") | |
3580 .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/header", true); | |
3581 return; | |
3582 } | |
3583 | |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3584 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
|
3585 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3586 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
|
3587 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3588 std::string dicomContent; |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4777
diff
changeset
|
3589 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
|
3590 |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3591 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to |
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3592 // speed up things here |
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2003
diff
changeset
|
3593 |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3594 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
|
3595 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3596 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
|
3597 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
|
3598 |
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
|
3599 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
|
3600 } |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3601 |
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1826
diff
changeset
|
3602 |
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
|
3603 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
|
3604 { |
4420 | 3605 if (call.IsDocumentation()) |
3606 { | |
3607 call.GetDocumentation() | |
3608 .SetTag("System") | |
3609 .SetSummary("Invalidate DICOM-as-JSON summaries") | |
3610 .SetDescription("Remove all the attachments of the type \"DICOM-as-JSON\" that are associated will all the " | |
3611 "DICOM instances stored in Orthanc. These summaries will be automatically re-created on the next access. " | |
3612 "This is notably useful after changes to the `Dictionary` configuration option. " | |
3613 "https://book.orthanc-server.com/faq/orthanc-storage.html#storage-area"); | |
3614 return; | |
3615 } | |
3616 | |
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
|
3617 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
|
3618 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3619 // 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
|
3620 // 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
|
3621 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
|
3622 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
|
3623 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3624 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
|
3625 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
|
3626 { |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3627 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
|
3628 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
|
3629 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3630 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
|
3631 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
|
3632 { |
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
|
3633 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
|
3634 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
|
3635 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3636 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3637 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3638 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
|
3639 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2128
diff
changeset
|
3640 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3641 void DocumentReconstructFilesField(RestApiPostCall& call) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3642 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3643 call.GetDocumentation() |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3644 .SetRequestField(RECONSTRUCT_FILES, RestApiCallDocumentation::Type_Boolean, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3645 "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
|
3646 "'false' by default. (New in Orthanc 1.11.0)", false); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3647 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3648 |
4994 | 3649 bool GetReconstructFilesField(const RestApiPostCall& call) |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3650 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3651 bool reconstructFiles = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3652 Json::Value request; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3653 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3654 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
|
3655 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3656 if (!request[RECONSTRUCT_FILES].isBool()) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3657 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3658 throw OrthancException(ErrorCode_BadFileFormat, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3659 "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
|
3660 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3661 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3662 reconstructFiles = request[RECONSTRUCT_FILES].asBool(); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3663 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3664 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3665 return reconstructFiles; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3666 } |
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
|
3667 |
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
|
3668 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
|
3669 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
|
3670 { |
4420 | 3671 if (call.IsDocumentation()) |
3672 { | |
3673 const std::string resource = GetResourceTypeText(type, false /* plural */, false /* lower case */); | |
3674 call.GetDocumentation() | |
3675 .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
|
3676 .SetSummary("Reconstruct tags & optionally files of " + resource) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3677 .SetDescription("Reconstruct the main DICOM tags in DB of the " + resource + " whose Orthanc identifier is provided " |
4420 | 3678 "in the URL. This is useful if child studies/series/instances have inconsistent values for " |
3679 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. " | |
3680 "Beware that this is a time-consuming operation, as all the children DICOM instances will be " | |
3681 "parsed again, and the Orthanc index will be updated accordingly.") | |
3682 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3683 DocumentReconstructFilesField(call); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3684 |
4420 | 3685 return; |
3686 } | |
3687 | |
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
|
3688 ServerContext& context = OrthancRestApi::GetContext(call); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3689 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""), GetReconstructFilesField(call)); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3690 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
|
3691 } |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
3692 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
3693 |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3694 static void ReconstructAllResources(RestApiPostCall& call) |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3695 { |
4420 | 3696 if (call.IsDocumentation()) |
3697 { | |
3698 call.GetDocumentation() | |
3699 .SetTag("System") | |
3700 .SetSummary("Reconstruct all the index") | |
3701 .SetDescription("Reconstruct the index of all the tags of all the DICOM instances that are stored in Orthanc. " | |
3702 "This is notably useful after the deletion of resources whose children resources have inconsistent " | |
3703 "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
|
3704 "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
|
3705 "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
|
3706 "this action resource by resource"); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3707 DocumentReconstructFilesField(call); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3708 |
4420 | 3709 return; |
3710 } | |
3711 | |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3712 ServerContext& context = OrthancRestApi::GetContext(call); |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3713 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3714 std::list<std::string> studies; |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3715 context.GetIndex().GetAllUuids(studies, ResourceType_Study); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3716 bool reconstructFiles = GetReconstructFilesField(call); |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3717 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3718 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
|
3719 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
|
3720 { |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4977
diff
changeset
|
3721 ServerToolbox::ReconstructResource(context, *study, reconstructFiles); |
2804
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3722 } |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3723 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
3724 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
|
3725 } |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3726 |
d88970f1ffbf
fix ordering of non-parallel slices + /tools/reconstruct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2780
diff
changeset
|
3727 |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3728 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
|
3729 ServerIndex& index, |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3730 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
|
3731 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3732 target.clear(); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3733 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3734 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
|
3735 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
|
3736 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3737 std::list<std::string> children; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3738 index.GetChildren(children, *it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3739 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3740 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
|
3741 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
|
3742 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3743 target.insert(*child); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3744 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3745 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3746 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3747 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3748 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3749 static void AddMetadata(Json::Value& target, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3750 ServerIndex& index, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3751 const std::string& resource, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3752 ResourceType level) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3753 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3754 target = Json::objectValue; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3755 |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3756 std::map<MetadataType, std::string> content; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3757 index.GetAllMetadata(content, resource, level); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3758 |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3759 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
|
3760 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
|
3761 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3762 target[EnumerationToString(it->first)] = it->second; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3763 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3764 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3765 |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3766 |
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
|
3767 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
|
3768 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3769 static const char* const LEVEL = "Level"; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3770 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
|
3771 |
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
|
3772 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
|
3773 { |
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
|
3774 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
|
3775 |
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
|
3776 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
|
3777 .SetTag("System") |
4879 | 3778 .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
|
3779 .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
|
3780 "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
|
3781 .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
|
3782 "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
|
3783 "`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
|
3784 "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
|
3785 .SetRequestField(METADATA, RestApiCallDocumentation::Type_Boolean, |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3786 "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
|
3787 .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
|
3788 "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
|
3789 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
|
3790 } |
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
|
3791 |
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
|
3792 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
|
3793 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
|
3794 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
|
3795 { |
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
|
3796 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
|
3797 "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
|
3798 } |
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
|
3799 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
|
3800 { |
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
|
3801 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
|
3802 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3803 bool metadata = true; |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3804 if (request.isMember(METADATA)) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3805 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3806 metadata = SerializationToolbox::ReadBoolean(request, METADATA); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3807 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3808 |
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
|
3809 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
|
3810 |
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
|
3811 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
|
3812 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3813 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
|
3814 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3815 // 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
|
3816 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
|
3817 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3818 std::set<std::string> resources; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3819 SerializationToolbox::ReadSetOfStrings(resources, request, "Resources"); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3820 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3821 std::set<std::string> interest; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3822 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3823 assert(ResourceType_Patient < ResourceType_Study && |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3824 ResourceType_Study < ResourceType_Series && |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3825 ResourceType_Series < ResourceType_Instance); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3826 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3827 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
|
3828 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
|
3829 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3830 ResourceType type; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3831 if (index.LookupResourceType(type, *it)) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3832 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3833 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3834 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3835 // 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
|
3836 interest.insert(*it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3837 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3838 else if (type < level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3839 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3840 // Need to explore children |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3841 std::set<std::string> current; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3842 current.insert(*it); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3843 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3844 for (;;) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3845 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3846 std::set<std::string> children; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3847 GetBulkChildren(children, index, current); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3848 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3849 type = GetChildResourceType(type); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3850 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3851 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3852 for (std::set<std::string>::const_iterator |
4716 | 3853 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
|
3854 { |
4716 | 3855 interest.insert(*it2); |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3856 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3857 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3858 break; // done |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3859 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3860 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3861 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3862 current.swap(children); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3863 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3864 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3865 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3866 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3867 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3868 // Need to explore parents |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3869 std::string current = *it; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3870 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3871 for (;;) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3872 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3873 std::string parent; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3874 if (index.LookupParent(parent, current)) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3875 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3876 type = GetParentResourceType(type); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3877 if (type == level) |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3878 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3879 interest.insert(parent); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3880 break; // done |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3881 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3882 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3883 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3884 current = parent; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3885 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3886 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3887 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3888 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3889 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
|
3890 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3891 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3892 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3893 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3894 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3895 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3896 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
|
3897 } |
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
|
3898 } |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3899 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3900 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
|
3901 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
|
3902 { |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3903 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
|
3904 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
|
3905 |
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
|
3906 if (OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3907 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3908 if (metadata) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3909 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3910 AddMetadata(item[METADATA], index, *it, level); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3911 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3912 |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3913 answer.append(item); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3914 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3915 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3916 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3917 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3918 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3919 // 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
|
3920 std::list<std::string> resources; |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3921 SerializationToolbox::ReadListOfStrings(resources, request, "Resources"); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3922 |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3923 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
|
3924 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
|
3925 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3926 ResourceType level; |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3927 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
|
3928 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
|
3929 |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3930 if (index.LookupResourceType(level, *it) && |
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
|
3931 OrthancRestApi::GetContext(call).ExpandResource(item, *it, level, format, emptyRequestedTags, true /* allowStorageAccess */)) |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3932 { |
4714
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3933 if (metadata) |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3934 { |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3935 AddMetadata(item[METADATA], index, *it, level); |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3936 } |
8ffe2fdb541f
added argument "Metadata" to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4699
diff
changeset
|
3937 |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3938 answer.append(item); |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3939 } |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3940 else |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3941 { |
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3942 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
|
3943 } |
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
|
3944 } |
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
|
3945 } |
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
|
3946 |
d16c3c7f11ef
new route "/tools/bulk-content" to get the content of a set of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4697
diff
changeset
|
3947 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
|
3948 } |
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
|
3949 } |
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
|
3950 |
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
|
3951 |
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
|
3952 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
|
3953 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3954 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
|
3955 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3956 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
|
3957 .SetTag("System") |
4879 | 3958 .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
|
3959 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, |
4699
facea16b055b
added the "Level" argument to "/tools/bulk-content"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4698
diff
changeset
|
3960 "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true) |
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
|
3961 .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
|
3962 "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
|
3963 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
|
3964 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3965 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3966 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
|
3967 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3968 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
|
3969 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
|
3970 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
|
3971 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3972 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
|
3973 "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
|
3974 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3975 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
|
3976 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3977 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
|
3978 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
|
3979 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3980 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
|
3981 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
|
3982 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3983 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
|
3984 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
|
3985 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3986 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
|
3987 !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
|
3988 { |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3989 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
|
3990 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3991 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3992 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3993 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
|
3994 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3995 } |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3996 |
da1edb7d6332
"/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4661
diff
changeset
|
3997 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3998 void OrthancRestApi::RegisterResources() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3999 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4000 Register("/instances", ListResources<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4001 Register("/patients", ListResources<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4002 Register("/series", ListResources<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4003 Register("/studies", ListResources<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4004 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4005 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4006 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4007 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4008 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4009 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4010 Register("/series/{id}", GetSingleResource<ResourceType_Series>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4011 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4012 Register("/studies/{id}", GetSingleResource<ResourceType_Study>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4013 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4014 Register("/instances/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4015 Register("/patients/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4016 Register("/studies/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4017 Register("/series/{id}/statistics", GetResourceStatistics); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4018 |
964
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4019 Register("/patients/{id}/shared-tags", GetSharedTags); |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4020 Register("/series/{id}/shared-tags", GetSharedTags); |
cc7a4ae474c1
simplify has a GET argument
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
963
diff
changeset
|
4021 Register("/studies/{id}/shared-tags", GetSharedTags); |
958
1fbe89dc18b5
extraction of the shared tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
4022 |
1276
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4023 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4024 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4025 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4026 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>); |
6164f7200c43
refactoring modules
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1201
diff
changeset
|
4027 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
|
4028 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4029 Register("/instances/{id}/file", GetInstanceFile); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4030 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
|
4031 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
|
4032 Register("/instances/{id}/simplified-tags", GetInstanceSimplifiedTags); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4033 Register("/instances/{id}/frames", ListFrames); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4034 |
4424
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4422
diff
changeset
|
4035 Register("/instances/{id}/frames/{frame}", RestApi::AutoListChildren); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4036 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
|
4037 Register("/instances/{id}/frames/{frame}/rendered", GetRenderedFrame); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4038 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4039 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4040 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
|
4041 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
|
4042 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
|
4043 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
|
4044 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
|
4045 Register("/instances/{id}/pdf", ExtractPdf); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4046 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
|
4047 Register("/instances/{id}/rendered", GetRenderedFrame); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4048 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4049 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4050 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
4051 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
|
4052 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
|
4053 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
|
4054 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4055 Register("/patients/{id}/protected", IsProtectedPatient); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4056 Register("/patients/{id}/protected", SetPatientProtection); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4057 |
4409 | 4058 std::vector<std::string> resourceTypes; |
4059 resourceTypes.push_back("patients"); | |
4060 resourceTypes.push_back("studies"); | |
4061 resourceTypes.push_back("series"); | |
4062 resourceTypes.push_back("instances"); | |
4063 | |
4064 for (size_t i = 0; i < resourceTypes.size(); i++) | |
4065 { | |
4066 Register("/" + resourceTypes[i] + "/{id}/metadata", ListMetadata); | |
4067 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", DeleteMetadata); | |
4068 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", GetMetadata); | |
4069 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", SetMetadata); | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4070 |
5221
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4071 // New in Orthanc 1.12.0 |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4072 Register("/" + resourceTypes[i] + "/{id}/labels", ListLabels); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4073 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", GetLabel); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4074 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", RemoveLabel); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4075 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", AddLabel); |
d0f7c742d397
started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5200
diff
changeset
|
4076 |
4409 | 4077 Register("/" + resourceTypes[i] + "/{id}/attachments", ListAttachments); |
4078 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", DeleteAttachment); | |
4079 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", GetAttachmentOperations); | |
4080 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", UploadAttachment); | |
4081 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>); | |
4082 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-data", GetAttachmentData<0>); | |
4083 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-md5", GetAttachmentCompressedMD5); | |
4084 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compressed-size", GetAttachmentCompressedSize); | |
4085 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/data", GetAttachmentData<1>); | |
4086 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/is-compressed", IsAttachmentCompressed); | |
4087 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5); | |
4088 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize); | |
4089 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
|
4090 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/info", GetAttachmentInfo); |
4409 | 4091 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment); |
4092 } | |
782 | 4093 |
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
|
4094 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
|
4095 Register("/tools/lookup", Lookup); |
1354 | 4096 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
|
4097 |
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
|
4098 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
|
4099 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
|
4100 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
|
4101 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
|
4102 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
|
4103 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
|
4104 |
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
|
4105 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
|
4106 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
|
4107 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
|
4108 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
|
4109 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
|
4110 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
|
4111 |
1166
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4112 Register("/patients/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4113 Register("/studies/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4114 Register("/series/{id}/instances-tags", GetChildInstancesTags); |
a921e3b5e763
bulk tags retrieval
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1146
diff
changeset
|
4115 |
782 | 4116 Register("/instances/{id}/content/*", GetRawContent); |
1702
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
4117 |
9980875edc7c
started work on SliceOrdering
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1701
diff
changeset
|
4118 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
|
4119 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
|
4120 |
e3fd5bc429a2
URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
4121 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
|
4122 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
|
4123 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
|
4124 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
|
4125 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
|
4126 |
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
|
4127 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
|
4128 Register("/tools/bulk-delete", BulkDelete); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4129 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4130 } |