comparison Resources/Orthanc/Sdk-1.3.1/orthanc/OrthancCPlugin.h @ 18:d795b48a62a8 0.2.1

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