comparison Resources/Orthanc/Sdk-1.0.0/orthanc/OrthancCPlugin.h @ 0:520cba9a0d42

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