Mercurial > hg > orthanc-stl
comparison Resources/Orthanc/Sdk-1.2.0/orthanc/OrthancCPlugin.h @ 49:0a408a81fb15 nexus
upgraded Orthanc SDK to 1.2.0
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 17 May 2024 14:05:28 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
48:a70fc4846be1 | 49:0a408a81fb15 |
---|---|
1 /** | |
2 * \mainpage | |
3 * | |
4 * This C/C++ SDK allows external developers to create plugins that | |
5 * can be loaded into Orthanc to extend its functionality. Each | |
6 * Orthanc plugin must expose 4 public functions with the following | |
7 * signatures: | |
8 * | |
9 * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>: | |
10 * This function is invoked by Orthanc when it loads the plugin on startup. | |
11 * The plugin must: | |
12 * - Check its compatibility with the Orthanc version using | |
13 * ::OrthancPluginCheckVersion(). | |
14 * - Store the context pointer so that it can use the plugin | |
15 * services of Orthanc. | |
16 * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback(). | |
17 * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback(). | |
18 * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback(). | |
19 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea(). | |
20 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2(). | |
21 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback(). | |
22 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback(). | |
23 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback(). | |
24 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback(). | |
25 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter(). | |
26 * -# <tt>void OrthancPluginFinalize()</tt>: | |
27 * This function is invoked by Orthanc during its shutdown. The plugin | |
28 * must free all its memory. | |
29 * -# <tt>const char* OrthancPluginGetName()</tt>: | |
30 * The plugin must return a short string to identify itself. | |
31 * -# <tt>const char* OrthancPluginGetVersion()</tt>: | |
32 * The plugin must return a string containing its version number. | |
33 * | |
34 * The name and the version of a plugin is only used to prevent it | |
35 * from being loaded twice. Note that, in C++, it is mandatory to | |
36 * declare these functions within an <tt>extern "C"</tt> section. | |
37 * | |
38 * To ensure multi-threading safety, the various REST callbacks are | |
39 * guaranteed to be executed in mutual exclusion since Orthanc | |
40 * 0.8.5. If this feature is undesired (notably when developing | |
41 * high-performance plugins handling simultaneous requests), use | |
42 * ::OrthancPluginRegisterRestCallbackNoLock(). | |
43 **/ | |
44 | |
45 | |
46 | |
47 /** | |
48 * @defgroup Images Images and compression | |
49 * @brief Functions to deal with images and compressed buffers. | |
50 * | |
51 * @defgroup REST REST | |
52 * @brief Functions to answer REST requests in a callback. | |
53 * | |
54 * @defgroup Callbacks Callbacks | |
55 * @brief Functions to register and manage callbacks by the plugins. | |
56 * | |
57 * @defgroup DicomCallbaks DicomCallbaks | |
58 * @brief Functions to register and manage DICOM callbacks (worklists, C-Find, C-MOVE). | |
59 * | |
60 * @defgroup Orthanc Orthanc | |
61 * @brief Functions to access the content of the Orthanc server. | |
62 **/ | |
63 | |
64 | |
65 | |
66 /** | |
67 * @defgroup Toolbox Toolbox | |
68 * @brief Generic functions to help with the creation of plugins. | |
69 **/ | |
70 | |
71 | |
72 | |
73 /** | |
74 * Orthanc - A Lightweight, RESTful DICOM Store | |
75 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
76 * Department, University Hospital of Liege, Belgium | |
77 * | |
78 * This program is free software: you can redistribute it and/or | |
79 * modify it under the terms of the GNU General Public License as | |
80 * published by the Free Software Foundation, either version 3 of the | |
81 * License, or (at your option) any later version. | |
82 * | |
83 * In addition, as a special exception, the copyright holders of this | |
84 * program give permission to link the code of its release with the | |
85 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
86 * that use the same license as the "OpenSSL" library), and distribute | |
87 * the linked executables. You must obey the GNU General Public License | |
88 * in all respects for all of the code used other than "OpenSSL". If you | |
89 * modify file(s) with this exception, you may extend this exception to | |
90 * your version of the file(s), but you are not obligated to do so. If | |
91 * you do not wish to do so, delete this exception statement from your | |
92 * version. If you delete this exception statement from all source files | |
93 * in the program, then also delete it here. | |
94 * | |
95 * This program is distributed in the hope that it will be useful, but | |
96 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
97 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
98 * General Public License for more details. | |
99 * | |
100 * You should have received a copy of the GNU General Public License | |
101 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
102 **/ | |
103 | |
104 | |
105 | |
106 #pragma once | |
107 | |
108 | |
109 #include <stdio.h> | |
110 #include <string.h> | |
111 | |
112 #ifdef WIN32 | |
113 #define ORTHANC_PLUGINS_API __declspec(dllexport) | |
114 #else | |
115 #define ORTHANC_PLUGINS_API | |
116 #endif | |
117 | |
118 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 | |
119 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 2 | |
120 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 0 | |
121 | |
122 | |
123 | |
124 /******************************************************************** | |
125 ** Check that function inlining is properly supported. The use of | |
126 ** inlining is required, to avoid the duplication of object code | |
127 ** between two compilation modules that would use the Orthanc Plugin | |
128 ** API. | |
129 ********************************************************************/ | |
130 | |
131 /* If the auto-detection of the "inline" keyword below does not work | |
132 automatically and that your compiler is known to properly support | |
133 inlining, uncomment the following #define and adapt the definition | |
134 of "static inline". */ | |
135 | |
136 /* #define ORTHANC_PLUGIN_INLINE static inline */ | |
137 | |
138 #ifndef ORTHANC_PLUGIN_INLINE | |
139 # if __STDC_VERSION__ >= 199901L | |
140 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */ | |
141 # define ORTHANC_PLUGIN_INLINE static inline | |
142 # elif defined(__cplusplus) | |
143 /* This is C++ */ | |
144 # define ORTHANC_PLUGIN_INLINE static inline | |
145 # elif defined(__GNUC__) | |
146 /* This is GCC running in C89 mode */ | |
147 # define ORTHANC_PLUGIN_INLINE static __inline | |
148 # elif defined(_MSC_VER) | |
149 /* This is Visual Studio running in C89 mode */ | |
150 # define ORTHANC_PLUGIN_INLINE static __inline | |
151 # else | |
152 # error Your compiler is not known to support the "inline" keyword | |
153 # endif | |
154 #endif | |
155 | |
156 | |
157 | |
158 /******************************************************************** | |
159 ** Inclusion of standard libraries. | |
160 ********************************************************************/ | |
161 | |
162 /** | |
163 * For Microsoft Visual Studio, a compatibility "stdint.h" can be | |
164 * downloaded at the following URL: | |
165 * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h | |
166 **/ | |
167 #include <stdint.h> | |
168 | |
169 #include <stdlib.h> | |
170 | |
171 | |
172 | |
173 /******************************************************************** | |
174 ** Definition of the Orthanc Plugin API. | |
175 ********************************************************************/ | |
176 | |
177 /** @{ */ | |
178 | |
179 #ifdef __cplusplus | |
180 extern "C" | |
181 { | |
182 #endif | |
183 | |
184 /** | |
185 * The various error codes that can be returned by the Orthanc core. | |
186 **/ | |
187 typedef enum | |
188 { | |
189 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */, | |
190 OrthancPluginErrorCode_Success = 0 /*!< Success */, | |
191 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, | |
192 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */, | |
193 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */, | |
194 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */, | |
195 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */, | |
196 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */, | |
197 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */, | |
198 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */, | |
199 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */, | |
200 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */, | |
201 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */, | |
202 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */, | |
203 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */, | |
204 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */, | |
205 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */, | |
206 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */, | |
207 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */, | |
208 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */, | |
209 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */, | |
210 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */, | |
211 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */, | |
212 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */, | |
213 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */, | |
214 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */, | |
215 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */, | |
216 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */, | |
217 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */, | |
218 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, | |
219 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, | |
220 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */, | |
221 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, | |
222 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, | |
223 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */, | |
224 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */, | |
225 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */, | |
226 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, | |
227 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, | |
228 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, | |
229 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */, | |
230 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */, | |
231 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */, | |
232 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */, | |
233 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */, | |
234 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */, | |
235 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */, | |
236 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */, | |
237 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */, | |
238 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */, | |
239 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */, | |
240 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */, | |
241 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */, | |
242 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */, | |
243 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */, | |
244 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */, | |
245 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */, | |
246 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */, | |
247 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */, | |
248 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */, | |
249 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */, | |
250 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */, | |
251 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */, | |
252 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */, | |
253 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */, | |
254 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */, | |
255 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */, | |
256 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */, | |
257 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */, | |
258 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */, | |
259 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */, | |
260 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */, | |
261 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */, | |
262 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */, | |
263 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */, | |
264 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */, | |
265 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */, | |
266 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */, | |
267 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */, | |
268 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, | |
269 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */, | |
270 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, | |
271 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, | |
272 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, | |
273 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, | |
274 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, | |
275 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, | |
276 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, | |
277 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, | |
278 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, | |
279 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, | |
280 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */, | |
281 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */, | |
282 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */, | |
283 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */, | |
284 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */, | |
285 | |
286 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff | |
287 } OrthancPluginErrorCode; | |
288 | |
289 | |
290 /** | |
291 * Forward declaration of one of the mandatory functions for Orthanc | |
292 * plugins. | |
293 **/ | |
294 ORTHANC_PLUGINS_API const char* OrthancPluginGetName(); | |
295 | |
296 | |
297 /** | |
298 * The various HTTP methods for a REST call. | |
299 **/ | |
300 typedef enum | |
301 { | |
302 OrthancPluginHttpMethod_Get = 1, /*!< GET request */ | |
303 OrthancPluginHttpMethod_Post = 2, /*!< POST request */ | |
304 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */ | |
305 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */ | |
306 | |
307 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff | |
308 } OrthancPluginHttpMethod; | |
309 | |
310 | |
311 /** | |
312 * @brief The parameters of a REST request. | |
313 * @ingroup Callbacks | |
314 **/ | |
315 typedef struct | |
316 { | |
317 /** | |
318 * @brief The HTTP method. | |
319 **/ | |
320 OrthancPluginHttpMethod method; | |
321 | |
322 /** | |
323 * @brief The number of groups of the regular expression. | |
324 **/ | |
325 uint32_t groupsCount; | |
326 | |
327 /** | |
328 * @brief The matched values for the groups of the regular expression. | |
329 **/ | |
330 const char* const* groups; | |
331 | |
332 /** | |
333 * @brief For a GET request, the number of GET parameters. | |
334 **/ | |
335 uint32_t getCount; | |
336 | |
337 /** | |
338 * @brief For a GET request, the keys of the GET parameters. | |
339 **/ | |
340 const char* const* getKeys; | |
341 | |
342 /** | |
343 * @brief For a GET request, the values of the GET parameters. | |
344 **/ | |
345 const char* const* getValues; | |
346 | |
347 /** | |
348 * @brief For a PUT or POST request, the content of the body. | |
349 **/ | |
350 const char* body; | |
351 | |
352 /** | |
353 * @brief For a PUT or POST request, the number of bytes of the body. | |
354 **/ | |
355 uint32_t bodySize; | |
356 | |
357 | |
358 /* -------------------------------------------------- | |
359 New in version 0.8.1 | |
360 -------------------------------------------------- */ | |
361 | |
362 /** | |
363 * @brief The number of HTTP headers. | |
364 **/ | |
365 uint32_t headersCount; | |
366 | |
367 /** | |
368 * @brief The keys of the HTTP headers (always converted to low-case). | |
369 **/ | |
370 const char* const* headersKeys; | |
371 | |
372 /** | |
373 * @brief The values of the HTTP headers. | |
374 **/ | |
375 const char* const* headersValues; | |
376 | |
377 } OrthancPluginHttpRequest; | |
378 | |
379 | |
380 typedef enum | |
381 { | |
382 /* Generic services */ | |
383 _OrthancPluginService_LogInfo = 1, | |
384 _OrthancPluginService_LogWarning = 2, | |
385 _OrthancPluginService_LogError = 3, | |
386 _OrthancPluginService_GetOrthancPath = 4, | |
387 _OrthancPluginService_GetOrthancDirectory = 5, | |
388 _OrthancPluginService_GetConfigurationPath = 6, | |
389 _OrthancPluginService_SetPluginProperty = 7, | |
390 _OrthancPluginService_GetGlobalProperty = 8, | |
391 _OrthancPluginService_SetGlobalProperty = 9, | |
392 _OrthancPluginService_GetCommandLineArgumentsCount = 10, | |
393 _OrthancPluginService_GetCommandLineArgument = 11, | |
394 _OrthancPluginService_GetExpectedDatabaseVersion = 12, | |
395 _OrthancPluginService_GetConfiguration = 13, | |
396 _OrthancPluginService_BufferCompression = 14, | |
397 _OrthancPluginService_ReadFile = 15, | |
398 _OrthancPluginService_WriteFile = 16, | |
399 _OrthancPluginService_GetErrorDescription = 17, | |
400 _OrthancPluginService_CallHttpClient = 18, | |
401 _OrthancPluginService_RegisterErrorCode = 19, | |
402 _OrthancPluginService_RegisterDictionaryTag = 20, | |
403 _OrthancPluginService_DicomBufferToJson = 21, | |
404 _OrthancPluginService_DicomInstanceToJson = 22, | |
405 _OrthancPluginService_CreateDicom = 23, | |
406 _OrthancPluginService_ComputeMd5 = 24, | |
407 _OrthancPluginService_ComputeSha1 = 25, | |
408 _OrthancPluginService_LookupDictionary = 26, | |
409 _OrthancPluginService_CallHttpClient2 = 27, | |
410 _OrthancPluginService_GenerateUuid = 28, | |
411 _OrthancPluginService_RegisterPrivateDictionaryTag = 29, | |
412 | |
413 /* Registration of callbacks */ | |
414 _OrthancPluginService_RegisterRestCallback = 1000, | |
415 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001, | |
416 _OrthancPluginService_RegisterStorageArea = 1002, | |
417 _OrthancPluginService_RegisterOnChangeCallback = 1003, | |
418 _OrthancPluginService_RegisterRestCallbackNoLock = 1004, | |
419 _OrthancPluginService_RegisterWorklistCallback = 1005, | |
420 _OrthancPluginService_RegisterDecodeImageCallback = 1006, | |
421 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007, | |
422 _OrthancPluginService_RegisterFindCallback = 1008, | |
423 _OrthancPluginService_RegisterMoveCallback = 1009, | |
424 | |
425 /* Sending answers to REST calls */ | |
426 _OrthancPluginService_AnswerBuffer = 2000, | |
427 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */ | |
428 _OrthancPluginService_Redirect = 2002, | |
429 _OrthancPluginService_SendHttpStatusCode = 2003, | |
430 _OrthancPluginService_SendUnauthorized = 2004, | |
431 _OrthancPluginService_SendMethodNotAllowed = 2005, | |
432 _OrthancPluginService_SetCookie = 2006, | |
433 _OrthancPluginService_SetHttpHeader = 2007, | |
434 _OrthancPluginService_StartMultipartAnswer = 2008, | |
435 _OrthancPluginService_SendMultipartItem = 2009, | |
436 _OrthancPluginService_SendHttpStatus = 2010, | |
437 _OrthancPluginService_CompressAndAnswerImage = 2011, | |
438 _OrthancPluginService_SendMultipartItem2 = 2012, | |
439 | |
440 /* Access to the Orthanc database and API */ | |
441 _OrthancPluginService_GetDicomForInstance = 3000, | |
442 _OrthancPluginService_RestApiGet = 3001, | |
443 _OrthancPluginService_RestApiPost = 3002, | |
444 _OrthancPluginService_RestApiDelete = 3003, | |
445 _OrthancPluginService_RestApiPut = 3004, | |
446 _OrthancPluginService_LookupPatient = 3005, | |
447 _OrthancPluginService_LookupStudy = 3006, | |
448 _OrthancPluginService_LookupSeries = 3007, | |
449 _OrthancPluginService_LookupInstance = 3008, | |
450 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009, | |
451 _OrthancPluginService_RestApiGetAfterPlugins = 3010, | |
452 _OrthancPluginService_RestApiPostAfterPlugins = 3011, | |
453 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, | |
454 _OrthancPluginService_RestApiPutAfterPlugins = 3013, | |
455 _OrthancPluginService_ReconstructMainDicomTags = 3014, | |
456 _OrthancPluginService_RestApiGet2 = 3015, | |
457 | |
458 /* Access to DICOM instances */ | |
459 _OrthancPluginService_GetInstanceRemoteAet = 4000, | |
460 _OrthancPluginService_GetInstanceSize = 4001, | |
461 _OrthancPluginService_GetInstanceData = 4002, | |
462 _OrthancPluginService_GetInstanceJson = 4003, | |
463 _OrthancPluginService_GetInstanceSimplifiedJson = 4004, | |
464 _OrthancPluginService_HasInstanceMetadata = 4005, | |
465 _OrthancPluginService_GetInstanceMetadata = 4006, | |
466 _OrthancPluginService_GetInstanceOrigin = 4007, | |
467 | |
468 /* Services for plugins implementing a database back-end */ | |
469 _OrthancPluginService_RegisterDatabaseBackend = 5000, | |
470 _OrthancPluginService_DatabaseAnswer = 5001, | |
471 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002, | |
472 _OrthancPluginService_StorageAreaCreate = 5003, | |
473 _OrthancPluginService_StorageAreaRead = 5004, | |
474 _OrthancPluginService_StorageAreaRemove = 5005, | |
475 | |
476 /* Primitives for handling images */ | |
477 _OrthancPluginService_GetImagePixelFormat = 6000, | |
478 _OrthancPluginService_GetImageWidth = 6001, | |
479 _OrthancPluginService_GetImageHeight = 6002, | |
480 _OrthancPluginService_GetImagePitch = 6003, | |
481 _OrthancPluginService_GetImageBuffer = 6004, | |
482 _OrthancPluginService_UncompressImage = 6005, | |
483 _OrthancPluginService_FreeImage = 6006, | |
484 _OrthancPluginService_CompressImage = 6007, | |
485 _OrthancPluginService_ConvertPixelFormat = 6008, | |
486 _OrthancPluginService_GetFontsCount = 6009, | |
487 _OrthancPluginService_GetFontInfo = 6010, | |
488 _OrthancPluginService_DrawText = 6011, | |
489 _OrthancPluginService_CreateImage = 6012, | |
490 _OrthancPluginService_CreateImageAccessor = 6013, | |
491 _OrthancPluginService_DecodeDicomImage = 6014, | |
492 | |
493 /* Primitives for handling C-Find, C-Move and worklists */ | |
494 _OrthancPluginService_WorklistAddAnswer = 7000, | |
495 _OrthancPluginService_WorklistMarkIncomplete = 7001, | |
496 _OrthancPluginService_WorklistIsMatch = 7002, | |
497 _OrthancPluginService_WorklistGetDicomQuery = 7003, | |
498 _OrthancPluginService_FindAddAnswer = 7004, | |
499 _OrthancPluginService_FindMarkIncomplete = 7005, | |
500 _OrthancPluginService_GetFindQuerySize = 7006, | |
501 _OrthancPluginService_GetFindQueryTag = 7007, | |
502 _OrthancPluginService_GetFindQueryTagName = 7008, | |
503 _OrthancPluginService_GetFindQueryValue = 7009, | |
504 _OrthancPluginService_CreateFindMatcher = 7010, | |
505 _OrthancPluginService_FreeFindMatcher = 7011, | |
506 _OrthancPluginService_FindMatcherIsMatch = 7012, | |
507 | |
508 _OrthancPluginService_INTERNAL = 0x7fffffff | |
509 } _OrthancPluginService; | |
510 | |
511 | |
512 typedef enum | |
513 { | |
514 _OrthancPluginProperty_Description = 1, | |
515 _OrthancPluginProperty_RootUri = 2, | |
516 _OrthancPluginProperty_OrthancExplorer = 3, | |
517 | |
518 _OrthancPluginProperty_INTERNAL = 0x7fffffff | |
519 } _OrthancPluginProperty; | |
520 | |
521 | |
522 | |
523 /** | |
524 * The memory layout of the pixels of an image. | |
525 * @ingroup Images | |
526 **/ | |
527 typedef enum | |
528 { | |
529 /** | |
530 * @brief Graylevel 8bpp image. | |
531 * | |
532 * The image is graylevel. Each pixel is unsigned and stored in | |
533 * one byte. | |
534 **/ | |
535 OrthancPluginPixelFormat_Grayscale8 = 1, | |
536 | |
537 /** | |
538 * @brief Graylevel, unsigned 16bpp image. | |
539 * | |
540 * The image is graylevel. Each pixel is unsigned and stored in | |
541 * two bytes. | |
542 **/ | |
543 OrthancPluginPixelFormat_Grayscale16 = 2, | |
544 | |
545 /** | |
546 * @brief Graylevel, signed 16bpp image. | |
547 * | |
548 * The image is graylevel. Each pixel is signed and stored in two | |
549 * bytes. | |
550 **/ | |
551 OrthancPluginPixelFormat_SignedGrayscale16 = 3, | |
552 | |
553 /** | |
554 * @brief Color image in RGB24 format. | |
555 * | |
556 * This format describes a color image. The pixels are stored in 3 | |
557 * consecutive bytes. The memory layout is RGB. | |
558 **/ | |
559 OrthancPluginPixelFormat_RGB24 = 4, | |
560 | |
561 /** | |
562 * @brief Color image in RGBA32 format. | |
563 * | |
564 * This format describes a color image. The pixels are stored in 4 | |
565 * consecutive bytes. The memory layout is RGBA. | |
566 **/ | |
567 OrthancPluginPixelFormat_RGBA32 = 5, | |
568 | |
569 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */ | |
570 | |
571 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff | |
572 } OrthancPluginPixelFormat; | |
573 | |
574 | |
575 | |
576 /** | |
577 * The content types that are supported by Orthanc plugins. | |
578 **/ | |
579 typedef enum | |
580 { | |
581 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */ | |
582 OrthancPluginContentType_Dicom = 1, /*!< DICOM */ | |
583 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */ | |
584 | |
585 _OrthancPluginContentType_INTERNAL = 0x7fffffff | |
586 } OrthancPluginContentType; | |
587 | |
588 | |
589 | |
590 /** | |
591 * The supported types of DICOM resources. | |
592 **/ | |
593 typedef enum | |
594 { | |
595 OrthancPluginResourceType_Patient = 0, /*!< Patient */ | |
596 OrthancPluginResourceType_Study = 1, /*!< Study */ | |
597 OrthancPluginResourceType_Series = 2, /*!< Series */ | |
598 OrthancPluginResourceType_Instance = 3, /*!< Instance */ | |
599 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */ | |
600 | |
601 _OrthancPluginResourceType_INTERNAL = 0x7fffffff | |
602 } OrthancPluginResourceType; | |
603 | |
604 | |
605 | |
606 /** | |
607 * The supported types of changes that can happen to DICOM resources. | |
608 * @ingroup Callbacks | |
609 **/ | |
610 typedef enum | |
611 { | |
612 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */ | |
613 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */ | |
614 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */ | |
615 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */ | |
616 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */ | |
617 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */ | |
618 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */ | |
619 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */ | |
620 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */ | |
621 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ | |
622 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ | |
623 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ | |
624 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */ | |
625 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */ | |
626 | |
627 _OrthancPluginChangeType_INTERNAL = 0x7fffffff | |
628 } OrthancPluginChangeType; | |
629 | |
630 | |
631 /** | |
632 * The compression algorithms that are supported by the Orthanc core. | |
633 * @ingroup Images | |
634 **/ | |
635 typedef enum | |
636 { | |
637 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */ | |
638 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */ | |
639 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */ | |
640 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */ | |
641 | |
642 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff | |
643 } OrthancPluginCompressionType; | |
644 | |
645 | |
646 /** | |
647 * The image formats that are supported by the Orthanc core. | |
648 * @ingroup Images | |
649 **/ | |
650 typedef enum | |
651 { | |
652 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */ | |
653 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */ | |
654 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */ | |
655 | |
656 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff | |
657 } OrthancPluginImageFormat; | |
658 | |
659 | |
660 /** | |
661 * The value representations present in the DICOM standard (version 2013). | |
662 * @ingroup Toolbox | |
663 **/ | |
664 typedef enum | |
665 { | |
666 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */ | |
667 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */ | |
668 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */ | |
669 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */ | |
670 OrthancPluginValueRepresentation_DA = 5, /*!< Date */ | |
671 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */ | |
672 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */ | |
673 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */ | |
674 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */ | |
675 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */ | |
676 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */ | |
677 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */ | |
678 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */ | |
679 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */ | |
680 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */ | |
681 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */ | |
682 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */ | |
683 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */ | |
684 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */ | |
685 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */ | |
686 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */ | |
687 OrthancPluginValueRepresentation_TM = 22, /*!< Time */ | |
688 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */ | |
689 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */ | |
690 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */ | |
691 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */ | |
692 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */ | |
693 | |
694 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff | |
695 } OrthancPluginValueRepresentation; | |
696 | |
697 | |
698 /** | |
699 * The possible output formats for a DICOM-to-JSON conversion. | |
700 * @ingroup Toolbox | |
701 * @see OrthancPluginDicomToJson() | |
702 **/ | |
703 typedef enum | |
704 { | |
705 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */ | |
706 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */ | |
707 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */ | |
708 | |
709 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff | |
710 } OrthancPluginDicomToJsonFormat; | |
711 | |
712 | |
713 /** | |
714 * Flags to customize a DICOM-to-JSON conversion. By default, binary | |
715 * tags are formatted using Data URI scheme. | |
716 * @ingroup Toolbox | |
717 **/ | |
718 typedef enum | |
719 { | |
720 OrthancPluginDicomToJsonFlags_None = 0, | |
721 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */ | |
722 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */ | |
723 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */ | |
724 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */ | |
725 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */ | |
726 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */ | |
727 | |
728 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff | |
729 } OrthancPluginDicomToJsonFlags; | |
730 | |
731 | |
732 /** | |
733 * Flags to the creation of a DICOM file. | |
734 * @ingroup Toolbox | |
735 * @see OrthancPluginCreateDicom() | |
736 **/ | |
737 typedef enum | |
738 { | |
739 OrthancPluginCreateDicomFlags_None = 0, | |
740 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */ | |
741 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */ | |
742 | |
743 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff | |
744 } OrthancPluginCreateDicomFlags; | |
745 | |
746 | |
747 /** | |
748 * The constraints on the DICOM identifiers that must be supported | |
749 * by the database plugins. | |
750 **/ | |
751 typedef enum | |
752 { | |
753 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */ | |
754 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */ | |
755 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */ | |
756 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */ | |
757 | |
758 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff | |
759 } OrthancPluginIdentifierConstraint; | |
760 | |
761 | |
762 /** | |
763 * The origin of a DICOM instance that has been received by Orthanc. | |
764 **/ | |
765 typedef enum | |
766 { | |
767 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */ | |
768 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */ | |
769 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */ | |
770 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */ | |
771 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */ | |
772 | |
773 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff | |
774 } OrthancPluginInstanceOrigin; | |
775 | |
776 | |
777 /** | |
778 * @brief A memory buffer allocated by the core system of Orthanc. | |
779 * | |
780 * A memory buffer allocated by the core system of Orthanc. When the | |
781 * content of the buffer is not useful anymore, it must be free by a | |
782 * call to ::OrthancPluginFreeMemoryBuffer(). | |
783 **/ | |
784 typedef struct | |
785 { | |
786 /** | |
787 * @brief The content of the buffer. | |
788 **/ | |
789 void* data; | |
790 | |
791 /** | |
792 * @brief The number of bytes in the buffer. | |
793 **/ | |
794 uint32_t size; | |
795 } OrthancPluginMemoryBuffer; | |
796 | |
797 | |
798 | |
799 | |
800 /** | |
801 * @brief Opaque structure that represents the HTTP connection to the client application. | |
802 * @ingroup Callback | |
803 **/ | |
804 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput; | |
805 | |
806 | |
807 | |
808 /** | |
809 * @brief Opaque structure that represents a DICOM instance received by Orthanc. | |
810 **/ | |
811 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance; | |
812 | |
813 | |
814 | |
815 /** | |
816 * @brief Opaque structure that represents an image that is uncompressed in memory. | |
817 * @ingroup Images | |
818 **/ | |
819 typedef struct _OrthancPluginImage_t OrthancPluginImage; | |
820 | |
821 | |
822 | |
823 /** | |
824 * @brief Opaque structure that represents the storage area that is actually used by Orthanc. | |
825 * @ingroup Images | |
826 **/ | |
827 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea; | |
828 | |
829 | |
830 | |
831 /** | |
832 * @brief Opaque structure to an object that represents a C-Find query for worklists. | |
833 * @ingroup DicomCallbacks | |
834 **/ | |
835 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery; | |
836 | |
837 | |
838 | |
839 /** | |
840 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. | |
841 * @ingroup DicomCallbacks | |
842 **/ | |
843 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers; | |
844 | |
845 | |
846 | |
847 /** | |
848 * @brief Opaque structure to an object that represents a C-Find query. | |
849 * @ingroup DicomCallbacks | |
850 **/ | |
851 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery; | |
852 | |
853 | |
854 | |
855 /** | |
856 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. | |
857 * @ingroup DicomCallbacks | |
858 **/ | |
859 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers; | |
860 | |
861 | |
862 | |
863 /** | |
864 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query. | |
865 * @ingroup Toolbox | |
866 **/ | |
867 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindMatcher; | |
868 | |
869 | |
870 | |
871 /** | |
872 * @brief Signature of a callback function that answers to a REST request. | |
873 * @ingroup Callbacks | |
874 **/ | |
875 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) ( | |
876 OrthancPluginRestOutput* output, | |
877 const char* url, | |
878 const OrthancPluginHttpRequest* request); | |
879 | |
880 | |
881 | |
882 /** | |
883 * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance. | |
884 * @ingroup Callbacks | |
885 **/ | |
886 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) ( | |
887 OrthancPluginDicomInstance* instance, | |
888 const char* instanceId); | |
889 | |
890 | |
891 | |
892 /** | |
893 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource. | |
894 * @ingroup Callbacks | |
895 **/ | |
896 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) ( | |
897 OrthancPluginChangeType changeType, | |
898 OrthancPluginResourceType resourceType, | |
899 const char* resourceId); | |
900 | |
901 | |
902 | |
903 /** | |
904 * @brief Signature of a callback function to decode a DICOM instance as an image. | |
905 * @ingroup Callbacks | |
906 **/ | |
907 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) ( | |
908 OrthancPluginImage** target, | |
909 const void* dicom, | |
910 const uint32_t size, | |
911 uint32_t frameIndex); | |
912 | |
913 | |
914 | |
915 /** | |
916 * @brief Signature of a function to free dynamic memory. | |
917 **/ | |
918 typedef void (*OrthancPluginFree) (void* buffer); | |
919 | |
920 | |
921 | |
922 /** | |
923 * @brief Callback for writing to the storage area. | |
924 * | |
925 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area. | |
926 * | |
927 * @param uuid The UUID of the file. | |
928 * @param content The content of the file. | |
929 * @param size The size of the file. | |
930 * @param type The content type corresponding to this file. | |
931 * @return 0 if success, other value if error. | |
932 * @ingroup Callbacks | |
933 **/ | |
934 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) ( | |
935 const char* uuid, | |
936 const void* content, | |
937 int64_t size, | |
938 OrthancPluginContentType type); | |
939 | |
940 | |
941 | |
942 /** | |
943 * @brief Callback for reading from the storage area. | |
944 * | |
945 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area. | |
946 * | |
947 * @param content The content of the file (output). | |
948 * @param size The size of the file (output). | |
949 * @param uuid The UUID of the file of interest. | |
950 * @param type The content type corresponding to this file. | |
951 * @return 0 if success, other value if error. | |
952 * @ingroup Callbacks | |
953 **/ | |
954 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) ( | |
955 void** content, | |
956 int64_t* size, | |
957 const char* uuid, | |
958 OrthancPluginContentType type); | |
959 | |
960 | |
961 | |
962 /** | |
963 * @brief Callback for removing a file from the storage area. | |
964 * | |
965 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area. | |
966 * | |
967 * @param uuid The UUID of the file to be removed. | |
968 * @param type The content type corresponding to this file. | |
969 * @return 0 if success, other value if error. | |
970 * @ingroup Callbacks | |
971 **/ | |
972 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) ( | |
973 const char* uuid, | |
974 OrthancPluginContentType type); | |
975 | |
976 | |
977 | |
978 /** | |
979 * @brief Callback to handle the C-Find SCP requests for worklists. | |
980 * | |
981 * Signature of a callback function that is triggered when Orthanc | |
982 * receives a C-Find SCP request against modality worklists. | |
983 * | |
984 * @param answers The target structure where answers must be stored. | |
985 * @param query The worklist query. | |
986 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates. | |
987 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. | |
988 * @return 0 if success, other value if error. | |
989 * @ingroup DicomCallbacks | |
990 **/ | |
991 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) ( | |
992 OrthancPluginWorklistAnswers* answers, | |
993 const OrthancPluginWorklistQuery* query, | |
994 const char* issuerAet, | |
995 const char* calledAet); | |
996 | |
997 | |
998 | |
999 /** | |
1000 * @brief Callback to filter incoming HTTP requests received by Orthanc. | |
1001 * | |
1002 * Signature of a callback function that is triggered whenever | |
1003 * Orthanc receives an HTTP/REST request, and that answers whether | |
1004 * this request should be allowed. If the callback returns "0" | |
1005 * ("false"), the server answers with HTTP status code 403 | |
1006 * (Forbidden). | |
1007 * | |
1008 * @param method The HTTP method used by the request. | |
1009 * @param uri The URI of interest. | |
1010 * @param ip The IP address of the HTTP client. | |
1011 * @param headersCount The number of HTTP headers. | |
1012 * @param headersKeys The keys of the HTTP headers (always converted to low-case). | |
1013 * @param headersValues The values of the HTTP headers. | |
1014 * @return 0 if forbidden access, 1 if allowed access, -1 if error. | |
1015 * @ingroup Callback | |
1016 **/ | |
1017 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) ( | |
1018 OrthancPluginHttpMethod method, | |
1019 const char* uri, | |
1020 const char* ip, | |
1021 uint32_t headersCount, | |
1022 const char* const* headersKeys, | |
1023 const char* const* headersValues); | |
1024 | |
1025 | |
1026 | |
1027 /** | |
1028 * @brief Callback to handle incoming C-Find SCP requests. | |
1029 * | |
1030 * Signature of a callback function that is triggered whenever | |
1031 * Orthanc receives a C-Find SCP request not concerning modality | |
1032 * worklists. | |
1033 * | |
1034 * @param answers The target structure where answers must be stored. | |
1035 * @param query The worklist query. | |
1036 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates. | |
1037 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. | |
1038 * @return 0 if success, other value if error. | |
1039 * @ingroup DicomCallbacks | |
1040 **/ | |
1041 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) ( | |
1042 OrthancPluginFindAnswers* answers, | |
1043 const OrthancPluginFindQuery* query, | |
1044 const char* issuerAet, | |
1045 const char* calledAet); | |
1046 | |
1047 | |
1048 | |
1049 /** | |
1050 * @brief Callback to handle incoming C-Move SCP requests. | |
1051 * | |
1052 * Signature of a callback function that is triggered whenever | |
1053 * Orthanc receives a C-Move SCP request. The callback receives the | |
1054 * type of the resource of interest (study, series, instance...) | |
1055 * together with the DICOM tags containing its identifiers. In turn, | |
1056 * the plugin must create a driver object that will be responsible | |
1057 * for driving the successive move suboperations. | |
1058 * | |
1059 * @param resourceType The type of the resource of interest. Note | |
1060 * that this might be set to ResourceType_None if the | |
1061 * QueryRetrieveLevel (0008,0052) tag was not provided by the | |
1062 * issuer (i.e. the originator modality). | |
1063 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL. | |
1064 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL. | |
1065 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL. | |
1066 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL. | |
1067 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL. | |
1068 * @param originatorAet The Application Entity Title (AET) of the | |
1069 * modality from which the request originates. | |
1070 * @param sourceAet The Application Entity Title (AET) of the | |
1071 * modality that should send its DICOM files to another modality. | |
1072 * @param targetAet The Application Entity Title (AET) of the | |
1073 * modality that should receive the DICOM files. | |
1074 * @param originatorId The Message ID issued by the originator modality, | |
1075 * as found in tag (0000,0110) of the DICOM query emitted by the issuer. | |
1076 * | |
1077 * @return The NULL value if the plugin cannot deal with this query, | |
1078 * or a pointer to the driver object that is responsible for | |
1079 * handling the successive move suboperations. | |
1080 * | |
1081 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation. | |
1082 * @ingroup DicomCallbacks | |
1083 **/ | |
1084 typedef void* (*OrthancPluginMoveCallback) ( | |
1085 OrthancPluginResourceType resourceType, | |
1086 const char* patientId, | |
1087 const char* accessionNumber, | |
1088 const char* studyInstanceUid, | |
1089 const char* seriesInstanceUid, | |
1090 const char* sopInstanceUid, | |
1091 const char* originatorAet, | |
1092 const char* sourceAet, | |
1093 const char* targetAet, | |
1094 uint16_t originatorId); | |
1095 | |
1096 | |
1097 /** | |
1098 * @brief Callback to read the size of a C-Move driver. | |
1099 * | |
1100 * Signature of a callback function that returns the number of | |
1101 * C-Move suboperations that are to be achieved by the given C-Move | |
1102 * driver. This driver is the return value of a previous call to the | |
1103 * OrthancPluginMoveCallback() callback. | |
1104 * | |
1105 * @param moveDriver The C-Move driver of interest. | |
1106 * @return The number of suboperations. | |
1107 **/ | |
1108 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver); | |
1109 | |
1110 | |
1111 /** | |
1112 * @brief Callback to apply one C-Move suboperation. | |
1113 * | |
1114 * Signature of a callback function that applies the next C-Move | |
1115 * suboperation that os to be achieved by the given C-Move | |
1116 * driver. This driver is the return value of a previous call to the | |
1117 * OrthancPluginMoveCallback() callback. | |
1118 * | |
1119 * @param moveDriver The C-Move driver of interest. | |
1120 * @return 0 if success, or the error code if failure. | |
1121 **/ | |
1122 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver); | |
1123 | |
1124 | |
1125 /** | |
1126 * @brief Callback to free one C-Move driver. | |
1127 * | |
1128 * Signature of a callback function that releases the resources | |
1129 * allocated by the given C-Move driver. This driver is the return | |
1130 * value of a previous call to the OrthancPluginMoveCallback() | |
1131 * callback. | |
1132 * | |
1133 * @param moveDriver The C-Move driver of interest. | |
1134 **/ | |
1135 typedef void (*OrthancPluginFreeMove) (void* moveDriver); | |
1136 | |
1137 | |
1138 | |
1139 /** | |
1140 * @brief Data structure that contains information about the Orthanc core. | |
1141 **/ | |
1142 typedef struct _OrthancPluginContext_t | |
1143 { | |
1144 void* pluginsManager; | |
1145 const char* orthancVersion; | |
1146 OrthancPluginFree Free; | |
1147 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context, | |
1148 _OrthancPluginService service, | |
1149 const void* params); | |
1150 } OrthancPluginContext; | |
1151 | |
1152 | |
1153 | |
1154 /** | |
1155 * @brief An entry in the dictionary of DICOM tags. | |
1156 **/ | |
1157 typedef struct | |
1158 { | |
1159 uint16_t group; /*!< The group of the tag */ | |
1160 uint16_t element; /*!< The element of the tag */ | |
1161 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */ | |
1162 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */ | |
1163 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */ | |
1164 } OrthancPluginDictionaryEntry; | |
1165 | |
1166 | |
1167 | |
1168 /** | |
1169 * @brief Free a string. | |
1170 * | |
1171 * Free a string that was allocated by the core system of Orthanc. | |
1172 * | |
1173 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1174 * @param str The string to be freed. | |
1175 **/ | |
1176 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString( | |
1177 OrthancPluginContext* context, | |
1178 char* str) | |
1179 { | |
1180 if (str != NULL) | |
1181 { | |
1182 context->Free(str); | |
1183 } | |
1184 } | |
1185 | |
1186 | |
1187 /** | |
1188 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc. | |
1189 * | |
1190 * This function checks whether the version of this C header is | |
1191 * compatible with the current version of Orthanc. The result of | |
1192 * this function should always be checked in the | |
1193 * OrthancPluginInitialize() entry point of the plugin. | |
1194 * | |
1195 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1196 * @return 1 if and only if the versions are compatible. If the | |
1197 * result is 0, the initialization of the plugin should fail. | |
1198 * @ingroup Callbacks | |
1199 **/ | |
1200 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( | |
1201 OrthancPluginContext* context) | |
1202 { | |
1203 int major, minor, revision; | |
1204 | |
1205 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) || | |
1206 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) || | |
1207 sizeof(int32_t) != sizeof(_OrthancPluginService) || | |
1208 sizeof(int32_t) != sizeof(_OrthancPluginProperty) || | |
1209 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || | |
1210 sizeof(int32_t) != sizeof(OrthancPluginContentType) || | |
1211 sizeof(int32_t) != sizeof(OrthancPluginResourceType) || | |
1212 sizeof(int32_t) != sizeof(OrthancPluginChangeType) || | |
1213 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || | |
1214 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || | |
1215 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || | |
1216 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || | |
1217 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || | |
1218 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || | |
1219 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || | |
1220 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin)) | |
1221 { | |
1222 /* Mismatch in the size of the enumerations */ | |
1223 return 0; | |
1224 } | |
1225 | |
1226 /* Assume compatibility with the mainline */ | |
1227 if (!strcmp(context->orthancVersion, "mainline")) | |
1228 { | |
1229 return 1; | |
1230 } | |
1231 | |
1232 /* Parse the version of the Orthanc core */ | |
1233 if ( | |
1234 #ifdef _MSC_VER | |
1235 sscanf_s | |
1236 #else | |
1237 sscanf | |
1238 #endif | |
1239 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3) | |
1240 { | |
1241 return 0; | |
1242 } | |
1243 | |
1244 /* Check the major number of the version */ | |
1245 | |
1246 if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) | |
1247 { | |
1248 return 1; | |
1249 } | |
1250 | |
1251 if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) | |
1252 { | |
1253 return 0; | |
1254 } | |
1255 | |
1256 /* Check the minor number of the version */ | |
1257 | |
1258 if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) | |
1259 { | |
1260 return 1; | |
1261 } | |
1262 | |
1263 if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) | |
1264 { | |
1265 return 0; | |
1266 } | |
1267 | |
1268 /* Check the revision number of the version */ | |
1269 | |
1270 if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER) | |
1271 { | |
1272 return 1; | |
1273 } | |
1274 else | |
1275 { | |
1276 return 0; | |
1277 } | |
1278 } | |
1279 | |
1280 | |
1281 /** | |
1282 * @brief Free a memory buffer. | |
1283 * | |
1284 * Free a memory buffer that was allocated by the core system of Orthanc. | |
1285 * | |
1286 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1287 * @param buffer The memory buffer to release. | |
1288 **/ | |
1289 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer( | |
1290 OrthancPluginContext* context, | |
1291 OrthancPluginMemoryBuffer* buffer) | |
1292 { | |
1293 context->Free(buffer->data); | |
1294 } | |
1295 | |
1296 | |
1297 /** | |
1298 * @brief Log an error. | |
1299 * | |
1300 * Log an error message using the Orthanc logging system. | |
1301 * | |
1302 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1303 * @param message The message to be logged. | |
1304 **/ | |
1305 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError( | |
1306 OrthancPluginContext* context, | |
1307 const char* message) | |
1308 { | |
1309 context->InvokeService(context, _OrthancPluginService_LogError, message); | |
1310 } | |
1311 | |
1312 | |
1313 /** | |
1314 * @brief Log a warning. | |
1315 * | |
1316 * Log a warning message using the Orthanc logging system. | |
1317 * | |
1318 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1319 * @param message The message to be logged. | |
1320 **/ | |
1321 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning( | |
1322 OrthancPluginContext* context, | |
1323 const char* message) | |
1324 { | |
1325 context->InvokeService(context, _OrthancPluginService_LogWarning, message); | |
1326 } | |
1327 | |
1328 | |
1329 /** | |
1330 * @brief Log an information. | |
1331 * | |
1332 * Log an information message using the Orthanc logging system. | |
1333 * | |
1334 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1335 * @param message The message to be logged. | |
1336 **/ | |
1337 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo( | |
1338 OrthancPluginContext* context, | |
1339 const char* message) | |
1340 { | |
1341 context->InvokeService(context, _OrthancPluginService_LogInfo, message); | |
1342 } | |
1343 | |
1344 | |
1345 | |
1346 typedef struct | |
1347 { | |
1348 const char* pathRegularExpression; | |
1349 OrthancPluginRestCallback callback; | |
1350 } _OrthancPluginRestCallback; | |
1351 | |
1352 /** | |
1353 * @brief Register a REST callback. | |
1354 * | |
1355 * This function registers a REST callback against a regular | |
1356 * expression for a URI. This function must be called during the | |
1357 * initialization of the plugin, i.e. inside the | |
1358 * OrthancPluginInitialize() public function. | |
1359 * | |
1360 * Each REST callback is guaranteed to run in mutual exclusion. | |
1361 * | |
1362 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1363 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
1364 * @param callback The callback function to handle the REST call. | |
1365 * @see OrthancPluginRegisterRestCallbackNoLock() | |
1366 * @ingroup Callbacks | |
1367 **/ | |
1368 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback( | |
1369 OrthancPluginContext* context, | |
1370 const char* pathRegularExpression, | |
1371 OrthancPluginRestCallback callback) | |
1372 { | |
1373 _OrthancPluginRestCallback params; | |
1374 params.pathRegularExpression = pathRegularExpression; | |
1375 params.callback = callback; | |
1376 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, ¶ms); | |
1377 } | |
1378 | |
1379 | |
1380 | |
1381 /** | |
1382 * @brief Register a REST callback, without locking. | |
1383 * | |
1384 * This function registers a REST callback against a regular | |
1385 * expression for a URI. This function must be called during the | |
1386 * initialization of the plugin, i.e. inside the | |
1387 * OrthancPluginInitialize() public function. | |
1388 * | |
1389 * Contrarily to OrthancPluginRegisterRestCallback(), the callback | |
1390 * will NOT be invoked in mutual exclusion. This can be useful for | |
1391 * high-performance plugins that must handle concurrent requests | |
1392 * (Orthanc uses a pool of threads, one thread being assigned to | |
1393 * each incoming HTTP request). Of course, it is up to the plugin to | |
1394 * implement the required locking mechanisms. | |
1395 * | |
1396 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1397 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
1398 * @param callback The callback function to handle the REST call. | |
1399 * @see OrthancPluginRegisterRestCallback() | |
1400 * @ingroup Callbacks | |
1401 **/ | |
1402 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock( | |
1403 OrthancPluginContext* context, | |
1404 const char* pathRegularExpression, | |
1405 OrthancPluginRestCallback callback) | |
1406 { | |
1407 _OrthancPluginRestCallback params; | |
1408 params.pathRegularExpression = pathRegularExpression; | |
1409 params.callback = callback; | |
1410 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, ¶ms); | |
1411 } | |
1412 | |
1413 | |
1414 | |
1415 typedef struct | |
1416 { | |
1417 OrthancPluginOnStoredInstanceCallback callback; | |
1418 } _OrthancPluginOnStoredInstanceCallback; | |
1419 | |
1420 /** | |
1421 * @brief Register a callback for received instances. | |
1422 * | |
1423 * This function registers a callback function that is called | |
1424 * whenever a new DICOM instance is stored into the Orthanc core. | |
1425 * | |
1426 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1427 * @param callback The callback function. | |
1428 * @ingroup Callbacks | |
1429 **/ | |
1430 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback( | |
1431 OrthancPluginContext* context, | |
1432 OrthancPluginOnStoredInstanceCallback callback) | |
1433 { | |
1434 _OrthancPluginOnStoredInstanceCallback params; | |
1435 params.callback = callback; | |
1436 | |
1437 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, ¶ms); | |
1438 } | |
1439 | |
1440 | |
1441 | |
1442 typedef struct | |
1443 { | |
1444 OrthancPluginRestOutput* output; | |
1445 const char* answer; | |
1446 uint32_t answerSize; | |
1447 const char* mimeType; | |
1448 } _OrthancPluginAnswerBuffer; | |
1449 | |
1450 /** | |
1451 * @brief Answer to a REST request. | |
1452 * | |
1453 * This function answers to a REST request with the content of a memory buffer. | |
1454 * | |
1455 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1456 * @param output The HTTP connection to the client application. | |
1457 * @param answer Pointer to the memory buffer containing the answer. | |
1458 * @param answerSize Number of bytes of the answer. | |
1459 * @param mimeType The MIME type of the answer. | |
1460 * @ingroup REST | |
1461 **/ | |
1462 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer( | |
1463 OrthancPluginContext* context, | |
1464 OrthancPluginRestOutput* output, | |
1465 const char* answer, | |
1466 uint32_t answerSize, | |
1467 const char* mimeType) | |
1468 { | |
1469 _OrthancPluginAnswerBuffer params; | |
1470 params.output = output; | |
1471 params.answer = answer; | |
1472 params.answerSize = answerSize; | |
1473 params.mimeType = mimeType; | |
1474 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, ¶ms); | |
1475 } | |
1476 | |
1477 | |
1478 typedef struct | |
1479 { | |
1480 OrthancPluginRestOutput* output; | |
1481 OrthancPluginPixelFormat format; | |
1482 uint32_t width; | |
1483 uint32_t height; | |
1484 uint32_t pitch; | |
1485 const void* buffer; | |
1486 } _OrthancPluginCompressAndAnswerPngImage; | |
1487 | |
1488 typedef struct | |
1489 { | |
1490 OrthancPluginRestOutput* output; | |
1491 OrthancPluginImageFormat imageFormat; | |
1492 OrthancPluginPixelFormat pixelFormat; | |
1493 uint32_t width; | |
1494 uint32_t height; | |
1495 uint32_t pitch; | |
1496 const void* buffer; | |
1497 uint8_t quality; | |
1498 } _OrthancPluginCompressAndAnswerImage; | |
1499 | |
1500 | |
1501 /** | |
1502 * @brief Answer to a REST request with a PNG image. | |
1503 * | |
1504 * This function answers to a REST request with a PNG image. The | |
1505 * parameters of this function describe a memory buffer that | |
1506 * contains an uncompressed image. The image will be automatically compressed | |
1507 * as a PNG image by the core system of Orthanc. | |
1508 * | |
1509 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1510 * @param output The HTTP connection to the client application. | |
1511 * @param format The memory layout of the uncompressed image. | |
1512 * @param width The width of the image. | |
1513 * @param height The height of the image. | |
1514 * @param pitch The pitch of the image (i.e. the number of bytes | |
1515 * between 2 successive lines of the image in the memory buffer). | |
1516 * @param buffer The memory buffer containing the uncompressed image. | |
1517 * @ingroup REST | |
1518 **/ | |
1519 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage( | |
1520 OrthancPluginContext* context, | |
1521 OrthancPluginRestOutput* output, | |
1522 OrthancPluginPixelFormat format, | |
1523 uint32_t width, | |
1524 uint32_t height, | |
1525 uint32_t pitch, | |
1526 const void* buffer) | |
1527 { | |
1528 _OrthancPluginCompressAndAnswerImage params; | |
1529 params.output = output; | |
1530 params.imageFormat = OrthancPluginImageFormat_Png; | |
1531 params.pixelFormat = format; | |
1532 params.width = width; | |
1533 params.height = height; | |
1534 params.pitch = pitch; | |
1535 params.buffer = buffer; | |
1536 params.quality = 0; /* No quality for PNG */ | |
1537 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); | |
1538 } | |
1539 | |
1540 | |
1541 | |
1542 typedef struct | |
1543 { | |
1544 OrthancPluginMemoryBuffer* target; | |
1545 const char* instanceId; | |
1546 } _OrthancPluginGetDicomForInstance; | |
1547 | |
1548 /** | |
1549 * @brief Retrieve a DICOM instance using its Orthanc identifier. | |
1550 * | |
1551 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM | |
1552 * file is stored into a newly allocated memory buffer. | |
1553 * | |
1554 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1555 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1556 * @param instanceId The Orthanc identifier of the DICOM instance of interest. | |
1557 * @return 0 if success, or the error code if failure. | |
1558 * @ingroup Orthanc | |
1559 **/ | |
1560 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance( | |
1561 OrthancPluginContext* context, | |
1562 OrthancPluginMemoryBuffer* target, | |
1563 const char* instanceId) | |
1564 { | |
1565 _OrthancPluginGetDicomForInstance params; | |
1566 params.target = target; | |
1567 params.instanceId = instanceId; | |
1568 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, ¶ms); | |
1569 } | |
1570 | |
1571 | |
1572 | |
1573 typedef struct | |
1574 { | |
1575 OrthancPluginMemoryBuffer* target; | |
1576 const char* uri; | |
1577 } _OrthancPluginRestApiGet; | |
1578 | |
1579 /** | |
1580 * @brief Make a GET call to the built-in Orthanc REST API. | |
1581 * | |
1582 * Make a GET call to the built-in Orthanc REST API. The result to | |
1583 * the query is stored into a newly allocated memory buffer. | |
1584 * | |
1585 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1586 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1587 * @param uri The URI in the built-in Orthanc API. | |
1588 * @return 0 if success, or the error code if failure. | |
1589 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1590 * @see OrthancPluginRestApiGetAfterPlugins | |
1591 * @ingroup Orthanc | |
1592 **/ | |
1593 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet( | |
1594 OrthancPluginContext* context, | |
1595 OrthancPluginMemoryBuffer* target, | |
1596 const char* uri) | |
1597 { | |
1598 _OrthancPluginRestApiGet params; | |
1599 params.target = target; | |
1600 params.uri = uri; | |
1601 return context->InvokeService(context, _OrthancPluginService_RestApiGet, ¶ms); | |
1602 } | |
1603 | |
1604 | |
1605 | |
1606 /** | |
1607 * @brief Make a GET call to the REST API, as tainted by the plugins. | |
1608 * | |
1609 * Make a GET call to the Orthanc REST API, after all the plugins | |
1610 * are applied. In other words, if some plugin overrides or adds the | |
1611 * called URI to the built-in Orthanc REST API, this call will | |
1612 * return the result provided by this plugin. The result to the | |
1613 * query is stored into a newly allocated memory buffer. | |
1614 * | |
1615 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1616 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1617 * @param uri The URI in the built-in Orthanc API. | |
1618 * @return 0 if success, or the error code if failure. | |
1619 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1620 * @see OrthancPluginRestApiGet | |
1621 * @ingroup Orthanc | |
1622 **/ | |
1623 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins( | |
1624 OrthancPluginContext* context, | |
1625 OrthancPluginMemoryBuffer* target, | |
1626 const char* uri) | |
1627 { | |
1628 _OrthancPluginRestApiGet params; | |
1629 params.target = target; | |
1630 params.uri = uri; | |
1631 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, ¶ms); | |
1632 } | |
1633 | |
1634 | |
1635 | |
1636 typedef struct | |
1637 { | |
1638 OrthancPluginMemoryBuffer* target; | |
1639 const char* uri; | |
1640 const char* body; | |
1641 uint32_t bodySize; | |
1642 } _OrthancPluginRestApiPostPut; | |
1643 | |
1644 /** | |
1645 * @brief Make a POST call to the built-in Orthanc REST API. | |
1646 * | |
1647 * Make a POST call to the built-in Orthanc REST API. The result to | |
1648 * the query is stored into a newly allocated memory buffer. | |
1649 * | |
1650 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1651 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1652 * @param uri The URI in the built-in Orthanc API. | |
1653 * @param body The body of the POST request. | |
1654 * @param bodySize The size of the body. | |
1655 * @return 0 if success, or the error code if failure. | |
1656 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1657 * @see OrthancPluginRestApiPostAfterPlugins | |
1658 * @ingroup Orthanc | |
1659 **/ | |
1660 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost( | |
1661 OrthancPluginContext* context, | |
1662 OrthancPluginMemoryBuffer* target, | |
1663 const char* uri, | |
1664 const char* body, | |
1665 uint32_t bodySize) | |
1666 { | |
1667 _OrthancPluginRestApiPostPut params; | |
1668 params.target = target; | |
1669 params.uri = uri; | |
1670 params.body = body; | |
1671 params.bodySize = bodySize; | |
1672 return context->InvokeService(context, _OrthancPluginService_RestApiPost, ¶ms); | |
1673 } | |
1674 | |
1675 | |
1676 /** | |
1677 * @brief Make a POST call to the REST API, as tainted by the plugins. | |
1678 * | |
1679 * Make a POST call to the Orthanc REST API, after all the plugins | |
1680 * are applied. In other words, if some plugin overrides or adds the | |
1681 * called URI to the built-in Orthanc REST API, this call will | |
1682 * return the result provided by this plugin. The result to the | |
1683 * query is stored into a newly allocated memory buffer. | |
1684 * | |
1685 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1686 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1687 * @param uri The URI in the built-in Orthanc API. | |
1688 * @param body The body of the POST request. | |
1689 * @param bodySize The size of the body. | |
1690 * @return 0 if success, or the error code if failure. | |
1691 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1692 * @see OrthancPluginRestApiPost | |
1693 * @ingroup Orthanc | |
1694 **/ | |
1695 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins( | |
1696 OrthancPluginContext* context, | |
1697 OrthancPluginMemoryBuffer* target, | |
1698 const char* uri, | |
1699 const char* body, | |
1700 uint32_t bodySize) | |
1701 { | |
1702 _OrthancPluginRestApiPostPut params; | |
1703 params.target = target; | |
1704 params.uri = uri; | |
1705 params.body = body; | |
1706 params.bodySize = bodySize; | |
1707 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, ¶ms); | |
1708 } | |
1709 | |
1710 | |
1711 | |
1712 /** | |
1713 * @brief Make a DELETE call to the built-in Orthanc REST API. | |
1714 * | |
1715 * Make a DELETE call to the built-in Orthanc REST API. | |
1716 * | |
1717 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1718 * @param uri The URI to delete in the built-in Orthanc API. | |
1719 * @return 0 if success, or the error code if failure. | |
1720 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1721 * @see OrthancPluginRestApiDeleteAfterPlugins | |
1722 * @ingroup Orthanc | |
1723 **/ | |
1724 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete( | |
1725 OrthancPluginContext* context, | |
1726 const char* uri) | |
1727 { | |
1728 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri); | |
1729 } | |
1730 | |
1731 | |
1732 /** | |
1733 * @brief Make a DELETE call to the REST API, as tainted by the plugins. | |
1734 * | |
1735 * Make a DELETE call to the Orthanc REST API, after all the plugins | |
1736 * are applied. In other words, if some plugin overrides or adds the | |
1737 * called URI to the built-in Orthanc REST API, this call will | |
1738 * return the result provided by this plugin. | |
1739 * | |
1740 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1741 * @param uri The URI to delete in the built-in Orthanc API. | |
1742 * @return 0 if success, or the error code if failure. | |
1743 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1744 * @see OrthancPluginRestApiDelete | |
1745 * @ingroup Orthanc | |
1746 **/ | |
1747 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins( | |
1748 OrthancPluginContext* context, | |
1749 const char* uri) | |
1750 { | |
1751 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri); | |
1752 } | |
1753 | |
1754 | |
1755 | |
1756 /** | |
1757 * @brief Make a PUT call to the built-in Orthanc REST API. | |
1758 * | |
1759 * Make a PUT call to the built-in Orthanc REST API. The result to | |
1760 * the query is stored into a newly allocated memory buffer. | |
1761 * | |
1762 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1763 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1764 * @param uri The URI in the built-in Orthanc API. | |
1765 * @param body The body of the PUT request. | |
1766 * @param bodySize The size of the body. | |
1767 * @return 0 if success, or the error code if failure. | |
1768 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1769 * @see OrthancPluginRestApiPutAfterPlugins | |
1770 * @ingroup Orthanc | |
1771 **/ | |
1772 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut( | |
1773 OrthancPluginContext* context, | |
1774 OrthancPluginMemoryBuffer* target, | |
1775 const char* uri, | |
1776 const char* body, | |
1777 uint32_t bodySize) | |
1778 { | |
1779 _OrthancPluginRestApiPostPut params; | |
1780 params.target = target; | |
1781 params.uri = uri; | |
1782 params.body = body; | |
1783 params.bodySize = bodySize; | |
1784 return context->InvokeService(context, _OrthancPluginService_RestApiPut, ¶ms); | |
1785 } | |
1786 | |
1787 | |
1788 | |
1789 /** | |
1790 * @brief Make a PUT call to the REST API, as tainted by the plugins. | |
1791 * | |
1792 * Make a PUT call to the Orthanc REST API, after all the plugins | |
1793 * are applied. In other words, if some plugin overrides or adds the | |
1794 * called URI to the built-in Orthanc REST API, this call will | |
1795 * return the result provided by this plugin. The result to the | |
1796 * query is stored into a newly allocated memory buffer. | |
1797 * | |
1798 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1799 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1800 * @param uri The URI in the built-in Orthanc API. | |
1801 * @param body The body of the PUT request. | |
1802 * @param bodySize The size of the body. | |
1803 * @return 0 if success, or the error code if failure. | |
1804 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1805 * @see OrthancPluginRestApiPut | |
1806 * @ingroup Orthanc | |
1807 **/ | |
1808 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins( | |
1809 OrthancPluginContext* context, | |
1810 OrthancPluginMemoryBuffer* target, | |
1811 const char* uri, | |
1812 const char* body, | |
1813 uint32_t bodySize) | |
1814 { | |
1815 _OrthancPluginRestApiPostPut params; | |
1816 params.target = target; | |
1817 params.uri = uri; | |
1818 params.body = body; | |
1819 params.bodySize = bodySize; | |
1820 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, ¶ms); | |
1821 } | |
1822 | |
1823 | |
1824 | |
1825 typedef struct | |
1826 { | |
1827 OrthancPluginRestOutput* output; | |
1828 const char* argument; | |
1829 } _OrthancPluginOutputPlusArgument; | |
1830 | |
1831 /** | |
1832 * @brief Redirect a REST request. | |
1833 * | |
1834 * This function answers to a REST request by redirecting the user | |
1835 * to another URI using HTTP status 301. | |
1836 * | |
1837 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1838 * @param output The HTTP connection to the client application. | |
1839 * @param redirection Where to redirect. | |
1840 * @ingroup REST | |
1841 **/ | |
1842 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect( | |
1843 OrthancPluginContext* context, | |
1844 OrthancPluginRestOutput* output, | |
1845 const char* redirection) | |
1846 { | |
1847 _OrthancPluginOutputPlusArgument params; | |
1848 params.output = output; | |
1849 params.argument = redirection; | |
1850 context->InvokeService(context, _OrthancPluginService_Redirect, ¶ms); | |
1851 } | |
1852 | |
1853 | |
1854 | |
1855 typedef struct | |
1856 { | |
1857 char** result; | |
1858 const char* argument; | |
1859 } _OrthancPluginRetrieveDynamicString; | |
1860 | |
1861 /** | |
1862 * @brief Look for a patient. | |
1863 * | |
1864 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). | |
1865 * This function uses the database index to run as fast as possible (it does not loop | |
1866 * over all the stored patients). | |
1867 * | |
1868 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1869 * @param patientID The Patient ID of interest. | |
1870 * @return The NULL value if the patient is non-existent, or a string containing the | |
1871 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString(). | |
1872 * @ingroup Orthanc | |
1873 **/ | |
1874 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient( | |
1875 OrthancPluginContext* context, | |
1876 const char* patientID) | |
1877 { | |
1878 char* result; | |
1879 | |
1880 _OrthancPluginRetrieveDynamicString params; | |
1881 params.result = &result; | |
1882 params.argument = patientID; | |
1883 | |
1884 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms) != OrthancPluginErrorCode_Success) | |
1885 { | |
1886 /* Error */ | |
1887 return NULL; | |
1888 } | |
1889 else | |
1890 { | |
1891 return result; | |
1892 } | |
1893 } | |
1894 | |
1895 | |
1896 /** | |
1897 * @brief Look for a study. | |
1898 * | |
1899 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). | |
1900 * This function uses the database index to run as fast as possible (it does not loop | |
1901 * over all the stored studies). | |
1902 * | |
1903 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1904 * @param studyUID The Study Instance UID of interest. | |
1905 * @return The NULL value if the study is non-existent, or a string containing the | |
1906 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). | |
1907 * @ingroup Orthanc | |
1908 **/ | |
1909 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy( | |
1910 OrthancPluginContext* context, | |
1911 const char* studyUID) | |
1912 { | |
1913 char* result; | |
1914 | |
1915 _OrthancPluginRetrieveDynamicString params; | |
1916 params.result = &result; | |
1917 params.argument = studyUID; | |
1918 | |
1919 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms) != OrthancPluginErrorCode_Success) | |
1920 { | |
1921 /* Error */ | |
1922 return NULL; | |
1923 } | |
1924 else | |
1925 { | |
1926 return result; | |
1927 } | |
1928 } | |
1929 | |
1930 | |
1931 /** | |
1932 * @brief Look for a study, using the accession number. | |
1933 * | |
1934 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050). | |
1935 * This function uses the database index to run as fast as possible (it does not loop | |
1936 * over all the stored studies). | |
1937 * | |
1938 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1939 * @param accessionNumber The Accession Number of interest. | |
1940 * @return The NULL value if the study is non-existent, or a string containing the | |
1941 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). | |
1942 * @ingroup Orthanc | |
1943 **/ | |
1944 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber( | |
1945 OrthancPluginContext* context, | |
1946 const char* accessionNumber) | |
1947 { | |
1948 char* result; | |
1949 | |
1950 _OrthancPluginRetrieveDynamicString params; | |
1951 params.result = &result; | |
1952 params.argument = accessionNumber; | |
1953 | |
1954 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, ¶ms) != OrthancPluginErrorCode_Success) | |
1955 { | |
1956 /* Error */ | |
1957 return NULL; | |
1958 } | |
1959 else | |
1960 { | |
1961 return result; | |
1962 } | |
1963 } | |
1964 | |
1965 | |
1966 /** | |
1967 * @brief Look for a series. | |
1968 * | |
1969 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). | |
1970 * This function uses the database index to run as fast as possible (it does not loop | |
1971 * over all the stored series). | |
1972 * | |
1973 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1974 * @param seriesUID The Series Instance UID of interest. | |
1975 * @return The NULL value if the series is non-existent, or a string containing the | |
1976 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString(). | |
1977 * @ingroup Orthanc | |
1978 **/ | |
1979 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries( | |
1980 OrthancPluginContext* context, | |
1981 const char* seriesUID) | |
1982 { | |
1983 char* result; | |
1984 | |
1985 _OrthancPluginRetrieveDynamicString params; | |
1986 params.result = &result; | |
1987 params.argument = seriesUID; | |
1988 | |
1989 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms) != OrthancPluginErrorCode_Success) | |
1990 { | |
1991 /* Error */ | |
1992 return NULL; | |
1993 } | |
1994 else | |
1995 { | |
1996 return result; | |
1997 } | |
1998 } | |
1999 | |
2000 | |
2001 /** | |
2002 * @brief Look for an instance. | |
2003 * | |
2004 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). | |
2005 * This function uses the database index to run as fast as possible (it does not loop | |
2006 * over all the stored instances). | |
2007 * | |
2008 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2009 * @param sopInstanceUID The SOP Instance UID of interest. | |
2010 * @return The NULL value if the instance is non-existent, or a string containing the | |
2011 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString(). | |
2012 * @ingroup Orthanc | |
2013 **/ | |
2014 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance( | |
2015 OrthancPluginContext* context, | |
2016 const char* sopInstanceUID) | |
2017 { | |
2018 char* result; | |
2019 | |
2020 _OrthancPluginRetrieveDynamicString params; | |
2021 params.result = &result; | |
2022 params.argument = sopInstanceUID; | |
2023 | |
2024 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms) != OrthancPluginErrorCode_Success) | |
2025 { | |
2026 /* Error */ | |
2027 return NULL; | |
2028 } | |
2029 else | |
2030 { | |
2031 return result; | |
2032 } | |
2033 } | |
2034 | |
2035 | |
2036 | |
2037 typedef struct | |
2038 { | |
2039 OrthancPluginRestOutput* output; | |
2040 uint16_t status; | |
2041 } _OrthancPluginSendHttpStatusCode; | |
2042 | |
2043 /** | |
2044 * @brief Send a HTTP status code. | |
2045 * | |
2046 * This function answers to a REST request by sending a HTTP status | |
2047 * code (such as "400 - Bad Request"). Note that: | |
2048 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). | |
2049 * - Redirections (status 301) must use ::OrthancPluginRedirect(). | |
2050 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). | |
2051 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). | |
2052 * | |
2053 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2054 * @param output The HTTP connection to the client application. | |
2055 * @param status The HTTP status code to be sent. | |
2056 * @ingroup REST | |
2057 * @see OrthancPluginSendHttpStatus() | |
2058 **/ | |
2059 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode( | |
2060 OrthancPluginContext* context, | |
2061 OrthancPluginRestOutput* output, | |
2062 uint16_t status) | |
2063 { | |
2064 _OrthancPluginSendHttpStatusCode params; | |
2065 params.output = output; | |
2066 params.status = status; | |
2067 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, ¶ms); | |
2068 } | |
2069 | |
2070 | |
2071 /** | |
2072 * @brief Signal that a REST request is not authorized. | |
2073 * | |
2074 * This function answers to a REST request by signaling that it is | |
2075 * not authorized. | |
2076 * | |
2077 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2078 * @param output The HTTP connection to the client application. | |
2079 * @param realm The realm for the authorization process. | |
2080 * @ingroup REST | |
2081 **/ | |
2082 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized( | |
2083 OrthancPluginContext* context, | |
2084 OrthancPluginRestOutput* output, | |
2085 const char* realm) | |
2086 { | |
2087 _OrthancPluginOutputPlusArgument params; | |
2088 params.output = output; | |
2089 params.argument = realm; | |
2090 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, ¶ms); | |
2091 } | |
2092 | |
2093 | |
2094 /** | |
2095 * @brief Signal that this URI does not support this HTTP method. | |
2096 * | |
2097 * This function answers to a REST request by signaling that the | |
2098 * queried URI does not support this method. | |
2099 * | |
2100 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2101 * @param output The HTTP connection to the client application. | |
2102 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request). | |
2103 * @ingroup REST | |
2104 **/ | |
2105 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed( | |
2106 OrthancPluginContext* context, | |
2107 OrthancPluginRestOutput* output, | |
2108 const char* allowedMethods) | |
2109 { | |
2110 _OrthancPluginOutputPlusArgument params; | |
2111 params.output = output; | |
2112 params.argument = allowedMethods; | |
2113 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, ¶ms); | |
2114 } | |
2115 | |
2116 | |
2117 typedef struct | |
2118 { | |
2119 OrthancPluginRestOutput* output; | |
2120 const char* key; | |
2121 const char* value; | |
2122 } _OrthancPluginSetHttpHeader; | |
2123 | |
2124 /** | |
2125 * @brief Set a cookie. | |
2126 * | |
2127 * This function sets a cookie in the HTTP client. | |
2128 * | |
2129 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2130 * @param output The HTTP connection to the client application. | |
2131 * @param cookie The cookie to be set. | |
2132 * @param value The value of the cookie. | |
2133 * @ingroup REST | |
2134 **/ | |
2135 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie( | |
2136 OrthancPluginContext* context, | |
2137 OrthancPluginRestOutput* output, | |
2138 const char* cookie, | |
2139 const char* value) | |
2140 { | |
2141 _OrthancPluginSetHttpHeader params; | |
2142 params.output = output; | |
2143 params.key = cookie; | |
2144 params.value = value; | |
2145 context->InvokeService(context, _OrthancPluginService_SetCookie, ¶ms); | |
2146 } | |
2147 | |
2148 | |
2149 /** | |
2150 * @brief Set some HTTP header. | |
2151 * | |
2152 * This function sets a HTTP header in the HTTP answer. | |
2153 * | |
2154 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2155 * @param output The HTTP connection to the client application. | |
2156 * @param key The HTTP header to be set. | |
2157 * @param value The value of the HTTP header. | |
2158 * @ingroup REST | |
2159 **/ | |
2160 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader( | |
2161 OrthancPluginContext* context, | |
2162 OrthancPluginRestOutput* output, | |
2163 const char* key, | |
2164 const char* value) | |
2165 { | |
2166 _OrthancPluginSetHttpHeader params; | |
2167 params.output = output; | |
2168 params.key = key; | |
2169 params.value = value; | |
2170 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, ¶ms); | |
2171 } | |
2172 | |
2173 | |
2174 typedef struct | |
2175 { | |
2176 char** resultStringToFree; | |
2177 const char** resultString; | |
2178 int64_t* resultInt64; | |
2179 const char* key; | |
2180 OrthancPluginDicomInstance* instance; | |
2181 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */ | |
2182 } _OrthancPluginAccessDicomInstance; | |
2183 | |
2184 | |
2185 /** | |
2186 * @brief Get the AET of a DICOM instance. | |
2187 * | |
2188 * This function returns the Application Entity Title (AET) of the | |
2189 * DICOM modality from which a DICOM instance originates. | |
2190 * | |
2191 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2192 * @param instance The instance of interest. | |
2193 * @return The AET if success, NULL if error. | |
2194 * @ingroup Callbacks | |
2195 **/ | |
2196 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet( | |
2197 OrthancPluginContext* context, | |
2198 OrthancPluginDicomInstance* instance) | |
2199 { | |
2200 const char* result; | |
2201 | |
2202 _OrthancPluginAccessDicomInstance params; | |
2203 memset(¶ms, 0, sizeof(params)); | |
2204 params.resultString = &result; | |
2205 params.instance = instance; | |
2206 | |
2207 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms) != OrthancPluginErrorCode_Success) | |
2208 { | |
2209 /* Error */ | |
2210 return NULL; | |
2211 } | |
2212 else | |
2213 { | |
2214 return result; | |
2215 } | |
2216 } | |
2217 | |
2218 | |
2219 /** | |
2220 * @brief Get the size of a DICOM file. | |
2221 * | |
2222 * This function returns the number of bytes of the given DICOM instance. | |
2223 * | |
2224 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2225 * @param instance The instance of interest. | |
2226 * @return The size of the file, -1 in case of error. | |
2227 * @ingroup Callbacks | |
2228 **/ | |
2229 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize( | |
2230 OrthancPluginContext* context, | |
2231 OrthancPluginDicomInstance* instance) | |
2232 { | |
2233 int64_t size; | |
2234 | |
2235 _OrthancPluginAccessDicomInstance params; | |
2236 memset(¶ms, 0, sizeof(params)); | |
2237 params.resultInt64 = &size; | |
2238 params.instance = instance; | |
2239 | |
2240 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms) != OrthancPluginErrorCode_Success) | |
2241 { | |
2242 /* Error */ | |
2243 return -1; | |
2244 } | |
2245 else | |
2246 { | |
2247 return size; | |
2248 } | |
2249 } | |
2250 | |
2251 | |
2252 /** | |
2253 * @brief Get the data of a DICOM file. | |
2254 * | |
2255 * This function returns a pointer to the content of the given DICOM instance. | |
2256 * | |
2257 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2258 * @param instance The instance of interest. | |
2259 * @return The pointer to the DICOM data, NULL in case of error. | |
2260 * @ingroup Callbacks | |
2261 **/ | |
2262 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData( | |
2263 OrthancPluginContext* context, | |
2264 OrthancPluginDicomInstance* instance) | |
2265 { | |
2266 const char* result; | |
2267 | |
2268 _OrthancPluginAccessDicomInstance params; | |
2269 memset(¶ms, 0, sizeof(params)); | |
2270 params.resultString = &result; | |
2271 params.instance = instance; | |
2272 | |
2273 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms) != OrthancPluginErrorCode_Success) | |
2274 { | |
2275 /* Error */ | |
2276 return NULL; | |
2277 } | |
2278 else | |
2279 { | |
2280 return result; | |
2281 } | |
2282 } | |
2283 | |
2284 | |
2285 /** | |
2286 * @brief Get the DICOM tag hierarchy as a JSON file. | |
2287 * | |
2288 * This function returns a pointer to a newly created string | |
2289 * containing a JSON file. This JSON file encodes the tag hierarchy | |
2290 * of the given DICOM instance. | |
2291 * | |
2292 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2293 * @param instance The instance of interest. | |
2294 * @return The NULL value in case of error, or a string containing the JSON file. | |
2295 * This string must be freed by OrthancPluginFreeString(). | |
2296 * @ingroup Callbacks | |
2297 **/ | |
2298 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson( | |
2299 OrthancPluginContext* context, | |
2300 OrthancPluginDicomInstance* instance) | |
2301 { | |
2302 char* result; | |
2303 | |
2304 _OrthancPluginAccessDicomInstance params; | |
2305 memset(¶ms, 0, sizeof(params)); | |
2306 params.resultStringToFree = &result; | |
2307 params.instance = instance; | |
2308 | |
2309 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms) != OrthancPluginErrorCode_Success) | |
2310 { | |
2311 /* Error */ | |
2312 return NULL; | |
2313 } | |
2314 else | |
2315 { | |
2316 return result; | |
2317 } | |
2318 } | |
2319 | |
2320 | |
2321 /** | |
2322 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification). | |
2323 * | |
2324 * This function returns a pointer to a newly created string | |
2325 * containing a JSON file. This JSON file encodes the tag hierarchy | |
2326 * of the given DICOM instance. In contrast with | |
2327 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in | |
2328 * its simplified version. | |
2329 * | |
2330 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2331 * @param instance The instance of interest. | |
2332 * @return The NULL value in case of error, or a string containing the JSON file. | |
2333 * This string must be freed by OrthancPluginFreeString(). | |
2334 * @ingroup Callbacks | |
2335 **/ | |
2336 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson( | |
2337 OrthancPluginContext* context, | |
2338 OrthancPluginDicomInstance* instance) | |
2339 { | |
2340 char* result; | |
2341 | |
2342 _OrthancPluginAccessDicomInstance params; | |
2343 memset(¶ms, 0, sizeof(params)); | |
2344 params.resultStringToFree = &result; | |
2345 params.instance = instance; | |
2346 | |
2347 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms) != OrthancPluginErrorCode_Success) | |
2348 { | |
2349 /* Error */ | |
2350 return NULL; | |
2351 } | |
2352 else | |
2353 { | |
2354 return result; | |
2355 } | |
2356 } | |
2357 | |
2358 | |
2359 /** | |
2360 * @brief Check whether a DICOM instance is associated with some metadata. | |
2361 * | |
2362 * This function checks whether the DICOM instance of interest is | |
2363 * associated with some metadata. As of Orthanc 0.8.1, in the | |
2364 * callbacks registered by | |
2365 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only | |
2366 * possibly available metadata are "ReceptionDate", "RemoteAET" and | |
2367 * "IndexInSeries". | |
2368 * | |
2369 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2370 * @param instance The instance of interest. | |
2371 * @param metadata The metadata of interest. | |
2372 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error. | |
2373 * @ingroup Callbacks | |
2374 **/ | |
2375 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata( | |
2376 OrthancPluginContext* context, | |
2377 OrthancPluginDicomInstance* instance, | |
2378 const char* metadata) | |
2379 { | |
2380 int64_t result; | |
2381 | |
2382 _OrthancPluginAccessDicomInstance params; | |
2383 memset(¶ms, 0, sizeof(params)); | |
2384 params.resultInt64 = &result; | |
2385 params.instance = instance; | |
2386 params.key = metadata; | |
2387 | |
2388 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) | |
2389 { | |
2390 /* Error */ | |
2391 return -1; | |
2392 } | |
2393 else | |
2394 { | |
2395 return (result != 0); | |
2396 } | |
2397 } | |
2398 | |
2399 | |
2400 /** | |
2401 * @brief Get the value of some metadata associated with a given DICOM instance. | |
2402 * | |
2403 * This functions returns the value of some metadata that is associated with the DICOM instance of interest. | |
2404 * Before calling this function, the existence of the metadata must have been checked with | |
2405 * ::OrthancPluginHasInstanceMetadata(). | |
2406 * | |
2407 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2408 * @param instance The instance of interest. | |
2409 * @param metadata The metadata of interest. | |
2410 * @return The metadata value if success, NULL if error. | |
2411 * @ingroup Callbacks | |
2412 **/ | |
2413 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata( | |
2414 OrthancPluginContext* context, | |
2415 OrthancPluginDicomInstance* instance, | |
2416 const char* metadata) | |
2417 { | |
2418 const char* result; | |
2419 | |
2420 _OrthancPluginAccessDicomInstance params; | |
2421 memset(¶ms, 0, sizeof(params)); | |
2422 params.resultString = &result; | |
2423 params.instance = instance; | |
2424 params.key = metadata; | |
2425 | |
2426 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) | |
2427 { | |
2428 /* Error */ | |
2429 return NULL; | |
2430 } | |
2431 else | |
2432 { | |
2433 return result; | |
2434 } | |
2435 } | |
2436 | |
2437 | |
2438 | |
2439 typedef struct | |
2440 { | |
2441 OrthancPluginStorageCreate create; | |
2442 OrthancPluginStorageRead read; | |
2443 OrthancPluginStorageRemove remove; | |
2444 OrthancPluginFree free; | |
2445 } _OrthancPluginRegisterStorageArea; | |
2446 | |
2447 /** | |
2448 * @brief Register a custom storage area. | |
2449 * | |
2450 * This function registers a custom storage area, to replace the | |
2451 * built-in way Orthanc stores its files on the filesystem. This | |
2452 * function must be called during the initialization of the plugin, | |
2453 * i.e. inside the OrthancPluginInitialize() public function. | |
2454 * | |
2455 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2456 * @param create The callback function to store a file on the custom storage area. | |
2457 * @param read The callback function to read a file from the custom storage area. | |
2458 * @param remove The callback function to remove a file from the custom storage area. | |
2459 * @ingroup Callbacks | |
2460 **/ | |
2461 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea( | |
2462 OrthancPluginContext* context, | |
2463 OrthancPluginStorageCreate create, | |
2464 OrthancPluginStorageRead read, | |
2465 OrthancPluginStorageRemove remove) | |
2466 { | |
2467 _OrthancPluginRegisterStorageArea params; | |
2468 params.create = create; | |
2469 params.read = read; | |
2470 params.remove = remove; | |
2471 | |
2472 #ifdef __cplusplus | |
2473 params.free = ::free; | |
2474 #else | |
2475 params.free = free; | |
2476 #endif | |
2477 | |
2478 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, ¶ms); | |
2479 } | |
2480 | |
2481 | |
2482 | |
2483 /** | |
2484 * @brief Return the path to the Orthanc executable. | |
2485 * | |
2486 * This function returns the path to the Orthanc executable. | |
2487 * | |
2488 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2489 * @return NULL in the case of an error, or a newly allocated string | |
2490 * containing the path. This string must be freed by | |
2491 * OrthancPluginFreeString(). | |
2492 **/ | |
2493 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context) | |
2494 { | |
2495 char* result; | |
2496 | |
2497 _OrthancPluginRetrieveDynamicString params; | |
2498 params.result = &result; | |
2499 params.argument = NULL; | |
2500 | |
2501 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, ¶ms) != OrthancPluginErrorCode_Success) | |
2502 { | |
2503 /* Error */ | |
2504 return NULL; | |
2505 } | |
2506 else | |
2507 { | |
2508 return result; | |
2509 } | |
2510 } | |
2511 | |
2512 | |
2513 /** | |
2514 * @brief Return the directory containing the Orthanc. | |
2515 * | |
2516 * This function returns the path to the directory containing the Orthanc executable. | |
2517 * | |
2518 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2519 * @return NULL in the case of an error, or a newly allocated string | |
2520 * containing the path. This string must be freed by | |
2521 * OrthancPluginFreeString(). | |
2522 **/ | |
2523 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context) | |
2524 { | |
2525 char* result; | |
2526 | |
2527 _OrthancPluginRetrieveDynamicString params; | |
2528 params.result = &result; | |
2529 params.argument = NULL; | |
2530 | |
2531 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, ¶ms) != OrthancPluginErrorCode_Success) | |
2532 { | |
2533 /* Error */ | |
2534 return NULL; | |
2535 } | |
2536 else | |
2537 { | |
2538 return result; | |
2539 } | |
2540 } | |
2541 | |
2542 | |
2543 /** | |
2544 * @brief Return the path to the configuration file(s). | |
2545 * | |
2546 * This function returns the path to the configuration file(s) that | |
2547 * was specified when starting Orthanc. Since version 0.9.1, this | |
2548 * path can refer to a folder that stores a set of configuration | |
2549 * files. This function is deprecated in favor of | |
2550 * OrthancPluginGetConfiguration(). | |
2551 * | |
2552 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2553 * @return NULL in the case of an error, or a newly allocated string | |
2554 * containing the path. This string must be freed by | |
2555 * OrthancPluginFreeString(). | |
2556 * @see OrthancPluginGetConfiguration() | |
2557 **/ | |
2558 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context) | |
2559 { | |
2560 char* result; | |
2561 | |
2562 _OrthancPluginRetrieveDynamicString params; | |
2563 params.result = &result; | |
2564 params.argument = NULL; | |
2565 | |
2566 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, ¶ms) != OrthancPluginErrorCode_Success) | |
2567 { | |
2568 /* Error */ | |
2569 return NULL; | |
2570 } | |
2571 else | |
2572 { | |
2573 return result; | |
2574 } | |
2575 } | |
2576 | |
2577 | |
2578 | |
2579 typedef struct | |
2580 { | |
2581 OrthancPluginOnChangeCallback callback; | |
2582 } _OrthancPluginOnChangeCallback; | |
2583 | |
2584 /** | |
2585 * @brief Register a callback to monitor changes. | |
2586 * | |
2587 * This function registers a callback function that is called | |
2588 * whenever a change happens to some DICOM resource. | |
2589 * | |
2590 * @warning If your change callback has to call the REST API of | |
2591 * Orthanc, you should make these calls in a separate thread (with | |
2592 * the events passing through a message queue). Otherwise, this | |
2593 * could result in deadlocks in the presence of other plugins or Lua | |
2594 * scripts. | |
2595 * | |
2596 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2597 * @param callback The callback function. | |
2598 * @ingroup Callbacks | |
2599 **/ | |
2600 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback( | |
2601 OrthancPluginContext* context, | |
2602 OrthancPluginOnChangeCallback callback) | |
2603 { | |
2604 _OrthancPluginOnChangeCallback params; | |
2605 params.callback = callback; | |
2606 | |
2607 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, ¶ms); | |
2608 } | |
2609 | |
2610 | |
2611 | |
2612 typedef struct | |
2613 { | |
2614 const char* plugin; | |
2615 _OrthancPluginProperty property; | |
2616 const char* value; | |
2617 } _OrthancPluginSetPluginProperty; | |
2618 | |
2619 | |
2620 /** | |
2621 * @brief Set the URI where the plugin provides its Web interface. | |
2622 * | |
2623 * For plugins that come with a Web interface, this function | |
2624 * declares the entry path where to find this interface. This | |
2625 * information is notably used in the "Plugins" page of Orthanc | |
2626 * Explorer. | |
2627 * | |
2628 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2629 * @param uri The root URI for this plugin. | |
2630 **/ | |
2631 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri( | |
2632 OrthancPluginContext* context, | |
2633 const char* uri) | |
2634 { | |
2635 _OrthancPluginSetPluginProperty params; | |
2636 params.plugin = OrthancPluginGetName(); | |
2637 params.property = _OrthancPluginProperty_RootUri; | |
2638 params.value = uri; | |
2639 | |
2640 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
2641 } | |
2642 | |
2643 | |
2644 /** | |
2645 * @brief Set a description for this plugin. | |
2646 * | |
2647 * Set a description for this plugin. It is displayed in the | |
2648 * "Plugins" page of Orthanc Explorer. | |
2649 * | |
2650 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2651 * @param description The description. | |
2652 **/ | |
2653 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription( | |
2654 OrthancPluginContext* context, | |
2655 const char* description) | |
2656 { | |
2657 _OrthancPluginSetPluginProperty params; | |
2658 params.plugin = OrthancPluginGetName(); | |
2659 params.property = _OrthancPluginProperty_Description; | |
2660 params.value = description; | |
2661 | |
2662 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
2663 } | |
2664 | |
2665 | |
2666 /** | |
2667 * @brief Extend the JavaScript code of Orthanc Explorer. | |
2668 * | |
2669 * Add JavaScript code to customize the default behavior of Orthanc | |
2670 * Explorer. This can for instance be used to add new buttons. | |
2671 * | |
2672 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2673 * @param javascript The custom JavaScript code. | |
2674 **/ | |
2675 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer( | |
2676 OrthancPluginContext* context, | |
2677 const char* javascript) | |
2678 { | |
2679 _OrthancPluginSetPluginProperty params; | |
2680 params.plugin = OrthancPluginGetName(); | |
2681 params.property = _OrthancPluginProperty_OrthancExplorer; | |
2682 params.value = javascript; | |
2683 | |
2684 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
2685 } | |
2686 | |
2687 | |
2688 typedef struct | |
2689 { | |
2690 char** result; | |
2691 int32_t property; | |
2692 const char* value; | |
2693 } _OrthancPluginGlobalProperty; | |
2694 | |
2695 | |
2696 /** | |
2697 * @brief Get the value of a global property. | |
2698 * | |
2699 * Get the value of a global property that is stored in the Orthanc database. Global | |
2700 * properties whose index is below 1024 are reserved by Orthanc. | |
2701 * | |
2702 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2703 * @param property The global property of interest. | |
2704 * @param defaultValue The value to return, if the global property is unset. | |
2705 * @return The value of the global property, or NULL in the case of an error. This | |
2706 * string must be freed by OrthancPluginFreeString(). | |
2707 * @ingroup Orthanc | |
2708 **/ | |
2709 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty( | |
2710 OrthancPluginContext* context, | |
2711 int32_t property, | |
2712 const char* defaultValue) | |
2713 { | |
2714 char* result; | |
2715 | |
2716 _OrthancPluginGlobalProperty params; | |
2717 params.result = &result; | |
2718 params.property = property; | |
2719 params.value = defaultValue; | |
2720 | |
2721 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, ¶ms) != OrthancPluginErrorCode_Success) | |
2722 { | |
2723 /* Error */ | |
2724 return NULL; | |
2725 } | |
2726 else | |
2727 { | |
2728 return result; | |
2729 } | |
2730 } | |
2731 | |
2732 | |
2733 /** | |
2734 * @brief Set the value of a global property. | |
2735 * | |
2736 * Set the value of a global property into the Orthanc | |
2737 * database. Setting a global property can be used by plugins to | |
2738 * save their internal parameters. Plugins are only allowed to set | |
2739 * properties whose index are above or equal to 1024 (properties | |
2740 * below 1024 are read-only and reserved by Orthanc). | |
2741 * | |
2742 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2743 * @param property The global property of interest. | |
2744 * @param value The value to be set in the global property. | |
2745 * @return 0 if success, or the error code if failure. | |
2746 * @ingroup Orthanc | |
2747 **/ | |
2748 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty( | |
2749 OrthancPluginContext* context, | |
2750 int32_t property, | |
2751 const char* value) | |
2752 { | |
2753 _OrthancPluginGlobalProperty params; | |
2754 params.result = NULL; | |
2755 params.property = property; | |
2756 params.value = value; | |
2757 | |
2758 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, ¶ms); | |
2759 } | |
2760 | |
2761 | |
2762 | |
2763 typedef struct | |
2764 { | |
2765 int32_t *resultInt32; | |
2766 uint32_t *resultUint32; | |
2767 int64_t *resultInt64; | |
2768 uint64_t *resultUint64; | |
2769 } _OrthancPluginReturnSingleValue; | |
2770 | |
2771 /** | |
2772 * @brief Get the number of command-line arguments. | |
2773 * | |
2774 * Retrieve the number of command-line arguments that were used to launch Orthanc. | |
2775 * | |
2776 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2777 * @return The number of arguments. | |
2778 **/ | |
2779 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount( | |
2780 OrthancPluginContext* context) | |
2781 { | |
2782 uint32_t count = 0; | |
2783 | |
2784 _OrthancPluginReturnSingleValue params; | |
2785 memset(¶ms, 0, sizeof(params)); | |
2786 params.resultUint32 = &count; | |
2787 | |
2788 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, ¶ms) != OrthancPluginErrorCode_Success) | |
2789 { | |
2790 /* Error */ | |
2791 return 0; | |
2792 } | |
2793 else | |
2794 { | |
2795 return count; | |
2796 } | |
2797 } | |
2798 | |
2799 | |
2800 | |
2801 /** | |
2802 * @brief Get the value of a command-line argument. | |
2803 * | |
2804 * Get the value of one of the command-line arguments that were used | |
2805 * to launch Orthanc. The number of available arguments can be | |
2806 * retrieved by OrthancPluginGetCommandLineArgumentsCount(). | |
2807 * | |
2808 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2809 * @param argument The index of the argument. | |
2810 * @return The value of the argument, or NULL in the case of an error. This | |
2811 * string must be freed by OrthancPluginFreeString(). | |
2812 **/ | |
2813 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument( | |
2814 OrthancPluginContext* context, | |
2815 uint32_t argument) | |
2816 { | |
2817 char* result; | |
2818 | |
2819 _OrthancPluginGlobalProperty params; | |
2820 params.result = &result; | |
2821 params.property = (int32_t) argument; | |
2822 params.value = NULL; | |
2823 | |
2824 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, ¶ms) != OrthancPluginErrorCode_Success) | |
2825 { | |
2826 /* Error */ | |
2827 return NULL; | |
2828 } | |
2829 else | |
2830 { | |
2831 return result; | |
2832 } | |
2833 } | |
2834 | |
2835 | |
2836 /** | |
2837 * @brief Get the expected version of the database schema. | |
2838 * | |
2839 * Retrieve the expected version of the database schema. | |
2840 * | |
2841 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2842 * @return The version. | |
2843 * @ingroup Callbacks | |
2844 * @deprecated Please instead use IDatabaseBackend::UpgradeDatabase() | |
2845 **/ | |
2846 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion( | |
2847 OrthancPluginContext* context) | |
2848 { | |
2849 uint32_t count = 0; | |
2850 | |
2851 _OrthancPluginReturnSingleValue params; | |
2852 memset(¶ms, 0, sizeof(params)); | |
2853 params.resultUint32 = &count; | |
2854 | |
2855 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, ¶ms) != OrthancPluginErrorCode_Success) | |
2856 { | |
2857 /* Error */ | |
2858 return 0; | |
2859 } | |
2860 else | |
2861 { | |
2862 return count; | |
2863 } | |
2864 } | |
2865 | |
2866 | |
2867 | |
2868 /** | |
2869 * @brief Return the content of the configuration file(s). | |
2870 * | |
2871 * This function returns the content of the configuration that is | |
2872 * used by Orthanc, formatted as a JSON string. | |
2873 * | |
2874 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2875 * @return NULL in the case of an error, or a newly allocated string | |
2876 * containing the configuration. This string must be freed by | |
2877 * OrthancPluginFreeString(). | |
2878 **/ | |
2879 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context) | |
2880 { | |
2881 char* result; | |
2882 | |
2883 _OrthancPluginRetrieveDynamicString params; | |
2884 params.result = &result; | |
2885 params.argument = NULL; | |
2886 | |
2887 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, ¶ms) != OrthancPluginErrorCode_Success) | |
2888 { | |
2889 /* Error */ | |
2890 return NULL; | |
2891 } | |
2892 else | |
2893 { | |
2894 return result; | |
2895 } | |
2896 } | |
2897 | |
2898 | |
2899 | |
2900 typedef struct | |
2901 { | |
2902 OrthancPluginRestOutput* output; | |
2903 const char* subType; | |
2904 const char* contentType; | |
2905 } _OrthancPluginStartMultipartAnswer; | |
2906 | |
2907 /** | |
2908 * @brief Start an HTTP multipart answer. | |
2909 * | |
2910 * Initiates a HTTP multipart answer, as the result of a REST request. | |
2911 * | |
2912 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2913 * @param output The HTTP connection to the client application. | |
2914 * @param subType The sub-type of the multipart answer ("mixed" or "related"). | |
2915 * @param contentType The MIME type of the items in the multipart answer. | |
2916 * @return 0 if success, or the error code if failure. | |
2917 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2() | |
2918 * @ingroup REST | |
2919 **/ | |
2920 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer( | |
2921 OrthancPluginContext* context, | |
2922 OrthancPluginRestOutput* output, | |
2923 const char* subType, | |
2924 const char* contentType) | |
2925 { | |
2926 _OrthancPluginStartMultipartAnswer params; | |
2927 params.output = output; | |
2928 params.subType = subType; | |
2929 params.contentType = contentType; | |
2930 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, ¶ms); | |
2931 } | |
2932 | |
2933 | |
2934 /** | |
2935 * @brief Send an item as a part of some HTTP multipart answer. | |
2936 * | |
2937 * This function sends an item as a part of some HTTP multipart | |
2938 * answer that was initiated by OrthancPluginStartMultipartAnswer(). | |
2939 * | |
2940 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2941 * @param output The HTTP connection to the client application. | |
2942 * @param answer Pointer to the memory buffer containing the item. | |
2943 * @param answerSize Number of bytes of the item. | |
2944 * @return 0 if success, or the error code if failure (this notably happens | |
2945 * if the connection is closed by the client). | |
2946 * @see OrthancPluginSendMultipartItem2() | |
2947 * @ingroup REST | |
2948 **/ | |
2949 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem( | |
2950 OrthancPluginContext* context, | |
2951 OrthancPluginRestOutput* output, | |
2952 const char* answer, | |
2953 uint32_t answerSize) | |
2954 { | |
2955 _OrthancPluginAnswerBuffer params; | |
2956 params.output = output; | |
2957 params.answer = answer; | |
2958 params.answerSize = answerSize; | |
2959 params.mimeType = NULL; | |
2960 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, ¶ms); | |
2961 } | |
2962 | |
2963 | |
2964 | |
2965 typedef struct | |
2966 { | |
2967 OrthancPluginMemoryBuffer* target; | |
2968 const void* source; | |
2969 uint32_t size; | |
2970 OrthancPluginCompressionType compression; | |
2971 uint8_t uncompress; | |
2972 } _OrthancPluginBufferCompression; | |
2973 | |
2974 | |
2975 /** | |
2976 * @brief Compress or decompress a buffer. | |
2977 * | |
2978 * This function compresses or decompresses a buffer, using the | |
2979 * version of the zlib library that is used by the Orthanc core. | |
2980 * | |
2981 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2982 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2983 * @param source The source buffer. | |
2984 * @param size The size in bytes of the source buffer. | |
2985 * @param compression The compression algorithm. | |
2986 * @param uncompress If set to "0", the buffer must be compressed. | |
2987 * If set to "1", the buffer must be uncompressed. | |
2988 * @return 0 if success, or the error code if failure. | |
2989 * @ingroup Images | |
2990 **/ | |
2991 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression( | |
2992 OrthancPluginContext* context, | |
2993 OrthancPluginMemoryBuffer* target, | |
2994 const void* source, | |
2995 uint32_t size, | |
2996 OrthancPluginCompressionType compression, | |
2997 uint8_t uncompress) | |
2998 { | |
2999 _OrthancPluginBufferCompression params; | |
3000 params.target = target; | |
3001 params.source = source; | |
3002 params.size = size; | |
3003 params.compression = compression; | |
3004 params.uncompress = uncompress; | |
3005 | |
3006 return context->InvokeService(context, _OrthancPluginService_BufferCompression, ¶ms); | |
3007 } | |
3008 | |
3009 | |
3010 | |
3011 typedef struct | |
3012 { | |
3013 OrthancPluginMemoryBuffer* target; | |
3014 const char* path; | |
3015 } _OrthancPluginReadFile; | |
3016 | |
3017 /** | |
3018 * @brief Read a file. | |
3019 * | |
3020 * Read the content of a file on the filesystem, and returns it into | |
3021 * a newly allocated memory buffer. | |
3022 * | |
3023 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3024 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3025 * @param path The path of the file to be read. | |
3026 * @return 0 if success, or the error code if failure. | |
3027 **/ | |
3028 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile( | |
3029 OrthancPluginContext* context, | |
3030 OrthancPluginMemoryBuffer* target, | |
3031 const char* path) | |
3032 { | |
3033 _OrthancPluginReadFile params; | |
3034 params.target = target; | |
3035 params.path = path; | |
3036 return context->InvokeService(context, _OrthancPluginService_ReadFile, ¶ms); | |
3037 } | |
3038 | |
3039 | |
3040 | |
3041 typedef struct | |
3042 { | |
3043 const char* path; | |
3044 const void* data; | |
3045 uint32_t size; | |
3046 } _OrthancPluginWriteFile; | |
3047 | |
3048 /** | |
3049 * @brief Write a file. | |
3050 * | |
3051 * Write the content of a memory buffer to the filesystem. | |
3052 * | |
3053 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3054 * @param path The path of the file to be written. | |
3055 * @param data The content of the memory buffer. | |
3056 * @param size The size of the memory buffer. | |
3057 * @return 0 if success, or the error code if failure. | |
3058 **/ | |
3059 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile( | |
3060 OrthancPluginContext* context, | |
3061 const char* path, | |
3062 const void* data, | |
3063 uint32_t size) | |
3064 { | |
3065 _OrthancPluginWriteFile params; | |
3066 params.path = path; | |
3067 params.data = data; | |
3068 params.size = size; | |
3069 return context->InvokeService(context, _OrthancPluginService_WriteFile, ¶ms); | |
3070 } | |
3071 | |
3072 | |
3073 | |
3074 typedef struct | |
3075 { | |
3076 const char** target; | |
3077 OrthancPluginErrorCode error; | |
3078 } _OrthancPluginGetErrorDescription; | |
3079 | |
3080 /** | |
3081 * @brief Get the description of a given error code. | |
3082 * | |
3083 * This function returns the description of a given error code. | |
3084 * | |
3085 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3086 * @param error The error code of interest. | |
3087 * @return The error description. This is a statically-allocated | |
3088 * string, do not free it. | |
3089 **/ | |
3090 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription( | |
3091 OrthancPluginContext* context, | |
3092 OrthancPluginErrorCode error) | |
3093 { | |
3094 const char* result = NULL; | |
3095 | |
3096 _OrthancPluginGetErrorDescription params; | |
3097 params.target = &result; | |
3098 params.error = error; | |
3099 | |
3100 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, ¶ms) != OrthancPluginErrorCode_Success || | |
3101 result == NULL) | |
3102 { | |
3103 return "Unknown error code"; | |
3104 } | |
3105 else | |
3106 { | |
3107 return result; | |
3108 } | |
3109 } | |
3110 | |
3111 | |
3112 | |
3113 typedef struct | |
3114 { | |
3115 OrthancPluginRestOutput* output; | |
3116 uint16_t status; | |
3117 const char* body; | |
3118 uint32_t bodySize; | |
3119 } _OrthancPluginSendHttpStatus; | |
3120 | |
3121 /** | |
3122 * @brief Send a HTTP status, with a custom body. | |
3123 * | |
3124 * This function answers to a HTTP request by sending a HTTP status | |
3125 * code (such as "400 - Bad Request"), together with a body | |
3126 * describing the error. The body will only be returned if the | |
3127 * configuration option "HttpDescribeErrors" of Orthanc is set to "true". | |
3128 * | |
3129 * Note that: | |
3130 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). | |
3131 * - Redirections (status 301) must use ::OrthancPluginRedirect(). | |
3132 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). | |
3133 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). | |
3134 * | |
3135 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3136 * @param output The HTTP connection to the client application. | |
3137 * @param status The HTTP status code to be sent. | |
3138 * @param body The body of the answer. | |
3139 * @param bodySize The size of the body. | |
3140 * @see OrthancPluginSendHttpStatusCode() | |
3141 * @ingroup REST | |
3142 **/ | |
3143 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus( | |
3144 OrthancPluginContext* context, | |
3145 OrthancPluginRestOutput* output, | |
3146 uint16_t status, | |
3147 const char* body, | |
3148 uint32_t bodySize) | |
3149 { | |
3150 _OrthancPluginSendHttpStatus params; | |
3151 params.output = output; | |
3152 params.status = status; | |
3153 params.body = body; | |
3154 params.bodySize = bodySize; | |
3155 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, ¶ms); | |
3156 } | |
3157 | |
3158 | |
3159 | |
3160 typedef struct | |
3161 { | |
3162 const OrthancPluginImage* image; | |
3163 uint32_t* resultUint32; | |
3164 OrthancPluginPixelFormat* resultPixelFormat; | |
3165 void** resultBuffer; | |
3166 } _OrthancPluginGetImageInfo; | |
3167 | |
3168 | |
3169 /** | |
3170 * @brief Return the pixel format of an image. | |
3171 * | |
3172 * This function returns the type of memory layout for the pixels of the given image. | |
3173 * | |
3174 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3175 * @param image The image of interest. | |
3176 * @return The pixel format. | |
3177 * @ingroup Images | |
3178 **/ | |
3179 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat( | |
3180 OrthancPluginContext* context, | |
3181 const OrthancPluginImage* image) | |
3182 { | |
3183 OrthancPluginPixelFormat target; | |
3184 | |
3185 _OrthancPluginGetImageInfo params; | |
3186 memset(¶ms, 0, sizeof(params)); | |
3187 params.image = image; | |
3188 params.resultPixelFormat = ⌖ | |
3189 | |
3190 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, ¶ms) != OrthancPluginErrorCode_Success) | |
3191 { | |
3192 return OrthancPluginPixelFormat_Unknown; | |
3193 } | |
3194 else | |
3195 { | |
3196 return (OrthancPluginPixelFormat) target; | |
3197 } | |
3198 } | |
3199 | |
3200 | |
3201 | |
3202 /** | |
3203 * @brief Return the width of an image. | |
3204 * | |
3205 * This function returns the width of the given image. | |
3206 * | |
3207 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3208 * @param image The image of interest. | |
3209 * @return The width. | |
3210 * @ingroup Images | |
3211 **/ | |
3212 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth( | |
3213 OrthancPluginContext* context, | |
3214 const OrthancPluginImage* image) | |
3215 { | |
3216 uint32_t width; | |
3217 | |
3218 _OrthancPluginGetImageInfo params; | |
3219 memset(¶ms, 0, sizeof(params)); | |
3220 params.image = image; | |
3221 params.resultUint32 = &width; | |
3222 | |
3223 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, ¶ms) != OrthancPluginErrorCode_Success) | |
3224 { | |
3225 return 0; | |
3226 } | |
3227 else | |
3228 { | |
3229 return width; | |
3230 } | |
3231 } | |
3232 | |
3233 | |
3234 | |
3235 /** | |
3236 * @brief Return the height of an image. | |
3237 * | |
3238 * This function returns the height of the given image. | |
3239 * | |
3240 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3241 * @param image The image of interest. | |
3242 * @return The height. | |
3243 * @ingroup Images | |
3244 **/ | |
3245 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight( | |
3246 OrthancPluginContext* context, | |
3247 const OrthancPluginImage* image) | |
3248 { | |
3249 uint32_t height; | |
3250 | |
3251 _OrthancPluginGetImageInfo params; | |
3252 memset(¶ms, 0, sizeof(params)); | |
3253 params.image = image; | |
3254 params.resultUint32 = &height; | |
3255 | |
3256 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, ¶ms) != OrthancPluginErrorCode_Success) | |
3257 { | |
3258 return 0; | |
3259 } | |
3260 else | |
3261 { | |
3262 return height; | |
3263 } | |
3264 } | |
3265 | |
3266 | |
3267 | |
3268 /** | |
3269 * @brief Return the pitch of an image. | |
3270 * | |
3271 * This function returns the pitch of the given image. The pitch is | |
3272 * defined as the number of bytes between 2 successive lines of the | |
3273 * image in the memory buffer. | |
3274 * | |
3275 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3276 * @param image The image of interest. | |
3277 * @return The pitch. | |
3278 * @ingroup Images | |
3279 **/ | |
3280 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch( | |
3281 OrthancPluginContext* context, | |
3282 const OrthancPluginImage* image) | |
3283 { | |
3284 uint32_t pitch; | |
3285 | |
3286 _OrthancPluginGetImageInfo params; | |
3287 memset(¶ms, 0, sizeof(params)); | |
3288 params.image = image; | |
3289 params.resultUint32 = &pitch; | |
3290 | |
3291 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, ¶ms) != OrthancPluginErrorCode_Success) | |
3292 { | |
3293 return 0; | |
3294 } | |
3295 else | |
3296 { | |
3297 return pitch; | |
3298 } | |
3299 } | |
3300 | |
3301 | |
3302 | |
3303 /** | |
3304 * @brief Return a pointer to the content of an image. | |
3305 * | |
3306 * This function returns a pointer to the memory buffer that | |
3307 * contains the pixels of the image. | |
3308 * | |
3309 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3310 * @param image The image of interest. | |
3311 * @return The pointer. | |
3312 * @ingroup Images | |
3313 **/ | |
3314 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer( | |
3315 OrthancPluginContext* context, | |
3316 const OrthancPluginImage* image) | |
3317 { | |
3318 void* target = NULL; | |
3319 | |
3320 _OrthancPluginGetImageInfo params; | |
3321 memset(¶ms, 0, sizeof(params)); | |
3322 params.resultBuffer = ⌖ | |
3323 params.image = image; | |
3324 | |
3325 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, ¶ms) != OrthancPluginErrorCode_Success) | |
3326 { | |
3327 return NULL; | |
3328 } | |
3329 else | |
3330 { | |
3331 return target; | |
3332 } | |
3333 } | |
3334 | |
3335 | |
3336 typedef struct | |
3337 { | |
3338 OrthancPluginImage** target; | |
3339 const void* data; | |
3340 uint32_t size; | |
3341 OrthancPluginImageFormat format; | |
3342 } _OrthancPluginUncompressImage; | |
3343 | |
3344 | |
3345 /** | |
3346 * @brief Decode a compressed image. | |
3347 * | |
3348 * This function decodes a compressed image from a memory buffer. | |
3349 * | |
3350 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3351 * @param data Pointer to a memory buffer containing the compressed image. | |
3352 * @param size Size of the memory buffer containing the compressed image. | |
3353 * @param format The file format of the compressed image. | |
3354 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
3355 * @ingroup Images | |
3356 **/ | |
3357 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage( | |
3358 OrthancPluginContext* context, | |
3359 const void* data, | |
3360 uint32_t size, | |
3361 OrthancPluginImageFormat format) | |
3362 { | |
3363 OrthancPluginImage* target = NULL; | |
3364 | |
3365 _OrthancPluginUncompressImage params; | |
3366 memset(¶ms, 0, sizeof(params)); | |
3367 params.target = ⌖ | |
3368 params.data = data; | |
3369 params.size = size; | |
3370 params.format = format; | |
3371 | |
3372 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, ¶ms) != OrthancPluginErrorCode_Success) | |
3373 { | |
3374 return NULL; | |
3375 } | |
3376 else | |
3377 { | |
3378 return target; | |
3379 } | |
3380 } | |
3381 | |
3382 | |
3383 | |
3384 | |
3385 typedef struct | |
3386 { | |
3387 OrthancPluginImage* image; | |
3388 } _OrthancPluginFreeImage; | |
3389 | |
3390 /** | |
3391 * @brief Free an image. | |
3392 * | |
3393 * This function frees an image that was decoded with OrthancPluginUncompressImage(). | |
3394 * | |
3395 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3396 * @param image The image. | |
3397 * @ingroup Images | |
3398 **/ | |
3399 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage( | |
3400 OrthancPluginContext* context, | |
3401 OrthancPluginImage* image) | |
3402 { | |
3403 _OrthancPluginFreeImage params; | |
3404 params.image = image; | |
3405 | |
3406 context->InvokeService(context, _OrthancPluginService_FreeImage, ¶ms); | |
3407 } | |
3408 | |
3409 | |
3410 | |
3411 | |
3412 typedef struct | |
3413 { | |
3414 OrthancPluginMemoryBuffer* target; | |
3415 OrthancPluginImageFormat imageFormat; | |
3416 OrthancPluginPixelFormat pixelFormat; | |
3417 uint32_t width; | |
3418 uint32_t height; | |
3419 uint32_t pitch; | |
3420 const void* buffer; | |
3421 uint8_t quality; | |
3422 } _OrthancPluginCompressImage; | |
3423 | |
3424 | |
3425 /** | |
3426 * @brief Encode a PNG image. | |
3427 * | |
3428 * This function compresses the given memory buffer containing an | |
3429 * image using the PNG specification, and stores the result of the | |
3430 * compression into a newly allocated memory buffer. | |
3431 * | |
3432 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3433 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3434 * @param format The memory layout of the uncompressed image. | |
3435 * @param width The width of the image. | |
3436 * @param height The height of the image. | |
3437 * @param pitch The pitch of the image (i.e. the number of bytes | |
3438 * between 2 successive lines of the image in the memory buffer). | |
3439 * @param buffer The memory buffer containing the uncompressed image. | |
3440 * @return 0 if success, or the error code if failure. | |
3441 * @see OrthancPluginCompressAndAnswerPngImage() | |
3442 * @ingroup Images | |
3443 **/ | |
3444 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage( | |
3445 OrthancPluginContext* context, | |
3446 OrthancPluginMemoryBuffer* target, | |
3447 OrthancPluginPixelFormat format, | |
3448 uint32_t width, | |
3449 uint32_t height, | |
3450 uint32_t pitch, | |
3451 const void* buffer) | |
3452 { | |
3453 _OrthancPluginCompressImage params; | |
3454 memset(¶ms, 0, sizeof(params)); | |
3455 params.target = target; | |
3456 params.imageFormat = OrthancPluginImageFormat_Png; | |
3457 params.pixelFormat = format; | |
3458 params.width = width; | |
3459 params.height = height; | |
3460 params.pitch = pitch; | |
3461 params.buffer = buffer; | |
3462 params.quality = 0; /* Unused for PNG */ | |
3463 | |
3464 return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); | |
3465 } | |
3466 | |
3467 | |
3468 /** | |
3469 * @brief Encode a JPEG image. | |
3470 * | |
3471 * This function compresses the given memory buffer containing an | |
3472 * image using the JPEG specification, and stores the result of the | |
3473 * compression into a newly allocated memory buffer. | |
3474 * | |
3475 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3476 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3477 * @param format The memory layout of the uncompressed image. | |
3478 * @param width The width of the image. | |
3479 * @param height The height of the image. | |
3480 * @param pitch The pitch of the image (i.e. the number of bytes | |
3481 * between 2 successive lines of the image in the memory buffer). | |
3482 * @param buffer The memory buffer containing the uncompressed image. | |
3483 * @param quality The quality of the JPEG encoding, between 1 (worst | |
3484 * quality, best compression) and 100 (best quality, worst | |
3485 * compression). | |
3486 * @return 0 if success, or the error code if failure. | |
3487 * @ingroup Images | |
3488 **/ | |
3489 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage( | |
3490 OrthancPluginContext* context, | |
3491 OrthancPluginMemoryBuffer* target, | |
3492 OrthancPluginPixelFormat format, | |
3493 uint32_t width, | |
3494 uint32_t height, | |
3495 uint32_t pitch, | |
3496 const void* buffer, | |
3497 uint8_t quality) | |
3498 { | |
3499 _OrthancPluginCompressImage params; | |
3500 memset(¶ms, 0, sizeof(params)); | |
3501 params.target = target; | |
3502 params.imageFormat = OrthancPluginImageFormat_Jpeg; | |
3503 params.pixelFormat = format; | |
3504 params.width = width; | |
3505 params.height = height; | |
3506 params.pitch = pitch; | |
3507 params.buffer = buffer; | |
3508 params.quality = quality; | |
3509 | |
3510 return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); | |
3511 } | |
3512 | |
3513 | |
3514 | |
3515 /** | |
3516 * @brief Answer to a REST request with a JPEG image. | |
3517 * | |
3518 * This function answers to a REST request with a JPEG image. The | |
3519 * parameters of this function describe a memory buffer that | |
3520 * contains an uncompressed image. The image will be automatically compressed | |
3521 * as a JPEG image by the core system of Orthanc. | |
3522 * | |
3523 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3524 * @param output The HTTP connection to the client application. | |
3525 * @param format The memory layout of the uncompressed image. | |
3526 * @param width The width of the image. | |
3527 * @param height The height of the image. | |
3528 * @param pitch The pitch of the image (i.e. the number of bytes | |
3529 * between 2 successive lines of the image in the memory buffer). | |
3530 * @param buffer The memory buffer containing the uncompressed image. | |
3531 * @param quality The quality of the JPEG encoding, between 1 (worst | |
3532 * quality, best compression) and 100 (best quality, worst | |
3533 * compression). | |
3534 * @ingroup REST | |
3535 **/ | |
3536 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage( | |
3537 OrthancPluginContext* context, | |
3538 OrthancPluginRestOutput* output, | |
3539 OrthancPluginPixelFormat format, | |
3540 uint32_t width, | |
3541 uint32_t height, | |
3542 uint32_t pitch, | |
3543 const void* buffer, | |
3544 uint8_t quality) | |
3545 { | |
3546 _OrthancPluginCompressAndAnswerImage params; | |
3547 params.output = output; | |
3548 params.imageFormat = OrthancPluginImageFormat_Jpeg; | |
3549 params.pixelFormat = format; | |
3550 params.width = width; | |
3551 params.height = height; | |
3552 params.pitch = pitch; | |
3553 params.buffer = buffer; | |
3554 params.quality = quality; | |
3555 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); | |
3556 } | |
3557 | |
3558 | |
3559 | |
3560 | |
3561 typedef struct | |
3562 { | |
3563 OrthancPluginMemoryBuffer* target; | |
3564 OrthancPluginHttpMethod method; | |
3565 const char* url; | |
3566 const char* username; | |
3567 const char* password; | |
3568 const char* body; | |
3569 uint32_t bodySize; | |
3570 } _OrthancPluginCallHttpClient; | |
3571 | |
3572 | |
3573 /** | |
3574 * @brief Issue a HTTP GET call. | |
3575 * | |
3576 * Make a HTTP GET call to the given URL. The result to the query is | |
3577 * stored into a newly allocated memory buffer. Favor | |
3578 * OrthancPluginRestApiGet() if calling the built-in REST API of the | |
3579 * Orthanc instance that hosts this plugin. | |
3580 * | |
3581 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3582 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3583 * @param url The URL of interest. | |
3584 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3585 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3586 * @return 0 if success, or the error code if failure. | |
3587 **/ | |
3588 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet( | |
3589 OrthancPluginContext* context, | |
3590 OrthancPluginMemoryBuffer* target, | |
3591 const char* url, | |
3592 const char* username, | |
3593 const char* password) | |
3594 { | |
3595 _OrthancPluginCallHttpClient params; | |
3596 memset(¶ms, 0, sizeof(params)); | |
3597 | |
3598 params.target = target; | |
3599 params.method = OrthancPluginHttpMethod_Get; | |
3600 params.url = url; | |
3601 params.username = username; | |
3602 params.password = password; | |
3603 | |
3604 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
3605 } | |
3606 | |
3607 | |
3608 /** | |
3609 * @brief Issue a HTTP POST call. | |
3610 * | |
3611 * Make a HTTP POST call to the given URL. The result to the query | |
3612 * is stored into a newly allocated memory buffer. Favor | |
3613 * OrthancPluginRestApiPost() if calling the built-in REST API of | |
3614 * the Orthanc instance that hosts this plugin. | |
3615 * | |
3616 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3617 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3618 * @param url The URL of interest. | |
3619 * @param body The content of the body of the request. | |
3620 * @param bodySize The size of the body of the request. | |
3621 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3622 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3623 * @return 0 if success, or the error code if failure. | |
3624 **/ | |
3625 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost( | |
3626 OrthancPluginContext* context, | |
3627 OrthancPluginMemoryBuffer* target, | |
3628 const char* url, | |
3629 const char* body, | |
3630 uint32_t bodySize, | |
3631 const char* username, | |
3632 const char* password) | |
3633 { | |
3634 _OrthancPluginCallHttpClient params; | |
3635 memset(¶ms, 0, sizeof(params)); | |
3636 | |
3637 params.target = target; | |
3638 params.method = OrthancPluginHttpMethod_Post; | |
3639 params.url = url; | |
3640 params.body = body; | |
3641 params.bodySize = bodySize; | |
3642 params.username = username; | |
3643 params.password = password; | |
3644 | |
3645 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
3646 } | |
3647 | |
3648 | |
3649 /** | |
3650 * @brief Issue a HTTP PUT call. | |
3651 * | |
3652 * Make a HTTP PUT call to the given URL. The result to the query is | |
3653 * stored into a newly allocated memory buffer. Favor | |
3654 * OrthancPluginRestApiPut() if calling the built-in REST API of the | |
3655 * Orthanc instance that hosts this plugin. | |
3656 * | |
3657 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3658 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3659 * @param url The URL of interest. | |
3660 * @param body The content of the body of the request. | |
3661 * @param bodySize The size of the body of the request. | |
3662 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3663 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3664 * @return 0 if success, or the error code if failure. | |
3665 **/ | |
3666 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut( | |
3667 OrthancPluginContext* context, | |
3668 OrthancPluginMemoryBuffer* target, | |
3669 const char* url, | |
3670 const char* body, | |
3671 uint32_t bodySize, | |
3672 const char* username, | |
3673 const char* password) | |
3674 { | |
3675 _OrthancPluginCallHttpClient params; | |
3676 memset(¶ms, 0, sizeof(params)); | |
3677 | |
3678 params.target = target; | |
3679 params.method = OrthancPluginHttpMethod_Put; | |
3680 params.url = url; | |
3681 params.body = body; | |
3682 params.bodySize = bodySize; | |
3683 params.username = username; | |
3684 params.password = password; | |
3685 | |
3686 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
3687 } | |
3688 | |
3689 | |
3690 /** | |
3691 * @brief Issue a HTTP DELETE call. | |
3692 * | |
3693 * Make a HTTP DELETE call to the given URL. Favor | |
3694 * OrthancPluginRestApiDelete() if calling the built-in REST API of | |
3695 * the Orthanc instance that hosts this plugin. | |
3696 * | |
3697 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3698 * @param url The URL of interest. | |
3699 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3700 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3701 * @return 0 if success, or the error code if failure. | |
3702 **/ | |
3703 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete( | |
3704 OrthancPluginContext* context, | |
3705 const char* url, | |
3706 const char* username, | |
3707 const char* password) | |
3708 { | |
3709 _OrthancPluginCallHttpClient params; | |
3710 memset(¶ms, 0, sizeof(params)); | |
3711 | |
3712 params.method = OrthancPluginHttpMethod_Delete; | |
3713 params.url = url; | |
3714 params.username = username; | |
3715 params.password = password; | |
3716 | |
3717 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
3718 } | |
3719 | |
3720 | |
3721 | |
3722 typedef struct | |
3723 { | |
3724 OrthancPluginImage** target; | |
3725 const OrthancPluginImage* source; | |
3726 OrthancPluginPixelFormat targetFormat; | |
3727 } _OrthancPluginConvertPixelFormat; | |
3728 | |
3729 | |
3730 /** | |
3731 * @brief Change the pixel format of an image. | |
3732 * | |
3733 * This function creates a new image, changing the memory layout of the pixels. | |
3734 * | |
3735 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3736 * @param source The source image. | |
3737 * @param targetFormat The target pixel format. | |
3738 * @return The resulting image. It must be freed with OrthancPluginFreeImage(). | |
3739 * @ingroup Images | |
3740 **/ | |
3741 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat( | |
3742 OrthancPluginContext* context, | |
3743 const OrthancPluginImage* source, | |
3744 OrthancPluginPixelFormat targetFormat) | |
3745 { | |
3746 OrthancPluginImage* target = NULL; | |
3747 | |
3748 _OrthancPluginConvertPixelFormat params; | |
3749 params.target = ⌖ | |
3750 params.source = source; | |
3751 params.targetFormat = targetFormat; | |
3752 | |
3753 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, ¶ms) != OrthancPluginErrorCode_Success) | |
3754 { | |
3755 return NULL; | |
3756 } | |
3757 else | |
3758 { | |
3759 return target; | |
3760 } | |
3761 } | |
3762 | |
3763 | |
3764 | |
3765 /** | |
3766 * @brief Return the number of available fonts. | |
3767 * | |
3768 * This function returns the number of fonts that are built in the | |
3769 * Orthanc core. These fonts can be used to draw texts on images | |
3770 * through OrthancPluginDrawText(). | |
3771 * | |
3772 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3773 * @return The number of fonts. | |
3774 * @ingroup Images | |
3775 **/ | |
3776 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount( | |
3777 OrthancPluginContext* context) | |
3778 { | |
3779 uint32_t count = 0; | |
3780 | |
3781 _OrthancPluginReturnSingleValue params; | |
3782 memset(¶ms, 0, sizeof(params)); | |
3783 params.resultUint32 = &count; | |
3784 | |
3785 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, ¶ms) != OrthancPluginErrorCode_Success) | |
3786 { | |
3787 /* Error */ | |
3788 return 0; | |
3789 } | |
3790 else | |
3791 { | |
3792 return count; | |
3793 } | |
3794 } | |
3795 | |
3796 | |
3797 | |
3798 | |
3799 typedef struct | |
3800 { | |
3801 uint32_t fontIndex; /* in */ | |
3802 const char** name; /* out */ | |
3803 uint32_t* size; /* out */ | |
3804 } _OrthancPluginGetFontInfo; | |
3805 | |
3806 /** | |
3807 * @brief Return the name of a font. | |
3808 * | |
3809 * This function returns the name of a font that is built in the Orthanc core. | |
3810 * | |
3811 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3812 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
3813 * @return The font name. This is a statically-allocated string, do not free it. | |
3814 * @ingroup Images | |
3815 **/ | |
3816 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName( | |
3817 OrthancPluginContext* context, | |
3818 uint32_t fontIndex) | |
3819 { | |
3820 const char* result = NULL; | |
3821 | |
3822 _OrthancPluginGetFontInfo params; | |
3823 memset(¶ms, 0, sizeof(params)); | |
3824 params.name = &result; | |
3825 params.fontIndex = fontIndex; | |
3826 | |
3827 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) | |
3828 { | |
3829 return NULL; | |
3830 } | |
3831 else | |
3832 { | |
3833 return result; | |
3834 } | |
3835 } | |
3836 | |
3837 | |
3838 /** | |
3839 * @brief Return the size of a font. | |
3840 * | |
3841 * This function returns the size of a font that is built in the Orthanc core. | |
3842 * | |
3843 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3844 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
3845 * @return The font size. | |
3846 * @ingroup Images | |
3847 **/ | |
3848 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize( | |
3849 OrthancPluginContext* context, | |
3850 uint32_t fontIndex) | |
3851 { | |
3852 uint32_t result; | |
3853 | |
3854 _OrthancPluginGetFontInfo params; | |
3855 memset(¶ms, 0, sizeof(params)); | |
3856 params.size = &result; | |
3857 params.fontIndex = fontIndex; | |
3858 | |
3859 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) | |
3860 { | |
3861 return 0; | |
3862 } | |
3863 else | |
3864 { | |
3865 return result; | |
3866 } | |
3867 } | |
3868 | |
3869 | |
3870 | |
3871 typedef struct | |
3872 { | |
3873 OrthancPluginImage* image; | |
3874 uint32_t fontIndex; | |
3875 const char* utf8Text; | |
3876 int32_t x; | |
3877 int32_t y; | |
3878 uint8_t r; | |
3879 uint8_t g; | |
3880 uint8_t b; | |
3881 } _OrthancPluginDrawText; | |
3882 | |
3883 | |
3884 /** | |
3885 * @brief Draw text on an image. | |
3886 * | |
3887 * This function draws some text on some image. | |
3888 * | |
3889 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3890 * @param image The image upon which to draw the text. | |
3891 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
3892 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string. | |
3893 * @param x The X position of the text over the image. | |
3894 * @param y The Y position of the text over the image. | |
3895 * @param r The value of the red color channel of the text. | |
3896 * @param g The value of the green color channel of the text. | |
3897 * @param b The value of the blue color channel of the text. | |
3898 * @return 0 if success, other value if error. | |
3899 * @ingroup Images | |
3900 **/ | |
3901 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText( | |
3902 OrthancPluginContext* context, | |
3903 OrthancPluginImage* image, | |
3904 uint32_t fontIndex, | |
3905 const char* utf8Text, | |
3906 int32_t x, | |
3907 int32_t y, | |
3908 uint8_t r, | |
3909 uint8_t g, | |
3910 uint8_t b) | |
3911 { | |
3912 _OrthancPluginDrawText params; | |
3913 memset(¶ms, 0, sizeof(params)); | |
3914 params.image = image; | |
3915 params.fontIndex = fontIndex; | |
3916 params.utf8Text = utf8Text; | |
3917 params.x = x; | |
3918 params.y = y; | |
3919 params.r = r; | |
3920 params.g = g; | |
3921 params.b = b; | |
3922 | |
3923 return context->InvokeService(context, _OrthancPluginService_DrawText, ¶ms); | |
3924 } | |
3925 | |
3926 | |
3927 | |
3928 typedef struct | |
3929 { | |
3930 OrthancPluginStorageArea* storageArea; | |
3931 const char* uuid; | |
3932 const void* content; | |
3933 uint64_t size; | |
3934 OrthancPluginContentType type; | |
3935 } _OrthancPluginStorageAreaCreate; | |
3936 | |
3937 | |
3938 /** | |
3939 * @brief Create a file inside the storage area. | |
3940 * | |
3941 * This function creates a new file inside the storage area that is | |
3942 * currently used by Orthanc. | |
3943 * | |
3944 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3945 * @param storageArea The storage area. | |
3946 * @param uuid The identifier of the file to be created. | |
3947 * @param content The content to store in the newly created file. | |
3948 * @param size The size of the content. | |
3949 * @param type The type of the file content. | |
3950 * @return 0 if success, other value if error. | |
3951 * @ingroup Callbacks | |
3952 **/ | |
3953 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate( | |
3954 OrthancPluginContext* context, | |
3955 OrthancPluginStorageArea* storageArea, | |
3956 const char* uuid, | |
3957 const void* content, | |
3958 uint64_t size, | |
3959 OrthancPluginContentType type) | |
3960 { | |
3961 _OrthancPluginStorageAreaCreate params; | |
3962 params.storageArea = storageArea; | |
3963 params.uuid = uuid; | |
3964 params.content = content; | |
3965 params.size = size; | |
3966 params.type = type; | |
3967 | |
3968 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, ¶ms); | |
3969 } | |
3970 | |
3971 | |
3972 typedef struct | |
3973 { | |
3974 OrthancPluginMemoryBuffer* target; | |
3975 OrthancPluginStorageArea* storageArea; | |
3976 const char* uuid; | |
3977 OrthancPluginContentType type; | |
3978 } _OrthancPluginStorageAreaRead; | |
3979 | |
3980 | |
3981 /** | |
3982 * @brief Read a file from the storage area. | |
3983 * | |
3984 * This function reads the content of a given file from the storage | |
3985 * area that is currently used by Orthanc. | |
3986 * | |
3987 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3988 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3989 * @param storageArea The storage area. | |
3990 * @param uuid The identifier of the file to be read. | |
3991 * @param type The type of the file content. | |
3992 * @return 0 if success, other value if error. | |
3993 * @ingroup Callbacks | |
3994 **/ | |
3995 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead( | |
3996 OrthancPluginContext* context, | |
3997 OrthancPluginMemoryBuffer* target, | |
3998 OrthancPluginStorageArea* storageArea, | |
3999 const char* uuid, | |
4000 OrthancPluginContentType type) | |
4001 { | |
4002 _OrthancPluginStorageAreaRead params; | |
4003 params.target = target; | |
4004 params.storageArea = storageArea; | |
4005 params.uuid = uuid; | |
4006 params.type = type; | |
4007 | |
4008 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, ¶ms); | |
4009 } | |
4010 | |
4011 | |
4012 typedef struct | |
4013 { | |
4014 OrthancPluginStorageArea* storageArea; | |
4015 const char* uuid; | |
4016 OrthancPluginContentType type; | |
4017 } _OrthancPluginStorageAreaRemove; | |
4018 | |
4019 /** | |
4020 * @brief Remove a file from the storage area. | |
4021 * | |
4022 * This function removes a given file from the storage area that is | |
4023 * currently used by Orthanc. | |
4024 * | |
4025 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4026 * @param storageArea The storage area. | |
4027 * @param uuid The identifier of the file to be removed. | |
4028 * @param type The type of the file content. | |
4029 * @return 0 if success, other value if error. | |
4030 * @ingroup Callbacks | |
4031 **/ | |
4032 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove( | |
4033 OrthancPluginContext* context, | |
4034 OrthancPluginStorageArea* storageArea, | |
4035 const char* uuid, | |
4036 OrthancPluginContentType type) | |
4037 { | |
4038 _OrthancPluginStorageAreaRemove params; | |
4039 params.storageArea = storageArea; | |
4040 params.uuid = uuid; | |
4041 params.type = type; | |
4042 | |
4043 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, ¶ms); | |
4044 } | |
4045 | |
4046 | |
4047 | |
4048 typedef struct | |
4049 { | |
4050 OrthancPluginErrorCode* target; | |
4051 int32_t code; | |
4052 uint16_t httpStatus; | |
4053 const char* message; | |
4054 } _OrthancPluginRegisterErrorCode; | |
4055 | |
4056 /** | |
4057 * @brief Declare a custom error code for this plugin. | |
4058 * | |
4059 * This function declares a custom error code that can be generated | |
4060 * by this plugin. This declaration is used to enrich the body of | |
4061 * the HTTP answer in the case of an error, and to set the proper | |
4062 * HTTP status code. | |
4063 * | |
4064 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4065 * @param code The error code that is internal to this plugin. | |
4066 * @param httpStatus The HTTP status corresponding to this error. | |
4067 * @param message The description of the error. | |
4068 * @return The error code that has been assigned inside the Orthanc core. | |
4069 * @ingroup Toolbox | |
4070 **/ | |
4071 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode( | |
4072 OrthancPluginContext* context, | |
4073 int32_t code, | |
4074 uint16_t httpStatus, | |
4075 const char* message) | |
4076 { | |
4077 OrthancPluginErrorCode target; | |
4078 | |
4079 _OrthancPluginRegisterErrorCode params; | |
4080 params.target = ⌖ | |
4081 params.code = code; | |
4082 params.httpStatus = httpStatus; | |
4083 params.message = message; | |
4084 | |
4085 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, ¶ms) == OrthancPluginErrorCode_Success) | |
4086 { | |
4087 return target; | |
4088 } | |
4089 else | |
4090 { | |
4091 /* There was an error while assigned the error. Use a generic code. */ | |
4092 return OrthancPluginErrorCode_Plugin; | |
4093 } | |
4094 } | |
4095 | |
4096 | |
4097 | |
4098 typedef struct | |
4099 { | |
4100 uint16_t group; | |
4101 uint16_t element; | |
4102 OrthancPluginValueRepresentation vr; | |
4103 const char* name; | |
4104 uint32_t minMultiplicity; | |
4105 uint32_t maxMultiplicity; | |
4106 } _OrthancPluginRegisterDictionaryTag; | |
4107 | |
4108 /** | |
4109 * @brief Register a new tag into the DICOM dictionary. | |
4110 * | |
4111 * This function declares a new public tag in the dictionary of | |
4112 * DICOM tags that are known to Orthanc. This function should be | |
4113 * used in the OrthancPluginInitialize() callback. | |
4114 * | |
4115 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4116 * @param group The group of the tag. | |
4117 * @param element The element of the tag. | |
4118 * @param vr The value representation of the tag. | |
4119 * @param name The nickname of the tag. | |
4120 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). | |
4121 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means | |
4122 * an arbitrary multiplicity ("<tt>n</tt>"). | |
4123 * @return 0 if success, other value if error. | |
4124 * @see OrthancPluginRegisterPrivateDictionaryTag() | |
4125 * @ingroup Toolbox | |
4126 **/ | |
4127 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag( | |
4128 OrthancPluginContext* context, | |
4129 uint16_t group, | |
4130 uint16_t element, | |
4131 OrthancPluginValueRepresentation vr, | |
4132 const char* name, | |
4133 uint32_t minMultiplicity, | |
4134 uint32_t maxMultiplicity) | |
4135 { | |
4136 _OrthancPluginRegisterDictionaryTag params; | |
4137 params.group = group; | |
4138 params.element = element; | |
4139 params.vr = vr; | |
4140 params.name = name; | |
4141 params.minMultiplicity = minMultiplicity; | |
4142 params.maxMultiplicity = maxMultiplicity; | |
4143 | |
4144 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, ¶ms); | |
4145 } | |
4146 | |
4147 | |
4148 | |
4149 typedef struct | |
4150 { | |
4151 uint16_t group; | |
4152 uint16_t element; | |
4153 OrthancPluginValueRepresentation vr; | |
4154 const char* name; | |
4155 uint32_t minMultiplicity; | |
4156 uint32_t maxMultiplicity; | |
4157 const char* privateCreator; | |
4158 } _OrthancPluginRegisterPrivateDictionaryTag; | |
4159 | |
4160 /** | |
4161 * @brief Register a new private tag into the DICOM dictionary. | |
4162 * | |
4163 * This function declares a new private tag in the dictionary of | |
4164 * DICOM tags that are known to Orthanc. This function should be | |
4165 * used in the OrthancPluginInitialize() callback. | |
4166 * | |
4167 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4168 * @param group The group of the tag. | |
4169 * @param element The element of the tag. | |
4170 * @param vr The value representation of the tag. | |
4171 * @param name The nickname of the tag. | |
4172 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). | |
4173 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means | |
4174 * an arbitrary multiplicity ("<tt>n</tt>"). | |
4175 * @param privateCreator The private creator of this private tag. | |
4176 * @return 0 if success, other value if error. | |
4177 * @see OrthancPluginRegisterDictionaryTag() | |
4178 * @ingroup Toolbox | |
4179 **/ | |
4180 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag( | |
4181 OrthancPluginContext* context, | |
4182 uint16_t group, | |
4183 uint16_t element, | |
4184 OrthancPluginValueRepresentation vr, | |
4185 const char* name, | |
4186 uint32_t minMultiplicity, | |
4187 uint32_t maxMultiplicity, | |
4188 const char* privateCreator) | |
4189 { | |
4190 _OrthancPluginRegisterPrivateDictionaryTag params; | |
4191 params.group = group; | |
4192 params.element = element; | |
4193 params.vr = vr; | |
4194 params.name = name; | |
4195 params.minMultiplicity = minMultiplicity; | |
4196 params.maxMultiplicity = maxMultiplicity; | |
4197 params.privateCreator = privateCreator; | |
4198 | |
4199 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, ¶ms); | |
4200 } | |
4201 | |
4202 | |
4203 | |
4204 typedef struct | |
4205 { | |
4206 OrthancPluginStorageArea* storageArea; | |
4207 OrthancPluginResourceType level; | |
4208 } _OrthancPluginReconstructMainDicomTags; | |
4209 | |
4210 /** | |
4211 * @brief Reconstruct the main DICOM tags. | |
4212 * | |
4213 * This function requests the Orthanc core to reconstruct the main | |
4214 * DICOM tags of all the resources of the given type. This function | |
4215 * can only be used as a part of the upgrade of a custom database | |
4216 * back-end | |
4217 * (cf. OrthancPlugins::IDatabaseBackend::UpgradeDatabase). A | |
4218 * database transaction will be automatically setup. | |
4219 * | |
4220 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4221 * @param storageArea The storage area. | |
4222 * @param level The type of the resources of interest. | |
4223 * @return 0 if success, other value if error. | |
4224 * @ingroup Callbacks | |
4225 **/ | |
4226 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( | |
4227 OrthancPluginContext* context, | |
4228 OrthancPluginStorageArea* storageArea, | |
4229 OrthancPluginResourceType level) | |
4230 { | |
4231 _OrthancPluginReconstructMainDicomTags params; | |
4232 params.level = level; | |
4233 params.storageArea = storageArea; | |
4234 | |
4235 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, ¶ms); | |
4236 } | |
4237 | |
4238 | |
4239 typedef struct | |
4240 { | |
4241 char** result; | |
4242 const char* instanceId; | |
4243 const void* buffer; | |
4244 uint32_t size; | |
4245 OrthancPluginDicomToJsonFormat format; | |
4246 OrthancPluginDicomToJsonFlags flags; | |
4247 uint32_t maxStringLength; | |
4248 } _OrthancPluginDicomToJson; | |
4249 | |
4250 | |
4251 /** | |
4252 * @brief Format a DICOM memory buffer as a JSON string. | |
4253 * | |
4254 * This function takes as input a memory buffer containing a DICOM | |
4255 * file, and outputs a JSON string representing the tags of this | |
4256 * DICOM file. | |
4257 * | |
4258 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4259 * @param buffer The memory buffer containing the DICOM file. | |
4260 * @param size The size of the memory buffer. | |
4261 * @param format The output format. | |
4262 * @param flags Flags governing the output. | |
4263 * @param maxStringLength The maximum length of a field. Too long fields will | |
4264 * be output as "null". The 0 value means no maximum length. | |
4265 * @return The NULL value if the case of an error, or the JSON | |
4266 * string. This string must be freed by OrthancPluginFreeString(). | |
4267 * @ingroup Toolbox | |
4268 * @see OrthancPluginDicomInstanceToJson | |
4269 **/ | |
4270 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson( | |
4271 OrthancPluginContext* context, | |
4272 const void* buffer, | |
4273 uint32_t size, | |
4274 OrthancPluginDicomToJsonFormat format, | |
4275 OrthancPluginDicomToJsonFlags flags, | |
4276 uint32_t maxStringLength) | |
4277 { | |
4278 char* result; | |
4279 | |
4280 _OrthancPluginDicomToJson params; | |
4281 memset(¶ms, 0, sizeof(params)); | |
4282 params.result = &result; | |
4283 params.buffer = buffer; | |
4284 params.size = size; | |
4285 params.format = format; | |
4286 params.flags = flags; | |
4287 params.maxStringLength = maxStringLength; | |
4288 | |
4289 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) | |
4290 { | |
4291 /* Error */ | |
4292 return NULL; | |
4293 } | |
4294 else | |
4295 { | |
4296 return result; | |
4297 } | |
4298 } | |
4299 | |
4300 | |
4301 /** | |
4302 * @brief Format a DICOM instance as a JSON string. | |
4303 * | |
4304 * This function formats a DICOM instance that is stored in Orthanc, | |
4305 * and outputs a JSON string representing the tags of this DICOM | |
4306 * instance. | |
4307 * | |
4308 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4309 * @param instanceId The Orthanc identifier of the instance. | |
4310 * @param format The output format. | |
4311 * @param flags Flags governing the output. | |
4312 * @param maxStringLength The maximum length of a field. Too long fields will | |
4313 * be output as "null". The 0 value means no maximum length. | |
4314 * @return The NULL value if the case of an error, or the JSON | |
4315 * string. This string must be freed by OrthancPluginFreeString(). | |
4316 * @ingroup Toolbox | |
4317 * @see OrthancPluginDicomInstanceToJson | |
4318 **/ | |
4319 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson( | |
4320 OrthancPluginContext* context, | |
4321 const char* instanceId, | |
4322 OrthancPluginDicomToJsonFormat format, | |
4323 OrthancPluginDicomToJsonFlags flags, | |
4324 uint32_t maxStringLength) | |
4325 { | |
4326 char* result; | |
4327 | |
4328 _OrthancPluginDicomToJson params; | |
4329 memset(¶ms, 0, sizeof(params)); | |
4330 params.result = &result; | |
4331 params.instanceId = instanceId; | |
4332 params.format = format; | |
4333 params.flags = flags; | |
4334 params.maxStringLength = maxStringLength; | |
4335 | |
4336 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, ¶ms) != OrthancPluginErrorCode_Success) | |
4337 { | |
4338 /* Error */ | |
4339 return NULL; | |
4340 } | |
4341 else | |
4342 { | |
4343 return result; | |
4344 } | |
4345 } | |
4346 | |
4347 | |
4348 typedef struct | |
4349 { | |
4350 OrthancPluginMemoryBuffer* target; | |
4351 const char* uri; | |
4352 uint32_t headersCount; | |
4353 const char* const* headersKeys; | |
4354 const char* const* headersValues; | |
4355 int32_t afterPlugins; | |
4356 } _OrthancPluginRestApiGet2; | |
4357 | |
4358 /** | |
4359 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers. | |
4360 * | |
4361 * Make a GET call to the Orthanc REST API with extended | |
4362 * parameters. The result to the query is stored into a newly | |
4363 * allocated memory buffer. | |
4364 * | |
4365 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4366 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4367 * @param uri The URI in the built-in Orthanc API. | |
4368 * @param headersCount The number of HTTP headers. | |
4369 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
4370 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
4371 * @param afterPlugins If 0, the built-in API of Orthanc is used. | |
4372 * If 1, the API is tainted by the plugins. | |
4373 * @return 0 if success, or the error code if failure. | |
4374 * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins | |
4375 * @ingroup Orthanc | |
4376 **/ | |
4377 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2( | |
4378 OrthancPluginContext* context, | |
4379 OrthancPluginMemoryBuffer* target, | |
4380 const char* uri, | |
4381 uint32_t headersCount, | |
4382 const char* const* headersKeys, | |
4383 const char* const* headersValues, | |
4384 int32_t afterPlugins) | |
4385 { | |
4386 _OrthancPluginRestApiGet2 params; | |
4387 params.target = target; | |
4388 params.uri = uri; | |
4389 params.headersCount = headersCount; | |
4390 params.headersKeys = headersKeys; | |
4391 params.headersValues = headersValues; | |
4392 params.afterPlugins = afterPlugins; | |
4393 | |
4394 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, ¶ms); | |
4395 } | |
4396 | |
4397 | |
4398 | |
4399 typedef struct | |
4400 { | |
4401 OrthancPluginWorklistCallback callback; | |
4402 } _OrthancPluginWorklistCallback; | |
4403 | |
4404 /** | |
4405 * @brief Register a callback to handle modality worklists requests. | |
4406 * | |
4407 * This function registers a callback to handle C-Find SCP requests | |
4408 * on modality worklists. | |
4409 * | |
4410 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4411 * @param callback The callback. | |
4412 * @return 0 if success, other value if error. | |
4413 * @ingroup DicomCallbacks | |
4414 **/ | |
4415 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback( | |
4416 OrthancPluginContext* context, | |
4417 OrthancPluginWorklistCallback callback) | |
4418 { | |
4419 _OrthancPluginWorklistCallback params; | |
4420 params.callback = callback; | |
4421 | |
4422 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, ¶ms); | |
4423 } | |
4424 | |
4425 | |
4426 | |
4427 typedef struct | |
4428 { | |
4429 OrthancPluginWorklistAnswers* answers; | |
4430 const OrthancPluginWorklistQuery* query; | |
4431 const void* dicom; | |
4432 uint32_t size; | |
4433 } _OrthancPluginWorklistAnswersOperation; | |
4434 | |
4435 /** | |
4436 * @brief Add one answer to some modality worklist request. | |
4437 * | |
4438 * This function adds one worklist (encoded as a DICOM file) to the | |
4439 * set of answers corresponding to some C-Find SCP request against | |
4440 * modality worklists. | |
4441 * | |
4442 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4443 * @param answers The set of answers. | |
4444 * @param query The worklist query, as received by the callback. | |
4445 * @param dicom The worklist to answer, encoded as a DICOM file. | |
4446 * @param size The size of the DICOM file. | |
4447 * @return 0 if success, other value if error. | |
4448 * @ingroup DicomCallbacks | |
4449 * @see OrthancPluginCreateDicom() | |
4450 **/ | |
4451 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer( | |
4452 OrthancPluginContext* context, | |
4453 OrthancPluginWorklistAnswers* answers, | |
4454 const OrthancPluginWorklistQuery* query, | |
4455 const void* dicom, | |
4456 uint32_t size) | |
4457 { | |
4458 _OrthancPluginWorklistAnswersOperation params; | |
4459 params.answers = answers; | |
4460 params.query = query; | |
4461 params.dicom = dicom; | |
4462 params.size = size; | |
4463 | |
4464 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, ¶ms); | |
4465 } | |
4466 | |
4467 | |
4468 /** | |
4469 * @brief Mark the set of worklist answers as incomplete. | |
4470 * | |
4471 * This function marks as incomplete the set of answers | |
4472 * corresponding to some C-Find SCP request against modality | |
4473 * worklists. This must be used if canceling the handling of a | |
4474 * request when too many answers are to be returned. | |
4475 * | |
4476 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4477 * @param answers The set of answers. | |
4478 * @return 0 if success, other value if error. | |
4479 * @ingroup DicomCallbacks | |
4480 **/ | |
4481 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete( | |
4482 OrthancPluginContext* context, | |
4483 OrthancPluginWorklistAnswers* answers) | |
4484 { | |
4485 _OrthancPluginWorklistAnswersOperation params; | |
4486 params.answers = answers; | |
4487 params.query = NULL; | |
4488 params.dicom = NULL; | |
4489 params.size = 0; | |
4490 | |
4491 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, ¶ms); | |
4492 } | |
4493 | |
4494 | |
4495 typedef struct | |
4496 { | |
4497 const OrthancPluginWorklistQuery* query; | |
4498 const void* dicom; | |
4499 uint32_t size; | |
4500 int32_t* isMatch; | |
4501 OrthancPluginMemoryBuffer* target; | |
4502 } _OrthancPluginWorklistQueryOperation; | |
4503 | |
4504 /** | |
4505 * @brief Test whether a worklist matches the query. | |
4506 * | |
4507 * This function checks whether one worklist (encoded as a DICOM | |
4508 * file) matches the C-Find SCP query against modality | |
4509 * worklists. This function must be called before adding the | |
4510 * worklist as an answer through OrthancPluginWorklistAddAnswer(). | |
4511 * | |
4512 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4513 * @param query The worklist query, as received by the callback. | |
4514 * @param dicom The worklist to answer, encoded as a DICOM file. | |
4515 * @param size The size of the DICOM file. | |
4516 * @return 1 if the worklist matches the query, 0 otherwise. | |
4517 * @ingroup DicomCallbacks | |
4518 **/ | |
4519 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch( | |
4520 OrthancPluginContext* context, | |
4521 const OrthancPluginWorklistQuery* query, | |
4522 const void* dicom, | |
4523 uint32_t size) | |
4524 { | |
4525 int32_t isMatch = 0; | |
4526 | |
4527 _OrthancPluginWorklistQueryOperation params; | |
4528 params.query = query; | |
4529 params.dicom = dicom; | |
4530 params.size = size; | |
4531 params.isMatch = &isMatch; | |
4532 params.target = NULL; | |
4533 | |
4534 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, ¶ms) == OrthancPluginErrorCode_Success) | |
4535 { | |
4536 return isMatch; | |
4537 } | |
4538 else | |
4539 { | |
4540 /* Error: Assume non-match */ | |
4541 return 0; | |
4542 } | |
4543 } | |
4544 | |
4545 | |
4546 /** | |
4547 * @brief Retrieve the worklist query as a DICOM file. | |
4548 * | |
4549 * This function retrieves the DICOM file that underlies a C-Find | |
4550 * SCP query against modality worklists. | |
4551 * | |
4552 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4553 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4554 * @param query The worklist query, as received by the callback. | |
4555 * @return 0 if success, other value if error. | |
4556 * @ingroup DicomCallbacks | |
4557 **/ | |
4558 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery( | |
4559 OrthancPluginContext* context, | |
4560 OrthancPluginMemoryBuffer* target, | |
4561 const OrthancPluginWorklistQuery* query) | |
4562 { | |
4563 _OrthancPluginWorklistQueryOperation params; | |
4564 params.query = query; | |
4565 params.dicom = NULL; | |
4566 params.size = 0; | |
4567 params.isMatch = NULL; | |
4568 params.target = target; | |
4569 | |
4570 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, ¶ms); | |
4571 } | |
4572 | |
4573 | |
4574 /** | |
4575 * @brief Get the origin of a DICOM file. | |
4576 * | |
4577 * This function returns the origin of a DICOM instance that has been received by Orthanc. | |
4578 * | |
4579 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4580 * @param instance The instance of interest. | |
4581 * @return The origin of the instance. | |
4582 * @ingroup Callbacks | |
4583 **/ | |
4584 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin( | |
4585 OrthancPluginContext* context, | |
4586 OrthancPluginDicomInstance* instance) | |
4587 { | |
4588 OrthancPluginInstanceOrigin origin; | |
4589 | |
4590 _OrthancPluginAccessDicomInstance params; | |
4591 memset(¶ms, 0, sizeof(params)); | |
4592 params.resultOrigin = &origin; | |
4593 params.instance = instance; | |
4594 | |
4595 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, ¶ms) != OrthancPluginErrorCode_Success) | |
4596 { | |
4597 /* Error */ | |
4598 return OrthancPluginInstanceOrigin_Unknown; | |
4599 } | |
4600 else | |
4601 { | |
4602 return origin; | |
4603 } | |
4604 } | |
4605 | |
4606 | |
4607 typedef struct | |
4608 { | |
4609 OrthancPluginMemoryBuffer* target; | |
4610 const char* json; | |
4611 const OrthancPluginImage* pixelData; | |
4612 OrthancPluginCreateDicomFlags flags; | |
4613 } _OrthancPluginCreateDicom; | |
4614 | |
4615 /** | |
4616 * @brief Create a DICOM instance from a JSON string and an image. | |
4617 * | |
4618 * This function takes as input a string containing a JSON file | |
4619 * describing the content of a DICOM instance. As an output, it | |
4620 * writes the corresponding DICOM instance to a newly allocated | |
4621 * memory buffer. Additionally, an image to be encoded within the | |
4622 * DICOM instance can also be provided. | |
4623 * | |
4624 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4625 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4626 * @param json The input JSON file. | |
4627 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme. | |
4628 * @param flags Flags governing the output. | |
4629 * @return 0 if success, other value if error. | |
4630 * @ingroup Toolbox | |
4631 * @see OrthancPluginDicomBufferToJson | |
4632 **/ | |
4633 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom( | |
4634 OrthancPluginContext* context, | |
4635 OrthancPluginMemoryBuffer* target, | |
4636 const char* json, | |
4637 const OrthancPluginImage* pixelData, | |
4638 OrthancPluginCreateDicomFlags flags) | |
4639 { | |
4640 _OrthancPluginCreateDicom params; | |
4641 params.target = target; | |
4642 params.json = json; | |
4643 params.pixelData = pixelData; | |
4644 params.flags = flags; | |
4645 | |
4646 return context->InvokeService(context, _OrthancPluginService_CreateDicom, ¶ms); | |
4647 } | |
4648 | |
4649 | |
4650 typedef struct | |
4651 { | |
4652 OrthancPluginDecodeImageCallback callback; | |
4653 } _OrthancPluginDecodeImageCallback; | |
4654 | |
4655 /** | |
4656 * @brief Register a callback to handle the decoding of DICOM images. | |
4657 * | |
4658 * This function registers a custom callback to the decoding of | |
4659 * DICOM images, replacing the built-in decoder of Orthanc. | |
4660 * | |
4661 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4662 * @param callback The callback. | |
4663 * @return 0 if success, other value if error. | |
4664 * @ingroup Callbacks | |
4665 **/ | |
4666 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback( | |
4667 OrthancPluginContext* context, | |
4668 OrthancPluginDecodeImageCallback callback) | |
4669 { | |
4670 _OrthancPluginDecodeImageCallback params; | |
4671 params.callback = callback; | |
4672 | |
4673 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, ¶ms); | |
4674 } | |
4675 | |
4676 | |
4677 | |
4678 typedef struct | |
4679 { | |
4680 OrthancPluginImage** target; | |
4681 OrthancPluginPixelFormat format; | |
4682 uint32_t width; | |
4683 uint32_t height; | |
4684 uint32_t pitch; | |
4685 void* buffer; | |
4686 const void* constBuffer; | |
4687 uint32_t bufferSize; | |
4688 uint32_t frameIndex; | |
4689 } _OrthancPluginCreateImage; | |
4690 | |
4691 | |
4692 /** | |
4693 * @brief Create an image. | |
4694 * | |
4695 * This function creates an image of given size and format. | |
4696 * | |
4697 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4698 * @param format The format of the pixels. | |
4699 * @param width The width of the image. | |
4700 * @param height The height of the image. | |
4701 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). | |
4702 * @ingroup Images | |
4703 **/ | |
4704 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage( | |
4705 OrthancPluginContext* context, | |
4706 OrthancPluginPixelFormat format, | |
4707 uint32_t width, | |
4708 uint32_t height) | |
4709 { | |
4710 OrthancPluginImage* target = NULL; | |
4711 | |
4712 _OrthancPluginCreateImage params; | |
4713 memset(¶ms, 0, sizeof(params)); | |
4714 params.target = ⌖ | |
4715 params.format = format; | |
4716 params.width = width; | |
4717 params.height = height; | |
4718 | |
4719 if (context->InvokeService(context, _OrthancPluginService_CreateImage, ¶ms) != OrthancPluginErrorCode_Success) | |
4720 { | |
4721 return NULL; | |
4722 } | |
4723 else | |
4724 { | |
4725 return target; | |
4726 } | |
4727 } | |
4728 | |
4729 | |
4730 /** | |
4731 * @brief Create an image pointing to a memory buffer. | |
4732 * | |
4733 * This function creates an image whose content points to a memory | |
4734 * buffer managed by the plugin. Note that the buffer is directly | |
4735 * accessed, no memory is allocated and no data is copied. | |
4736 * | |
4737 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4738 * @param format The format of the pixels. | |
4739 * @param width The width of the image. | |
4740 * @param height The height of the image. | |
4741 * @param pitch The pitch of the image (i.e. the number of bytes | |
4742 * between 2 successive lines of the image in the memory buffer). | |
4743 * @param buffer The memory buffer. | |
4744 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). | |
4745 * @ingroup Images | |
4746 **/ | |
4747 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor( | |
4748 OrthancPluginContext* context, | |
4749 OrthancPluginPixelFormat format, | |
4750 uint32_t width, | |
4751 uint32_t height, | |
4752 uint32_t pitch, | |
4753 void* buffer) | |
4754 { | |
4755 OrthancPluginImage* target = NULL; | |
4756 | |
4757 _OrthancPluginCreateImage params; | |
4758 memset(¶ms, 0, sizeof(params)); | |
4759 params.target = ⌖ | |
4760 params.format = format; | |
4761 params.width = width; | |
4762 params.height = height; | |
4763 params.pitch = pitch; | |
4764 params.buffer = buffer; | |
4765 | |
4766 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, ¶ms) != OrthancPluginErrorCode_Success) | |
4767 { | |
4768 return NULL; | |
4769 } | |
4770 else | |
4771 { | |
4772 return target; | |
4773 } | |
4774 } | |
4775 | |
4776 | |
4777 | |
4778 /** | |
4779 * @brief Decode one frame from a DICOM instance. | |
4780 * | |
4781 * This function decodes one frame of a DICOM image that is stored | |
4782 * in a memory buffer. This function will give the same result as | |
4783 * OrthancPluginUncompressImage() for single-frame DICOM images. | |
4784 * | |
4785 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4786 * @param buffer Pointer to a memory buffer containing the DICOM image. | |
4787 * @param bufferSize Size of the memory buffer containing the DICOM image. | |
4788 * @param frameIndex The index of the frame of interest in a multi-frame image. | |
4789 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
4790 * @ingroup Images | |
4791 **/ | |
4792 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage( | |
4793 OrthancPluginContext* context, | |
4794 const void* buffer, | |
4795 uint32_t bufferSize, | |
4796 uint32_t frameIndex) | |
4797 { | |
4798 OrthancPluginImage* target = NULL; | |
4799 | |
4800 _OrthancPluginCreateImage params; | |
4801 memset(¶ms, 0, sizeof(params)); | |
4802 params.target = ⌖ | |
4803 params.constBuffer = buffer; | |
4804 params.bufferSize = bufferSize; | |
4805 params.frameIndex = frameIndex; | |
4806 | |
4807 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, ¶ms) != OrthancPluginErrorCode_Success) | |
4808 { | |
4809 return NULL; | |
4810 } | |
4811 else | |
4812 { | |
4813 return target; | |
4814 } | |
4815 } | |
4816 | |
4817 | |
4818 | |
4819 typedef struct | |
4820 { | |
4821 char** result; | |
4822 const void* buffer; | |
4823 uint32_t size; | |
4824 } _OrthancPluginComputeHash; | |
4825 | |
4826 /** | |
4827 * @brief Compute an MD5 hash. | |
4828 * | |
4829 * This functions computes the MD5 cryptographic hash of the given memory buffer. | |
4830 * | |
4831 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4832 * @param buffer The source memory buffer. | |
4833 * @param size The size in bytes of the source buffer. | |
4834 * @return The NULL value in case of error, or a string containing the cryptographic hash. | |
4835 * This string must be freed by OrthancPluginFreeString(). | |
4836 * @ingroup Toolbox | |
4837 **/ | |
4838 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5( | |
4839 OrthancPluginContext* context, | |
4840 const void* buffer, | |
4841 uint32_t size) | |
4842 { | |
4843 char* result; | |
4844 | |
4845 _OrthancPluginComputeHash params; | |
4846 params.result = &result; | |
4847 params.buffer = buffer; | |
4848 params.size = size; | |
4849 | |
4850 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, ¶ms) != OrthancPluginErrorCode_Success) | |
4851 { | |
4852 /* Error */ | |
4853 return NULL; | |
4854 } | |
4855 else | |
4856 { | |
4857 return result; | |
4858 } | |
4859 } | |
4860 | |
4861 | |
4862 /** | |
4863 * @brief Compute a SHA-1 hash. | |
4864 * | |
4865 * This functions computes the SHA-1 cryptographic hash of the given memory buffer. | |
4866 * | |
4867 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4868 * @param buffer The source memory buffer. | |
4869 * @param size The size in bytes of the source buffer. | |
4870 * @return The NULL value in case of error, or a string containing the cryptographic hash. | |
4871 * This string must be freed by OrthancPluginFreeString(). | |
4872 * @ingroup Toolbox | |
4873 **/ | |
4874 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1( | |
4875 OrthancPluginContext* context, | |
4876 const void* buffer, | |
4877 uint32_t size) | |
4878 { | |
4879 char* result; | |
4880 | |
4881 _OrthancPluginComputeHash params; | |
4882 params.result = &result; | |
4883 params.buffer = buffer; | |
4884 params.size = size; | |
4885 | |
4886 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, ¶ms) != OrthancPluginErrorCode_Success) | |
4887 { | |
4888 /* Error */ | |
4889 return NULL; | |
4890 } | |
4891 else | |
4892 { | |
4893 return result; | |
4894 } | |
4895 } | |
4896 | |
4897 | |
4898 | |
4899 typedef struct | |
4900 { | |
4901 OrthancPluginDictionaryEntry* target; | |
4902 const char* name; | |
4903 } _OrthancPluginLookupDictionary; | |
4904 | |
4905 /** | |
4906 * @brief Get information about the given DICOM tag. | |
4907 * | |
4908 * This functions makes a lookup in the dictionary of DICOM tags | |
4909 * that are known to Orthanc, and returns information about this | |
4910 * tag. The tag can be specified using its human-readable name | |
4911 * (e.g. "PatientName") or a set of two hexadecimal numbers | |
4912 * (e.g. "0010-0020"). | |
4913 * | |
4914 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4915 * @param target Where to store the information about the tag. | |
4916 * @param name The name of the DICOM tag. | |
4917 * @return 0 if success, other value if error. | |
4918 * @ingroup Toolbox | |
4919 **/ | |
4920 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary( | |
4921 OrthancPluginContext* context, | |
4922 OrthancPluginDictionaryEntry* target, | |
4923 const char* name) | |
4924 { | |
4925 _OrthancPluginLookupDictionary params; | |
4926 params.target = target; | |
4927 params.name = name; | |
4928 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, ¶ms); | |
4929 } | |
4930 | |
4931 | |
4932 | |
4933 typedef struct | |
4934 { | |
4935 OrthancPluginRestOutput* output; | |
4936 const char* answer; | |
4937 uint32_t answerSize; | |
4938 uint32_t headersCount; | |
4939 const char* const* headersKeys; | |
4940 const char* const* headersValues; | |
4941 } _OrthancPluginSendMultipartItem2; | |
4942 | |
4943 /** | |
4944 * @brief Send an item as a part of some HTTP multipart answer, with custom headers. | |
4945 * | |
4946 * This function sends an item as a part of some HTTP multipart | |
4947 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to | |
4948 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated | |
4949 * with the item. | |
4950 * | |
4951 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4952 * @param output The HTTP connection to the client application. | |
4953 * @param answer Pointer to the memory buffer containing the item. | |
4954 * @param answerSize Number of bytes of the item. | |
4955 * @param headersCount The number of HTTP headers. | |
4956 * @param headersKeys Array containing the keys of the HTTP headers. | |
4957 * @param headersValues Array containing the values of the HTTP headers. | |
4958 * @return 0 if success, or the error code if failure (this notably happens | |
4959 * if the connection is closed by the client). | |
4960 * @see OrthancPluginSendMultipartItem() | |
4961 * @ingroup REST | |
4962 **/ | |
4963 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2( | |
4964 OrthancPluginContext* context, | |
4965 OrthancPluginRestOutput* output, | |
4966 const char* answer, | |
4967 uint32_t answerSize, | |
4968 uint32_t headersCount, | |
4969 const char* const* headersKeys, | |
4970 const char* const* headersValues) | |
4971 { | |
4972 _OrthancPluginSendMultipartItem2 params; | |
4973 params.output = output; | |
4974 params.answer = answer; | |
4975 params.answerSize = answerSize; | |
4976 params.headersCount = headersCount; | |
4977 params.headersKeys = headersKeys; | |
4978 params.headersValues = headersValues; | |
4979 | |
4980 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, ¶ms); | |
4981 } | |
4982 | |
4983 | |
4984 typedef struct | |
4985 { | |
4986 OrthancPluginIncomingHttpRequestFilter callback; | |
4987 } _OrthancPluginIncomingHttpRequestFilter; | |
4988 | |
4989 /** | |
4990 * @brief Register a callback to filter incoming HTTP requests. | |
4991 * | |
4992 * This function registers a custom callback to filter incoming HTTP/REST | |
4993 * requests received by the HTTP server of Orthanc. | |
4994 * | |
4995 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4996 * @param callback The callback. | |
4997 * @return 0 if success, other value if error. | |
4998 * @ingroup Callbacks | |
4999 **/ | |
5000 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter( | |
5001 OrthancPluginContext* context, | |
5002 OrthancPluginIncomingHttpRequestFilter callback) | |
5003 { | |
5004 _OrthancPluginIncomingHttpRequestFilter params; | |
5005 params.callback = callback; | |
5006 | |
5007 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, ¶ms); | |
5008 } | |
5009 | |
5010 | |
5011 | |
5012 typedef struct | |
5013 { | |
5014 OrthancPluginMemoryBuffer* answerBody; | |
5015 OrthancPluginMemoryBuffer* answerHeaders; | |
5016 uint16_t* httpStatus; | |
5017 OrthancPluginHttpMethod method; | |
5018 const char* url; | |
5019 uint32_t headersCount; | |
5020 const char* const* headersKeys; | |
5021 const char* const* headersValues; | |
5022 const char* body; | |
5023 uint32_t bodySize; | |
5024 const char* username; | |
5025 const char* password; | |
5026 uint32_t timeout; | |
5027 const char* certificateFile; | |
5028 const char* certificateKeyFile; | |
5029 const char* certificateKeyPassword; | |
5030 uint8_t pkcs11; | |
5031 } _OrthancPluginCallHttpClient2; | |
5032 | |
5033 | |
5034 | |
5035 /** | |
5036 * @brief Issue a HTTP call with full flexibility. | |
5037 * | |
5038 * Make a HTTP call to the given URL. The result to the query is | |
5039 * stored into a newly allocated memory buffer. The HTTP request | |
5040 * will be done accordingly to the global configuration of Orthanc | |
5041 * (in particular, the options "HttpProxy", "HttpTimeout", | |
5042 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be | |
5043 * taken into account). | |
5044 * | |
5045 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5046 * @param answerBody The target memory buffer (out argument). | |
5047 * It must be freed with OrthancPluginFreeMemoryBuffer(). | |
5048 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). | |
5049 * The answer headers are formatted as a JSON object (associative array). | |
5050 * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). | |
5051 * This argument can be set to NULL if the plugin has no interest in the HTTP headers. | |
5052 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
5053 * @param method HTTP method to be used. | |
5054 * @param url The URL of interest. | |
5055 * @param headersCount The number of HTTP headers. | |
5056 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5057 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5058 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
5059 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
5060 * @param body The body of the POST request. | |
5061 * @param bodySize The size of the body. | |
5062 * @param timeout Timeout in seconds (0 for default timeout). | |
5063 * @param certificateFile Path to the client certificate for HTTPS, in PEM format | |
5064 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5065 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format | |
5066 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5067 * @param certificateKeyPassword Password to unlock the key of the client certificate | |
5068 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5069 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards. | |
5070 * @return 0 if success, or the error code if failure. | |
5071 **/ | |
5072 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient( | |
5073 OrthancPluginContext* context, | |
5074 OrthancPluginMemoryBuffer* answerBody, | |
5075 OrthancPluginMemoryBuffer* answerHeaders, | |
5076 uint16_t* httpStatus, | |
5077 OrthancPluginHttpMethod method, | |
5078 const char* url, | |
5079 uint32_t headersCount, | |
5080 const char* const* headersKeys, | |
5081 const char* const* headersValues, | |
5082 const char* body, | |
5083 uint32_t bodySize, | |
5084 const char* username, | |
5085 const char* password, | |
5086 uint32_t timeout, | |
5087 const char* certificateFile, | |
5088 const char* certificateKeyFile, | |
5089 const char* certificateKeyPassword, | |
5090 uint8_t pkcs11) | |
5091 { | |
5092 _OrthancPluginCallHttpClient2 params; | |
5093 memset(¶ms, 0, sizeof(params)); | |
5094 | |
5095 params.answerBody = answerBody; | |
5096 params.answerHeaders = answerHeaders; | |
5097 params.httpStatus = httpStatus; | |
5098 params.method = method; | |
5099 params.url = url; | |
5100 params.headersCount = headersCount; | |
5101 params.headersKeys = headersKeys; | |
5102 params.headersValues = headersValues; | |
5103 params.body = body; | |
5104 params.bodySize = bodySize; | |
5105 params.username = username; | |
5106 params.password = password; | |
5107 params.timeout = timeout; | |
5108 params.certificateFile = certificateFile; | |
5109 params.certificateKeyFile = certificateKeyFile; | |
5110 params.certificateKeyPassword = certificateKeyPassword; | |
5111 params.pkcs11 = pkcs11; | |
5112 | |
5113 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, ¶ms); | |
5114 } | |
5115 | |
5116 | |
5117 /** | |
5118 * @brief Generate an UUID. | |
5119 * | |
5120 * Generate a random GUID/UUID (globally unique identifier). | |
5121 * | |
5122 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5123 * @return NULL in the case of an error, or a newly allocated string | |
5124 * containing the UUID. This string must be freed by OrthancPluginFreeString(). | |
5125 * @ingroup Toolbox | |
5126 **/ | |
5127 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid( | |
5128 OrthancPluginContext* context) | |
5129 { | |
5130 char* result; | |
5131 | |
5132 _OrthancPluginRetrieveDynamicString params; | |
5133 params.result = &result; | |
5134 params.argument = NULL; | |
5135 | |
5136 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, ¶ms) != OrthancPluginErrorCode_Success) | |
5137 { | |
5138 /* Error */ | |
5139 return NULL; | |
5140 } | |
5141 else | |
5142 { | |
5143 return result; | |
5144 } | |
5145 } | |
5146 | |
5147 | |
5148 | |
5149 | |
5150 typedef struct | |
5151 { | |
5152 OrthancPluginFindCallback callback; | |
5153 } _OrthancPluginFindCallback; | |
5154 | |
5155 /** | |
5156 * @brief Register a callback to handle C-Find requests. | |
5157 * | |
5158 * This function registers a callback to handle C-Find SCP requests | |
5159 * that are not related to modality worklists. | |
5160 * | |
5161 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5162 * @param callback The callback. | |
5163 * @return 0 if success, other value if error. | |
5164 * @ingroup DicomCallbacks | |
5165 **/ | |
5166 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback( | |
5167 OrthancPluginContext* context, | |
5168 OrthancPluginFindCallback callback) | |
5169 { | |
5170 _OrthancPluginFindCallback params; | |
5171 params.callback = callback; | |
5172 | |
5173 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, ¶ms); | |
5174 } | |
5175 | |
5176 | |
5177 typedef struct | |
5178 { | |
5179 OrthancPluginFindAnswers *answers; | |
5180 const OrthancPluginFindQuery *query; | |
5181 const void *dicom; | |
5182 uint32_t size; | |
5183 uint32_t index; | |
5184 uint32_t *resultUint32; | |
5185 uint16_t *resultGroup; | |
5186 uint16_t *resultElement; | |
5187 char **resultString; | |
5188 } _OrthancPluginFindOperation; | |
5189 | |
5190 /** | |
5191 * @brief Add one answer to some C-Find request. | |
5192 * | |
5193 * This function adds one answer (encoded as a DICOM file) to the | |
5194 * set of answers corresponding to some C-Find SCP request that is | |
5195 * not related to modality worklists. | |
5196 * | |
5197 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5198 * @param answers The set of answers. | |
5199 * @param dicom The answer to be added, encoded as a DICOM file. | |
5200 * @param size The size of the DICOM file. | |
5201 * @return 0 if success, other value if error. | |
5202 * @ingroup DicomCallbacks | |
5203 * @see OrthancPluginCreateDicom() | |
5204 **/ | |
5205 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer( | |
5206 OrthancPluginContext* context, | |
5207 OrthancPluginFindAnswers* answers, | |
5208 const void* dicom, | |
5209 uint32_t size) | |
5210 { | |
5211 _OrthancPluginFindOperation params; | |
5212 memset(¶ms, 0, sizeof(params)); | |
5213 params.answers = answers; | |
5214 params.dicom = dicom; | |
5215 params.size = size; | |
5216 | |
5217 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, ¶ms); | |
5218 } | |
5219 | |
5220 | |
5221 /** | |
5222 * @brief Mark the set of C-Find answers as incomplete. | |
5223 * | |
5224 * This function marks as incomplete the set of answers | |
5225 * corresponding to some C-Find SCP request that is not related to | |
5226 * modality worklists. This must be used if canceling the handling | |
5227 * of a request when too many answers are to be returned. | |
5228 * | |
5229 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5230 * @param answers The set of answers. | |
5231 * @return 0 if success, other value if error. | |
5232 * @ingroup DicomCallbacks | |
5233 **/ | |
5234 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete( | |
5235 OrthancPluginContext* context, | |
5236 OrthancPluginFindAnswers* answers) | |
5237 { | |
5238 _OrthancPluginFindOperation params; | |
5239 memset(¶ms, 0, sizeof(params)); | |
5240 params.answers = answers; | |
5241 | |
5242 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, ¶ms); | |
5243 } | |
5244 | |
5245 | |
5246 | |
5247 /** | |
5248 * @brief Get the number of tags in a C-Find query. | |
5249 * | |
5250 * This function returns the number of tags that are contained in | |
5251 * the given C-Find query. | |
5252 * | |
5253 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5254 * @param query The C-Find query. | |
5255 * @return The number of tags. | |
5256 * @ingroup DicomCallbacks | |
5257 **/ | |
5258 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize( | |
5259 OrthancPluginContext* context, | |
5260 const OrthancPluginFindQuery* query) | |
5261 { | |
5262 uint32_t count = 0; | |
5263 | |
5264 _OrthancPluginFindOperation params; | |
5265 memset(¶ms, 0, sizeof(params)); | |
5266 params.query = query; | |
5267 params.resultUint32 = &count; | |
5268 | |
5269 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, ¶ms) != OrthancPluginErrorCode_Success) | |
5270 { | |
5271 /* Error */ | |
5272 return 0; | |
5273 } | |
5274 else | |
5275 { | |
5276 return count; | |
5277 } | |
5278 } | |
5279 | |
5280 | |
5281 /** | |
5282 * @brief Get one tag in a C-Find query. | |
5283 * | |
5284 * This function returns the group and the element of one DICOM tag | |
5285 * in the given C-Find query. | |
5286 * | |
5287 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5288 * @param group The group of the tag (output). | |
5289 * @param element The element of the tag (output). | |
5290 * @param query The C-Find query. | |
5291 * @param index The index of the tag of interest. | |
5292 * @return 0 if success, other value if error. | |
5293 * @ingroup DicomCallbacks | |
5294 **/ | |
5295 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag( | |
5296 OrthancPluginContext* context, | |
5297 uint16_t* group, | |
5298 uint16_t* element, | |
5299 const OrthancPluginFindQuery* query, | |
5300 uint32_t index) | |
5301 { | |
5302 _OrthancPluginFindOperation params; | |
5303 memset(¶ms, 0, sizeof(params)); | |
5304 params.query = query; | |
5305 params.index = index; | |
5306 params.resultGroup = group; | |
5307 params.resultElement = element; | |
5308 | |
5309 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, ¶ms); | |
5310 } | |
5311 | |
5312 | |
5313 /** | |
5314 * @brief Get the symbolic name of one tag in a C-Find query. | |
5315 * | |
5316 * This function returns the symbolic name of one DICOM tag in the | |
5317 * given C-Find query. | |
5318 * | |
5319 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5320 * @param query The C-Find query. | |
5321 * @param index The index of the tag of interest. | |
5322 * @return The NULL value in case of error, or a string containing the name of the tag. | |
5323 * @return 0 if success, other value if error. | |
5324 * @ingroup DicomCallbacks | |
5325 **/ | |
5326 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName( | |
5327 OrthancPluginContext* context, | |
5328 const OrthancPluginFindQuery* query, | |
5329 uint32_t index) | |
5330 { | |
5331 char* result; | |
5332 | |
5333 _OrthancPluginFindOperation params; | |
5334 memset(¶ms, 0, sizeof(params)); | |
5335 params.query = query; | |
5336 params.index = index; | |
5337 params.resultString = &result; | |
5338 | |
5339 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, ¶ms) != OrthancPluginErrorCode_Success) | |
5340 { | |
5341 /* Error */ | |
5342 return NULL; | |
5343 } | |
5344 else | |
5345 { | |
5346 return result; | |
5347 } | |
5348 } | |
5349 | |
5350 | |
5351 /** | |
5352 * @brief Get the value associated with one tag in a C-Find query. | |
5353 * | |
5354 * This function returns the value associated with one tag in the | |
5355 * given C-Find query. | |
5356 * | |
5357 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5358 * @param query The C-Find query. | |
5359 * @param index The index of the tag of interest. | |
5360 * @return The NULL value in case of error, or a string containing the value of the tag. | |
5361 * @return 0 if success, other value if error. | |
5362 * @ingroup DicomCallbacks | |
5363 **/ | |
5364 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue( | |
5365 OrthancPluginContext* context, | |
5366 const OrthancPluginFindQuery* query, | |
5367 uint32_t index) | |
5368 { | |
5369 char* result; | |
5370 | |
5371 _OrthancPluginFindOperation params; | |
5372 memset(¶ms, 0, sizeof(params)); | |
5373 params.query = query; | |
5374 params.index = index; | |
5375 params.resultString = &result; | |
5376 | |
5377 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, ¶ms) != OrthancPluginErrorCode_Success) | |
5378 { | |
5379 /* Error */ | |
5380 return NULL; | |
5381 } | |
5382 else | |
5383 { | |
5384 return result; | |
5385 } | |
5386 } | |
5387 | |
5388 | |
5389 | |
5390 | |
5391 typedef struct | |
5392 { | |
5393 OrthancPluginMoveCallback callback; | |
5394 OrthancPluginGetMoveSize getMoveSize; | |
5395 OrthancPluginApplyMove applyMove; | |
5396 OrthancPluginFreeMove freeMove; | |
5397 } _OrthancPluginMoveCallback; | |
5398 | |
5399 /** | |
5400 * @brief Register a callback to handle C-Move requests. | |
5401 * | |
5402 * This function registers a callback to handle C-Move SCP requests. | |
5403 * | |
5404 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5405 * @param callback The main callback. | |
5406 * @param getMoveSize Callback to read the number of C-Move suboperations. | |
5407 * @param applyMove Callback to apply one C-Move suboperations. | |
5408 * @param freeMove Callback to free the C-Move driver. | |
5409 * @return 0 if success, other value if error. | |
5410 * @ingroup DicomCallbacks | |
5411 **/ | |
5412 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback( | |
5413 OrthancPluginContext* context, | |
5414 OrthancPluginMoveCallback callback, | |
5415 OrthancPluginGetMoveSize getMoveSize, | |
5416 OrthancPluginApplyMove applyMove, | |
5417 OrthancPluginFreeMove freeMove) | |
5418 { | |
5419 _OrthancPluginMoveCallback params; | |
5420 params.callback = callback; | |
5421 params.getMoveSize = getMoveSize; | |
5422 params.applyMove = applyMove; | |
5423 params.freeMove = freeMove; | |
5424 | |
5425 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, ¶ms); | |
5426 } | |
5427 | |
5428 | |
5429 | |
5430 typedef struct | |
5431 { | |
5432 OrthancPluginFindMatcher** target; | |
5433 const void* query; | |
5434 uint32_t size; | |
5435 } _OrthancPluginCreateFindMatcher; | |
5436 | |
5437 | |
5438 /** | |
5439 * @brief Create a C-Find matcher. | |
5440 * | |
5441 * This function creates a "matcher" object that can be used to | |
5442 * check whether a DICOM instance matches a C-Find query. The C-Find | |
5443 * query must be expressed as a DICOM buffer. | |
5444 * | |
5445 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5446 * @param query The C-Find DICOM query. | |
5447 * @param size The size of the DICOM query. | |
5448 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher(). | |
5449 * @ingroup Toolbox | |
5450 **/ | |
5451 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher( | |
5452 OrthancPluginContext* context, | |
5453 const void* query, | |
5454 uint32_t size) | |
5455 { | |
5456 OrthancPluginFindMatcher* target = NULL; | |
5457 | |
5458 _OrthancPluginCreateFindMatcher params; | |
5459 memset(¶ms, 0, sizeof(params)); | |
5460 params.target = ⌖ | |
5461 params.query = query; | |
5462 params.size = size; | |
5463 | |
5464 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, ¶ms) != OrthancPluginErrorCode_Success) | |
5465 { | |
5466 return NULL; | |
5467 } | |
5468 else | |
5469 { | |
5470 return target; | |
5471 } | |
5472 } | |
5473 | |
5474 | |
5475 typedef struct | |
5476 { | |
5477 OrthancPluginFindMatcher* matcher; | |
5478 } _OrthancPluginFreeFindMatcher; | |
5479 | |
5480 /** | |
5481 * @brief Free a C-Find matcher. | |
5482 * | |
5483 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher(). | |
5484 * | |
5485 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5486 * @param matcher The matcher of interest. | |
5487 * @ingroup Toolbox | |
5488 **/ | |
5489 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher( | |
5490 OrthancPluginContext* context, | |
5491 OrthancPluginFindMatcher* matcher) | |
5492 { | |
5493 _OrthancPluginFreeFindMatcher params; | |
5494 params.matcher = matcher; | |
5495 | |
5496 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, ¶ms); | |
5497 } | |
5498 | |
5499 | |
5500 typedef struct | |
5501 { | |
5502 const OrthancPluginFindMatcher* matcher; | |
5503 const void* dicom; | |
5504 uint32_t size; | |
5505 int32_t* isMatch; | |
5506 } _OrthancPluginFindMatcherIsMatch; | |
5507 | |
5508 /** | |
5509 * @brief Test whether a DICOM instance matches a C-Find query. | |
5510 * | |
5511 * This function checks whether one DICOM instance matches C-Find | |
5512 * matcher that was previously allocated using | |
5513 * OrthancPluginCreateFindMatcher(). | |
5514 * | |
5515 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5516 * @param matcher The matcher of interest. | |
5517 * @param dicom The DICOM instance to be matched. | |
5518 * @param size The size of the DICOM instance. | |
5519 * @return 1 if the DICOM instance matches the query, 0 otherwise. | |
5520 * @ingroup Toolbox | |
5521 **/ | |
5522 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch( | |
5523 OrthancPluginContext* context, | |
5524 const OrthancPluginFindMatcher* matcher, | |
5525 const void* dicom, | |
5526 uint32_t size) | |
5527 { | |
5528 int32_t isMatch = 0; | |
5529 | |
5530 _OrthancPluginFindMatcherIsMatch params; | |
5531 params.matcher = matcher; | |
5532 params.dicom = dicom; | |
5533 params.size = size; | |
5534 params.isMatch = &isMatch; | |
5535 | |
5536 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, ¶ms) == OrthancPluginErrorCode_Success) | |
5537 { | |
5538 return isMatch; | |
5539 } | |
5540 else | |
5541 { | |
5542 /* Error: Assume non-match */ | |
5543 return 0; | |
5544 } | |
5545 } | |
5546 | |
5547 | |
5548 #ifdef __cplusplus | |
5549 } | |
5550 #endif | |
5551 | |
5552 | |
5553 /** @} */ | |
5554 |